aboutsummaryrefslogtreecommitdiff
path: root/test/integers.tm
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-09-21 17:44:08 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-09-21 17:44:08 -0400
commitc941b9a3325228eba404455afea7ccea0da45095 (patch)
treed4ca88c6848ac2e6ceee635bb87add87ba6d2322 /test/integers.tm
parent1cec086a6034ad546977cae7aeaf4bb876d21970 (diff)
Fix tests
Diffstat (limited to 'test/integers.tm')
-rw-r--r--test/integers.tm150
1 files changed, 56 insertions, 94 deletions
diff --git a/test/integers.tm b/test/integers.tm
index ee560952..d6e68066 100644
--- a/test/integers.tm
+++ b/test/integers.tm
@@ -7,11 +7,9 @@ func main()
assert 2 * 3 + 4 == 10
- >> Int8(1) + Int16(2)
- = Int16(3)
+ assert Int8(1) + Int16(2) == Int16(3)
- >> 1 << 10
- = 1024
+ assert 1 << 10 == 1024
# say("Signed and unsigned bit shifting:")
# >> Int64(-2) << 1
@@ -23,62 +21,46 @@ func main()
# >> Int64(-2) >>> 1
# = Int64(9223372036854775807)
- >> 3 and 2
- = 2
+ assert (3 and 2) == 2
- >> 3 or 4
- = 7
+ assert (3 or 4) == 7
- >> 3 xor 2
- = 1
+ assert (3 xor 2) == 1
nums := ""
for x in 5
nums ++= "$x,"
- >> nums
- = "1,2,3,4,5,"
+ assert nums == "1,2,3,4,5,"
>> x := Int64(123)
- >> x.hex()
- = "0x7B"
- >> x.hex(digits=4)
- = "0x007B"
- >> x.octal()
- = "0o173"
+ assert x.hex() == "0x7B"
+ assert x.hex(digits=4) == "0x007B"
+ assert x.octal() == "0o173"
- >> Int64.min
- = Int64(-9223372036854775808)
- >> Int64.max
- = Int64(9223372036854775807)
+ assert Int64.min == Int64(-9223372036854775808)
+ assert Int64.max == Int64(9223372036854775807)
- >> Int32(123).hex()
- = "0x7B"
- >> Int16(123).hex()
- = "0x7B"
- >> Int8(123).hex()
- = "0x7B"
+ assert Int32(123).hex() == "0x7B"
+ assert Int16(123).hex() == "0x7B"
+ assert Int8(123).hex() == "0x7B"
- >> Int(2.1, truncate=yes)
- = 2
+ assert Int(2.1, truncate=yes) == 2
do
- >> small_int := 1
- = 1
- >> max_small_int := 536870911
- = 536870911
- >> max_i64 := 536870912
- = 536870912
- >> super_big := 9999999999999999999999
- = 9999999999999999999999
- >> max_small_int + 1
- = 536870912
-
- >> max_small_int + max_small_int
- = 1073741822
-
- >> super_big + 1
- = 10000000000000000000000
+ small_int := 1
+ assert small_int == 1
+ max_small_int := 536870911
+ assert max_small_int == 536870911
+ max_i64 := 536870912
+ assert max_i64 == 536870912
+ super_big := 9999999999999999999999
+ assert super_big == 9999999999999999999999
+ assert max_small_int + 1 == 536870912
+
+ assert max_small_int + max_small_int == 1073741822
+
+ assert super_big + 1 == 10000000000000000000000
do
interesting_numerators := [-999999, -100, -23, -1, 0, 1, 23, 100, 999999]
@@ -87,10 +69,8 @@ func main()
for d in interesting_denominators
assert (n/d)*d + (n mod d) == n
- >> (0).next_prime()
- = 2
- >> (7).next_prime()
- = 11
+ assert (0).next_prime() == 2
+ assert (7).next_prime() == 11
#>> (11).prev_prime()
#= 7
assert (and: p.is_prime() for p in [
@@ -107,51 +87,33 @@ func main()
771958616175795150904761471637,
])!
- >> (or: p.is_prime() for p in [
+ assert (or: p.is_prime() for p in [
-1, 0, 1, 4, 6,
137372146048179869781170214707*2,
811418847921670560768224995279*3,
292590241572454328697048860273*754893741683930091960170890717,
- ])!
- = no
-
- >> Int(yes)
- = 1
- >> Int(no)
- = 0
-
- >> Int64(yes)
- = Int64(1)
- >> Int64(no)
- = Int64(0)
-
- >> (4).choose(2)
- = 6
-
- >> (4).factorial()
- = 24
-
- >> (3).is_between(1, 5)
- = yes
- >> (3).is_between(1, 3)
- = yes
- >> (3).is_between(100, 200)
- = no
-
- >> (6).get_bit(1)
- = no
- >> (6).get_bit(2)
- = yes
- >> (6).get_bit(3)
- = yes
- >> (6).get_bit(4)
- = no
-
- >> Int64(6).get_bit(1)
- = no
- >> Int64(6).get_bit(2)
- = yes
- >> Int64(6).get_bit(3)
- = yes
- >> Int64(6).get_bit(4)
- = no
+ ])! == no
+
+ assert Int(yes) == 1
+ assert Int(no) == 0
+
+ assert Int64(yes) == Int64(1)
+ assert Int64(no) == Int64(0)
+
+ assert (4).choose(2) == 6
+
+ assert (4).factorial() == 24
+
+ assert (3).is_between(1, 5) == yes
+ assert (3).is_between(1, 3) == yes
+ assert (3).is_between(100, 200) == no
+
+ assert (6).get_bit(1) == no
+ assert (6).get_bit(2) == yes
+ assert (6).get_bit(3) == yes
+ assert (6).get_bit(4) == no
+
+ assert Int64(6).get_bit(1) == no
+ assert Int64(6).get_bit(2) == yes
+ assert Int64(6).get_bit(3) == yes
+ assert Int64(6).get_bit(4) == no