v/vlib/math/modulo_test.v

71 lines
2.6 KiB
V

import math
fn test_modulo() {
assert math.modulo_euclid(5, 1) == 0
assert math.modulo_floored(5, 1) == 0
assert math.modulo_truncated(5, 1) == 0
assert math.modulo_euclid(5, 2) == 1
assert math.modulo_floored(5, 2) == 1
assert math.modulo_truncated(5, 2) == 1
assert math.modulo_euclid(5, 3) == 2
assert math.modulo_floored(5, 3) == 2
assert math.modulo_truncated(5, 3) == 2
assert math.modulo_euclid(5, 4) == 1
assert math.modulo_floored(5, 4) == 1
assert math.modulo_truncated(5, 4) == 1
assert math.modulo_euclid(5, 5) == 0
assert math.modulo_floored(5, 5) == 0
assert math.modulo_truncated(5, 5) == 0
assert math.modulo_euclid(-5, 1) == 0
assert math.modulo_floored(-5, 1) == 0
assert math.modulo_truncated(-5, 1) == 0
assert math.modulo_euclid(-5, 2) == 1
assert math.modulo_floored(-5, 2) == 1
assert math.modulo_truncated(-5, 2) == -1
assert math.modulo_euclid(-5, 3) == 1
assert math.modulo_floored(-5, 3) == 1
assert math.modulo_truncated(-5, 3) == -2
assert math.modulo_euclid(-5, 4) == 3
assert math.modulo_floored(-5, 4) == 3
assert math.modulo_truncated(-5, 4) == -1
assert math.modulo_euclid(-5, 5) == 0
assert math.modulo_floored(-5, 5) == 0
assert math.modulo_truncated(-5, 5) == 0
assert math.modulo_euclid(1, 5) == 1
assert math.modulo_floored(1, 5) == 1
assert math.modulo_truncated(1, 5) == 1
assert math.modulo_euclid(2, 5) == 2
assert math.modulo_floored(2, 5) == 2
assert math.modulo_truncated(2, 5) == 2
assert math.modulo_euclid(3, 5) == 3
assert math.modulo_floored(3, 5) == 3
assert math.modulo_truncated(3, 5) == 3
assert math.modulo_euclid(4, 5) == 4
assert math.modulo_floored(4, 5) == 4
assert math.modulo_truncated(4, 5) == 4
assert math.modulo_euclid(-1, 5) == 4
assert math.modulo_floored(-1, 5) == 4
assert math.modulo_truncated(-1, 5) == -1
assert math.modulo_euclid(-2, 5) == 3
assert math.modulo_floored(-2, 5) == 3
assert math.modulo_truncated(-2, 5) == -2
assert math.modulo_euclid(-3, 5) == 2
assert math.modulo_floored(-3, 5) == 2
assert math.modulo_truncated(-3, 5) == -3
assert math.modulo_euclid(-4, 5) == 1
assert math.modulo_floored(-4, 5) == 1
assert math.modulo_truncated(-4, 5) == -4
assert math.modulo_euclid(-1, -5) == 4
assert math.modulo_floored(-1, -5) == -1
assert math.modulo_truncated(-1, -5) == -1
assert math.modulo_euclid(-2, -5) == 3
assert math.modulo_floored(-2, -5) == -2
assert math.modulo_truncated(-2, -5) == -2
assert math.modulo_euclid(-3, -5) == 2
assert math.modulo_floored(-3, -5) == -3
assert math.modulo_truncated(-3, -5) == -3
assert math.modulo_euclid(-4, -5) == 1
assert math.modulo_floored(-4, -5) == -4
assert math.modulo_truncated(-4, -5) == -4
}