@@ -28,27 +28,27 @@ describe('formatGigaBytes', () => {
2828 } ) ;
2929
3030 it ( 'returns large values without fractional digits by default' , ( ) => {
31- expect ( formatGigaBytes ( 1234567890123 ) ) . toBe ( '1,150GB ' ) ;
31+ expect ( formatGigaBytes ( 1234567890123 ) ) . toBe ( '1,235GB ' ) ;
3232 } ) ;
3333
3434 it ( 'returns values with 2 fractional digits by default' , ( ) => {
35- expect ( formatGigaBytes ( 1234567890 ) ) . toBe ( '1.15GB ' ) ;
35+ expect ( formatGigaBytes ( 1234567890 ) ) . toBe ( '1.23GB ' ) ;
3636 } ) ;
3737
3838 it ( 'can return values with byte precision' , ( ) => {
39- expect ( formatGigaBytes ( 1234567890 , 3 , 2 , 1 ) ) . toBe ( '1GB 153MB 384KB 722B ' ) ;
39+ expect ( formatGigaBytes ( 1234567890 , 3 , 2 , 1 ) ) . toBe ( '1GB 234MB 567KB 890B ' ) ;
4040 } ) ;
4141
4242 it ( 'can return values with kilobyte precision' , ( ) => {
43- expect ( formatGigaBytes ( 1234567890 , 3 , 2 , 1024 ) ) . toBe ( '1GB 153MB 385KB ' ) ;
43+ expect ( formatGigaBytes ( 1234567890 , 3 , 2 , 1000 ) ) . toBe ( '1GB 234MB 568KB ' ) ;
4444 } ) ;
4545
4646 it ( 'can return values with megabyte precision' , ( ) => {
47- expect ( formatGigaBytes ( 1234567890 , 3 , 2 , 1024 ** 2 ) ) . toBe ( '1GB 153MB ' ) ;
47+ expect ( formatGigaBytes ( 1234567890 , 3 , 2 , 1000 ** 2 ) ) . toBe ( '1GB 235MB ' ) ;
4848 } ) ;
4949
5050 it ( 'can return values with gigabyte precision' , ( ) => {
51- expect ( formatGigaBytes ( 1234567890 , 3 , 2 , 1024 ** 3 ) ) . toBe ( '1GB' ) ;
51+ expect ( formatGigaBytes ( 1234567890 , 3 , 2 , 1000 ** 3 ) ) . toBe ( '1GB' ) ;
5252 } ) ;
5353} ) ;
5454
@@ -58,23 +58,23 @@ describe('formatMegaBytes', () => {
5858 } ) ;
5959
6060 it ( 'returns large values without fractional digits by default' , ( ) => {
61- expect ( formatMegaBytes ( 1234567890 ) ) . toBe ( '1,177MB ' ) ;
61+ expect ( formatMegaBytes ( 1234567890 ) ) . toBe ( '1,235MB ' ) ;
6262 } ) ;
6363
6464 it ( 'returns values with 2 fractional digits by default' , ( ) => {
65- expect ( formatMegaBytes ( 1234567 ) ) . toBe ( '1.18MB ' ) ;
65+ expect ( formatMegaBytes ( 1234567 ) ) . toBe ( '1.23MB ' ) ;
6666 } ) ;
6767
6868 it ( 'can return values with byte precision' , ( ) => {
69- expect ( formatMegaBytes ( 1234567 , 3 , 2 , 1 ) ) . toBe ( '1MB 181KB 647B ' ) ;
69+ expect ( formatMegaBytes ( 1234567 , 3 , 2 , 1 ) ) . toBe ( '1MB 234KB 567B ' ) ;
7070 } ) ;
7171
7272 it ( 'can return values with kilobyte precision' , ( ) => {
73- expect ( formatMegaBytes ( 1234567 , 3 , 2 , 1024 ) ) . toBe ( '1MB 182KB ' ) ;
73+ expect ( formatMegaBytes ( 1234567 , 3 , 2 , 1000 ) ) . toBe ( '1MB 235KB ' ) ;
7474 } ) ;
7575
7676 it ( 'can return values with megabyte precision' , ( ) => {
77- expect ( formatMegaBytes ( 1234567 , 3 , 2 , 1024 ** 2 ) ) . toBe ( '1MB' ) ;
77+ expect ( formatMegaBytes ( 1234567 , 3 , 2 , 1000 ** 2 ) ) . toBe ( '1MB' ) ;
7878 } ) ;
7979} ) ;
8080
@@ -84,19 +84,19 @@ describe('formatKiloBytes', () => {
8484 } ) ;
8585
8686 it ( 'returns large values without fractional digits by default' , ( ) => {
87- expect ( formatKiloBytes ( 1234567 ) ) . toBe ( '1,206KB ' ) ;
87+ expect ( formatKiloBytes ( 1234567 ) ) . toBe ( '1,235KB ' ) ;
8888 } ) ;
8989
9090 it ( 'returns values with 2 fractional digits by default' , ( ) => {
91- expect ( formatKiloBytes ( 1234 ) ) . toBe ( '1.21KB ' ) ;
91+ expect ( formatKiloBytes ( 1234 ) ) . toBe ( '1.23KB ' ) ;
9292 } ) ;
9393
9494 it ( 'can return values with byte precision' , ( ) => {
95- expect ( formatKiloBytes ( 1234 , 3 , 2 , 1 ) ) . toBe ( '1KB 210B ' ) ;
95+ expect ( formatKiloBytes ( 1234 , 3 , 2 , 1 ) ) . toBe ( '1KB 234B ' ) ;
9696 } ) ;
9797
9898 it ( 'can return values with kilobyte precision' , ( ) => {
99- expect ( formatKiloBytes ( 1234 , 3 , 2 , 1024 ) ) . toBe ( '1KB' ) ;
99+ expect ( formatKiloBytes ( 1234 , 3 , 2 , 1000 ) ) . toBe ( '1KB' ) ;
100100 } ) ;
101101} ) ;
102102
@@ -110,40 +110,53 @@ describe('formatBytes', () => {
110110 } ) ;
111111
112112 it ( 'can return values with the kilobyte unit' , ( ) => {
113- expect ( formatBytes ( 12345 ) ) . toBe ( '12.1KB ' ) ;
113+ expect ( formatBytes ( 12345 ) ) . toBe ( '12.3KB ' ) ;
114114 } ) ;
115115
116116 it ( 'can return values with the megabyte unit' , ( ) => {
117- expect ( formatBytes ( 1234567 ) ) . toBe ( '1.18MB ' ) ;
117+ expect ( formatBytes ( 1234567 ) ) . toBe ( '1.23MB ' ) ;
118118 } ) ;
119119
120120 it ( 'can return values with the gigabyte unit' , ( ) => {
121- expect ( formatBytes ( 1234567890 ) ) . toBe ( '1.15GB ' ) ;
121+ expect ( formatBytes ( 1234567890 ) ) . toBe ( '1.23GB ' ) ;
122122 } ) ;
123123
124124 it ( 'can return values with byte precision' , ( ) => {
125- expect ( formatBytes ( 12345 , 3 , 2 , 1 ) ) . toBe ( '12KB 57B ' ) ;
125+ expect ( formatBytes ( 12345 , 3 , 2 , 1 ) ) . toBe ( '12KB 345B ' ) ;
126126 } ) ;
127127
128128 it ( 'can return values with kilobyte precision' , ( ) => {
129- expect ( formatBytes ( 12345 , 3 , 2 , 1024 ) ) . toBe ( '12KB' ) ;
129+ expect ( formatBytes ( 12345 , 3 , 2 , 1000 ) ) . toBe ( '12KB' ) ;
130130 } ) ;
131131} ) ;
132132
133133describe ( 'findRoundBytesValueGreaterOrEqualTo' , ( ) => {
134- const expectedValues = [ 0 , 2 , 5 , 10 , 20 , 50 , 100 , 200 , 500 , 1000 , 2000 ] ;
135-
136- it ( 'rounds small bytes values using base 10 round value' , ( ) => {
134+ const expectedValues = [
135+ // minValue, expected
136+ // minValue <= 1000
137+ [ 0 , 0 ] ,
138+ [ 3 , 5 ] ,
139+ [ 63 , 100 ] ,
140+ [ 511 , 1000 ] ,
141+ [ 1000 , 2000 ] ,
142+
143+ // 1000 < minValue <= 1000^4
144+ [ 2047 , 4000 ] ,
145+ [ 9999 , 16000 ] ,
146+ [ 123456 , 128000 ] ,
147+ [ 999999 , 1000000 ] ,
148+ [ 1_234_567 , 2_000_000 ] ,
149+ [ 1_234_567_891 , 2_000_000_000 ] ,
150+
151+ // minValue > 1000^4
152+ [ 1_234_567_891_234 , 2_000_000_000_000 ] ,
153+ [ 1_234_567_891_234_567 , 2_000_000_000_000_000 ] ,
154+ ] ;
155+
156+ it ( 'correctly rounds bytes values using base 10 round value' , ( ) => {
137157 for ( let i = 0 ; i < expectedValues . length ; ++ i ) {
138- expect ( findRoundBytesValueGreaterOrEqualTo ( 2 ** i - 1 ) ) . toBe (
139- expectedValues [ i ]
140- ) ;
141- }
142- } ) ;
143-
144- it ( 'rounds large bytes values using base 2 round value' , ( ) => {
145- for ( let i = expectedValues . length ; i < 40 ; ++ i ) {
146- expect ( findRoundBytesValueGreaterOrEqualTo ( 2 ** i - 1 ) ) . toBe ( 2 ** i ) ;
158+ const [ input , expected ] = expectedValues [ i ] ;
159+ expect ( findRoundBytesValueGreaterOrEqualTo ( input ) ) . toBe ( expected ) ;
147160 }
148161 } ) ;
149162} ) ;
0 commit comments