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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
import std/expect
import std/int
import std/order
pub fn to_string() {
123
|> int:to_string
|> expect:equal(_, "123")
-123
|> int:to_string
|> expect:equal(_, "-123")
0123
|> int:to_string
|> expect:equal(_, "123")
}
pub fn parse() {
"123"
|> int:parse
|> expect:equal(_, Ok(123))
"-123"
|> int:parse
|> expect:equal(_, Ok(-123))
"0123"
|> int:parse
|> expect:equal(_, Ok(123))
""
|> int:parse
|> expect:is_error
"what"
|> int:parse
|> expect:is_error
"1.23"
|> int:parse
|> expect:is_error
}
pub fn to_base_string() {
100
|> int:to_base_string(_, 16)
|> expect:equal(_, "64")
-100
|> int:to_base_string(_, 16)
|> expect:equal(_, "-64")
}
pub fn compare_test() {
int:compare(0, 0)
|> expect:equal(_, order:Eq)
int:compare(1, 1)
|> expect:equal(_, order:Eq)
int:compare(0, 1)
|> expect:equal(_, order:Lt)
int:compare(-2, -1)
|> expect:equal(_, order:Lt)
int:compare(2, 1)
|> expect:equal(_, order:Gt)
int:compare(-1, -2)
|> expect:equal(_, order:Gt)
}
|