Skip to content

Commit a8e0120

Browse files
committed
math: add tests for math.divide_floored, math.divide_euclid, and math.divide_truncated too
1 parent a48e8e2 commit a8e0120

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

vlib/math/modulo_test.v

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,75 @@ fn test_modulo() {
6868
assert math.modulo_floored(-4, -5) == -4
6969
assert math.modulo_truncated(-4, -5) == -4
7070
}
71+
72+
fn test_divide_both_positive() {
73+
assert math.divide_euclid(10, 2) == math.DivResult[int]{5, 0}
74+
assert math.divide_floored(10, 2) == math.DivResult[int]{5, 0}
75+
assert math.divide_truncated(10, 2) == math.DivResult[int]{5, 0}
76+
77+
assert math.divide_euclid(10, 3) == math.DivResult[int]{3, 1}
78+
assert math.divide_floored(10, 3) == math.DivResult[int]{3, 1}
79+
assert math.divide_truncated(10, 3) == math.DivResult[int]{3, 1}
80+
81+
assert math.divide_euclid(10, 5) == math.DivResult[int]{2, 0}
82+
assert math.divide_floored(10, 5) == math.DivResult[int]{2, 0}
83+
assert math.divide_truncated(10, 5) == math.DivResult[int]{2, 0}
84+
85+
assert math.divide_euclid(10, 7) == math.DivResult[int]{1, 3}
86+
assert math.divide_floored(10, 7) == math.DivResult[int]{1, 3}
87+
assert math.divide_truncated(10, 7) == math.DivResult[int]{1, 3}
88+
}
89+
90+
fn test_divide_positive_divident_and_negative_divisor() {
91+
assert math.divide_euclid(10, -2) == math.DivResult[int]{-5, 0}
92+
assert math.divide_floored(10, -2) == math.DivResult[int]{-5, 0}
93+
assert math.divide_truncated(10, -2) == math.DivResult[int]{-5, 0}
94+
95+
assert math.divide_euclid(10, -3) == math.DivResult[int]{-3, 1}
96+
assert math.divide_floored(10, -3) == math.DivResult[int]{-4, -2}
97+
assert math.divide_truncated(10, -3) == math.DivResult[int]{-3, 1}
98+
99+
assert math.divide_euclid(10, -5) == math.DivResult[int]{-2, 0}
100+
assert math.divide_floored(10, -5) == math.DivResult[int]{-2, 0}
101+
assert math.divide_truncated(10, -5) == math.DivResult[int]{-2, 0}
102+
103+
assert math.divide_euclid(10, -7) == math.DivResult[int]{-1, 3}
104+
assert math.divide_floored(10, -7) == math.DivResult[int]{-2, -4}
105+
assert math.divide_truncated(10, -7) == math.DivResult[int]{-1, 3}
106+
}
107+
108+
fn test_divide_negative_divident_and_positive_divisor() {
109+
assert math.divide_euclid(-10, 2) == math.DivResult[int]{-5, 0}
110+
assert math.divide_floored(-10, 2) == math.DivResult[int]{-5, 0}
111+
assert math.divide_truncated(-10, 2) == math.DivResult[int]{-5, 0}
112+
113+
assert math.divide_euclid(-10, 3) == math.DivResult[int]{-4, 2}
114+
assert math.divide_floored(-10, 3) == math.DivResult[int]{-4, 2}
115+
assert math.divide_truncated(-10, 3) == math.DivResult[int]{-3, -1}
116+
117+
assert math.divide_euclid(-10, 5) == math.DivResult[int]{-2, 0}
118+
assert math.divide_floored(-10, 5) == math.DivResult[int]{-2, 0}
119+
assert math.divide_truncated(-10, 5) == math.DivResult[int]{-2, 0}
120+
121+
assert math.divide_euclid(-10, 7) == math.DivResult[int]{-2, 4}
122+
assert math.divide_floored(-10, 7) == math.DivResult[int]{-2, 4}
123+
assert math.divide_truncated(-10, 7) == math.DivResult[int]{-1, -3}
124+
}
125+
126+
fn test_divide_both_negative() {
127+
assert math.divide_euclid(-10, -2) == math.DivResult[int]{5, 0}
128+
assert math.divide_floored(-10, -2) == math.DivResult[int]{5, 0}
129+
assert math.divide_truncated(-10, -2) == math.DivResult[int]{5, 0}
130+
131+
assert math.divide_euclid(-10, -3) == math.DivResult[int]{4, 2}
132+
assert math.divide_floored(-10, -3) == math.DivResult[int]{3, -1}
133+
assert math.divide_truncated(-10, -3) == math.DivResult[int]{3, -1}
134+
135+
assert math.divide_euclid(-10, -5) == math.DivResult[int]{2, 0}
136+
assert math.divide_floored(-10, -5) == math.DivResult[int]{2, 0}
137+
assert math.divide_truncated(-10, -5) == math.DivResult[int]{2, 0}
138+
139+
assert math.divide_euclid(-10, -7) == math.DivResult[int]{2, 4}
140+
assert math.divide_floored(-10, -7) == math.DivResult[int]{1, -3}
141+
assert math.divide_truncated(-10, -7) == math.DivResult[int]{1, -3}
142+
}

0 commit comments

Comments
 (0)