|
| 1 | +import "stdlib/io.jou" |
| 2 | + |
| 3 | +def test_add() -> None: |
| 4 | + array = [1, 2] + [3, 4] |
| 5 | + printf("%d %d\n", array[0], array[1]) # Output: 4 6 |
| 6 | + |
| 7 | + array += [1, 1] |
| 8 | + printf("%d %d\n", array[0], array[1]) # Output: 5 7 |
| 9 | + |
| 10 | + with_offset = array + [0.5, 0.5] |
| 11 | + printf("%f %f\n", with_offset[0], with_offset[1]) # Output: 5.500000 7.500000 |
| 12 | + |
| 13 | + with_float_offset = array + [0.5 as float, 0.5 as float] |
| 14 | + printf("%f %f\n", with_float_offset[0], with_float_offset[1]) # Output: 5.500000 7.500000 |
| 15 | + |
| 16 | + # Output: Sizes: 16 and 8 |
| 17 | + printf("Sizes: %d and %d\n", sizeof(with_offset), sizeof(with_float_offset)) |
| 18 | + |
| 19 | + |
| 20 | +def test_sub() -> None: |
| 21 | + array = [1, 2] - [3, 5] |
| 22 | + printf("%d %d\n", array[0], array[1]) # Output: -2 -3 |
| 23 | + |
| 24 | + array -= [1, 1] |
| 25 | + printf("%d %d\n", array[0], array[1]) # Output: -3 -4 |
| 26 | + |
| 27 | + with_offset = array - [0.5, 0.5] |
| 28 | + printf("%f %f\n", with_offset[0], with_offset[1]) # Output: -3.500000 -4.500000 |
| 29 | + |
| 30 | + with_float_offset = array - [0.5 as float, 0.5 as float] |
| 31 | + printf("%f %f\n", with_float_offset[0], with_float_offset[1]) # Output: -3.500000 -4.500000 |
| 32 | + |
| 33 | + # Output: Sizes: 16 and 8 |
| 34 | + printf("Sizes: %d and %d\n", sizeof(with_offset), sizeof(with_float_offset)) |
| 35 | + |
| 36 | + |
| 37 | +def main() -> int: |
| 38 | + test_add() |
| 39 | + test_sub() |
| 40 | + return 0 |
0 commit comments