@anonymous/

YummyJumpyDevices

Python

No description

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
h=lambda v,u=0:v>999.4and h(v/1024,u+2)or"%.*f%sB"%(u and(v<10)+(v<100),v,"KiMiGi"[u-2:u])

test = {
    0: "0B",
    1: "1B",
    42: "42B",
    999: "999B",
    1000: "0.98KiB",
    1024: "1.00KiB",
    2018: "1.97KiB",
    10086: "9.85KiB",
    100010: "97.7KiB",
    456789: "446KiB",
    20080705: "19.2MiB",
    954437177: "910MiB",
    1084587701: "1.01GiB",
    1207959551: "1.12GiB",
    2147483647: "2.00GiB",
    1023079: "999KiB",
    1023488: "0.98MiB",
    1043333: "0.99MiB",
    1043334: "1.00MiB",
}

for v, s in test.items():
    print("{} --> {}".format(v, h(v)))
    assert h(v) == s