diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-09-21 23:23:59 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-09-21 23:23:59 -0400 |
| commit | 5824a2ef19879c59866667aced6b3f90e5925648 (patch) | |
| tree | a18ddeadb0c164c7a544b571c3968f86afb759ba /api/integers.md | |
| parent | bf067544e98f4085c26161953e301aaa00a904df (diff) | |
Update docs with proper assertions
Diffstat (limited to 'api/integers.md')
| -rw-r--r-- | api/integers.md | 101 |
1 files changed, 37 insertions, 64 deletions
diff --git a/api/integers.md b/api/integers.md index 6468589e..6af66b0d 100644 --- a/api/integers.md +++ b/api/integers.md @@ -20,8 +20,7 @@ x | `Int` | The integer whose absolute value is to be calculated. | - **Example:** ```tomo ->> (-10).abs() -= 10 +assert (-10).abs() == 10 ``` ## Int.choose @@ -42,8 +41,7 @@ k | `Int` | The number of things to be chosen. | - **Example:** ```tomo ->> (4).choose(2) -= 6 +assert (4).choose(2) == 6 ``` ## Int.clamped @@ -65,8 +63,7 @@ high | `Int` | The highest value the result can take. | - **Example:** ```tomo ->> (2).clamped(5, 10) -= 5 +assert (2).clamped(5, 10) == 5 ``` ## Int.factorial @@ -86,8 +83,7 @@ n | `Int` | The integer to compute the factorial of. | - **Example:** ```tomo ->> (10).factorial() -= 3628800 +assert (10).factorial() == 3628800 ``` ## Int.get_bit @@ -110,14 +106,10 @@ bit_index | `Int` | The index of the bit to check (1-indexed). | - **Example:** ```tomo ->> (6).get_bit(1) -= no ->> (6).get_bit(2) -= yes ->> (6).get_bit(3) -= yes ->> (6).get_bit(4) -= 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 ``` ## Int.hex @@ -140,8 +132,7 @@ prefix | `Bool` | Whether to include a "0x" prefix. | `yes` **Example:** ```tomo ->> (255).hex(digits=4, uppercase=yes, prefix=yes) -= "0x00FF" +assert (255).hex(digits=4, uppercase=yes, prefix=yes) == "0x00FF" ``` ## Int.is_between @@ -163,12 +154,9 @@ high | `Int` | The upper bound to check (inclusive). | - **Example:** ```tomo ->> (7).is_between(1, 10) -= yes ->> (7).is_between(100, 200) -= no ->> (7).is_between(1, 7) -= yes +assert (7).is_between(1, 10) == yes +assert (7).is_between(100, 200) == no +assert (7).is_between(1, 7) == yes ``` ## Int.is_prime @@ -191,10 +179,8 @@ reps | `Int` | The number of repetitions for primality tests. | `50` **Example:** ```tomo ->> (7).is_prime() -= yes ->> (6).is_prime() -= no +assert (7).is_prime() == yes +assert (6).is_prime() == no ``` ## Int.next_prime @@ -216,8 +202,7 @@ x | `Int` | The integer after which to find the next prime. | - **Example:** ```tomo ->> (11).next_prime() -= 13 +assert (11).next_prime() == 13 ``` ## Int.octal @@ -239,8 +224,7 @@ prefix | `Bool` | Whether to include a "0o" prefix. | `yes` **Example:** ```tomo ->> (64).octal(digits=4, prefix=yes) -= "0o0100" +assert (64).octal(digits=4, prefix=yes) == "0o0100" ``` ## Int.onward @@ -265,8 +249,7 @@ nums : &[Int] = &[] for i in (5).onward() nums.insert(i) stop if i == 10 ->> nums[] -= [5, 6, 7, 8, 9, 10] +assert nums[] == [5, 6, 7, 8, 9, 10] ``` ## Int.parse @@ -287,26 +270,18 @@ remainder | `&Text?` | If non-none, this argument will be set to the remainder o **Example:** ```tomo ->> Int.parse("123") -= 123 : Int? ->> Int.parse("0xFF") -= 255 : Int? - ->> Int.parse("123xyz") -= none +assert Int.parse("123") == 123 +assert Int.parse("0xFF") == 255 +assert Int.parse("123xyz") == none remainder : Text ->> Int.parse("123xyz", &remainder) -= 123 : Int? ->> remainder -= "xyz" +assert Int.parse("123xyz", &remainder) == 123 +assert remainder == "xyz" # Can't parse: ->> Int.parse("asdf") -= none : Int? +assert Int.parse("asdf") == none # Outside valid range: ->> Int8.parse("9999999") -= none : Int8? +assert Int8.parse("9999999") == none ``` ## Int.prev_prime @@ -328,8 +303,7 @@ x | `Int` | The integer before which to find the previous prime. | - **Example:** ```tomo ->> (11).prev_prime() -= 7 +assert (11).prev_prime() == 7 ``` ## Int.sqrt @@ -349,10 +323,8 @@ x | `Int` | The integer whose square root is to be calculated. | - **Example:** ```tomo ->> (16).sqrt() -= 4 ->> (17).sqrt() -= 4 +assert (16).sqrt() == 4 +assert (17).sqrt() == 4 ``` ## Int.to @@ -374,14 +346,15 @@ step | `Int?` | An optional step size to use. If unspecified or `none`, the step **Example:** ```tomo ->> (2).to(5) -= func(->Int?) ->> [x for x in (2).to(5)] -= [2, 3, 4, 5] ->> [x for x in (5).to(2)] -= [5, 4, 3, 2] - ->> [x for x in (2).to(5, step=2)] -= [2, 4] +iter := (2).to(5) +assert iter() == 2 +assert iter() == 3 +assert iter() == 4 +assert iter() == 5 +assert iter() == none + +assert [x for x in (2).to(5)] == [2, 3, 4, 5] +assert [x for x in (5).to(2)] == [5, 4, 3, 2] +assert [x for x in (2).to(5, step=2)] == [2, 4] ``` |
