-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsize_tests.nim
57 lines (46 loc) · 1.61 KB
/
size_tests.nim
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# source is included since we're not exporting
# anything to be used by other libs/packages
include ll
import unittest
type
Comparison = object
value: int64
expected: string
suite "size display tests":
test "it displays correctly for default format":
let
tests = [
Comparison(value: 1, expected: "1"),
Comparison(value: 123, expected: "123"),
Comparison(value: 12345, expected: "12345"),
Comparison(value: 123456789, expected: "123456789"),
]
for test in tests:
let
entry = Entry(size: test.value)
result = formatSize(entry, DisplaySize.default).clean
check:
result == test.expected
test "it displays correctly for human format":
let
tests = [
Comparison(value: 1, expected: "1"),
Comparison(value: 12, expected: "12"),
Comparison(value: 123, expected: "123"),
Comparison(value: 1000, expected: "1000"),
Comparison(value: 1024, expected: "1.0K"),
Comparison(value: 1234, expected: "1.2K"),
Comparison(value: 12345, expected: "12K"),
Comparison(value: 516526, expected: "504K"),
Comparison(value: 123456789, expected: "118M"),
Comparison(value: 445566778899, expected: "415G"),
Comparison(value: 33445566778899, expected: "30T"),
Comparison(value: 2233445566778899, expected: "2P"),
Comparison(value: 112233445566778899, expected: "100P"),
]
for test in tests:
let
entry = Entry(size: test.value)
result = formatSize(entry, DisplaySize.human).clean
check:
result == test.expected