@@ -3,11 +3,11 @@ import { bytesToString, ip, mbToBytes } from '@/lib/formatters';
33describe ( '@/lib/formatters.ts' , function ( ) {
44 describe ( 'mbToBytes()' , function ( ) {
55 it ( 'should convert from MB to Bytes' , function ( ) {
6- expect ( mbToBytes ( 1 ) ) . toBe ( 1_000_000 ) ;
6+ expect ( mbToBytes ( 1 ) ) . toBe ( 1_048_576 ) ;
77 expect ( mbToBytes ( 0 ) ) . toBe ( 0 ) ;
8- expect ( mbToBytes ( 0.1 ) ) . toBe ( 100_000 ) ;
9- expect ( mbToBytes ( 0.001 ) ) . toBe ( 1000 ) ;
10- expect ( mbToBytes ( 1024 ) ) . toBe ( 1_024_000_000 ) ;
8+ expect ( mbToBytes ( 0.1 ) ) . toBe ( 104_857 ) ;
9+ expect ( mbToBytes ( 0.001 ) ) . toBe ( 1_048 ) ;
10+ expect ( mbToBytes ( 1024 ) ) . toBe ( 1_073_741_824 ) ;
1111 } ) ;
1212 } ) ;
1313
@@ -20,18 +20,23 @@ describe('@/lib/formatters.ts', function () {
2020 [ 100.25 , '100.25 Bytes' ] ,
2121 [ 100.998 , '101 Bytes' ] ,
2222 [ 512 , '512 Bytes' ] ,
23- [ 1000 , '1 KB' ] ,
24- [ 1024 , '1.02 KB' ] ,
25- [ 5068 , '5.07 KB' ] ,
26- [ 10_000 , '10 KB' ] ,
27- [ 11_864 , '11.86 KB' ] ,
28- [ 1_000_000 , '1 MB' ] ,
29- [ 1_356_000 , '1.36 MB' ] ,
30- [ 1_024_000 , '1.02 MB' ] ,
31- [ 1_000_000_000 , '1 GB' ] ,
32- [ 1_024_000_000 , '1.02 GB' ] ,
33- [ 1_678_342_000 , '1.68 GB' ] ,
34- [ 1_000_000_000_000 , '1 TB' ] ,
23+ [ 1000 , '1000 Bytes' ] ,
24+ [ 1024 , '1 KB' ] ,
25+ [ 5068 , '4.95 KB' ] ,
26+ [ 10_000 , '9.77 KB' ] ,
27+ [ 10_240 , '10 KB' ] ,
28+ [ 11_864 , '11.59 KB' ] ,
29+ [ 1_000_000 , '976.56 KB' ] ,
30+ [ 1_024_000 , '1000 KB' ] ,
31+ [ 1_025_000 , '1000.98 KB' ] ,
32+ [ 1_048_576 , '1 MB' ] ,
33+ [ 1_356_000 , '1.29 MB' ] ,
34+ [ 1_000_000_000 , '953.67 MB' ] ,
35+ [ 1_070_000_100 , '1020.43 MB' ] ,
36+ [ 1_073_741_824 , '1 GB' ] ,
37+ [ 1_678_342_000 , '1.56 GB' ] ,
38+ [ 1_000_000_000_000 , '931.32 GB' ] ,
39+ [ 1_099_511_627_776 , '1 TB' ] ,
3540 ] ) ( 'should format %d bytes as "%s"' , function ( input , output ) {
3641 expect ( bytesToString ( input ) ) . toBe ( output ) ;
3742 } ) ;
0 commit comments