code / tomo

Lines41.3K C23.7K Markdown9.7K YAML5.0K Tomo2.3K
7 others 763
Python231 Shell230 make212 INI47 Text21 SVG16 Lua6
(129 lines)
1 func main()
2 assert 2 + 3 == 5
4 assert 2 * 3 == 6
6 assert 2 + 3 * 4 == 14
8 assert 2 * 3 + 4 == 10
10 assert Int8(1) + Int16(2) == Int16(3)
12 assert 1 << 10 == 1024
14 assert (3 and 2) == 2
16 assert (3 or 4) == 7
18 assert (3 xor 2) == 1
20 nums := ""
21 for x in 5
22 nums ++= "$x,"
23 assert nums == "1,2,3,4,5,"
25 >> x := Int64(123)
26 assert x.hex() == "0x7B"
27 assert x.hex(digits=4) == "0x007B"
28 assert x.octal() == "0o173"
30 assert Int64.min == Int64(-9223372036854775808)
31 assert Int64.max == Int64(9223372036854775807)
34 assert Int32(123).hex() == "0x7B"
35 assert Int16(123).hex() == "0x7B"
36 assert Int8(123).hex() == "0x7B"
38 assert Int(2.1, truncate=yes) == 2
40 do
41 small_int := 1
42 assert small_int == 1
43 max_small_int := 536870911
44 assert max_small_int == 536870911
45 max_i64 := 536870912
46 assert max_i64 == 536870912
47 super_big := 9999999999999999999999
48 assert super_big == 9999999999999999999999
49 assert max_small_int + 1 == 536870912
51 assert max_small_int + max_small_int == 1073741822
53 assert super_big + 1 == 10000000000000000000000
55 do
56 interesting_numerators := [-999999, -100, -23, -1, 0, 1, 23, 100, 999999]
57 interesting_denominators := [-99, -20, -17, -1, 1, 17, 20, 99]
58 for n in interesting_numerators
59 for d in interesting_denominators
60 assert (n/d)*d + (n mod d) == n
62 assert 0.next_prime() == 2
63 assert 7.next_prime() == 11
64 assert (and: p.is_prime() for p in [
65 2, 3, 5, 7,
66 137372146048179869781170214707,
67 811418847921670560768224995279,
68 292590241572454328697048860273,
69 754893741683930091960170890717,
70 319651808258437169510475301537,
71 323890224935694708770556249787,
72 507626552342376235511933571091,
73 548605069630614185274710840981,
74 121475876690852432982324195553,
75 771958616175795150904761471637,
76 ])!
78 assert (or: p.is_prime() for p in [
79 -1, 0, 1, 4, 6,
80 137372146048179869781170214707*2,
81 811418847921670560768224995279*3,
82 292590241572454328697048860273*754893741683930091960170890717,
83 ])! == no
85 assert Int(yes) == 1
86 assert Int(no) == 0
88 assert Int64(yes) == Int64(1)
89 assert Int64(no) == Int64(0)
91 assert 4.choose(2) == 6
93 assert 4.factorial() == 24
95 assert 3.is_between(1, 5) == yes
96 assert 3.is_between(1, 3) == yes
97 assert 3.is_between(5, 1) == yes
98 assert 3.is_between(100, 200) == no
100 assert 6.get_bit(1) == no
101 assert 6.get_bit(2) == yes
102 assert 6.get_bit(3) == yes
103 assert 6.get_bit(4) == no
105 assert Int64(6).get_bit(1) == no
106 assert Int64(6).get_bit(2) == yes
107 assert Int64(6).get_bit(3) == yes
108 assert Int64(6).get_bit(4) == no
110 assert Int.parse("123") == 123
111 assert Int.parse("0x10") == 16
112 assert Int.parse("0o10") == 8
113 assert Int.parse("0b10") == 2
114 assert Int.parse("abc") == none
116 assert Int.parse("-123") == -123
117 assert Int.parse("-0x10") == -16
118 assert Int.parse("-0o10") == -8
119 assert Int.parse("-0b10") == -2
121 for base in 2.to(36)
122 assert Int.parse("10", base=base) == base
124 assert Int.parse("111", base=1) == 3
126 assert Int.parse("z", base=36) == 35
127 assert Int.parse("Z", base=36) == 35
128 assert Int.parse("-z", base=36) == -35
129 assert Int.parse("-Z", base=36) == -35