Skip to content

Commit 2f6f3a0

Browse files
committed
Increase test coverage of votes_needed
1 parent cb165ec commit 2f6f3a0

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

packages/cw3/src/proposal.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,36 @@ mod test {
196196
// round up right over 1
197197
assert_eq!(2, votes_needed(3, Decimal::permille(334)));
198198
assert_eq!(11, votes_needed(30, Decimal::permille(334)));
199+
// round up to full number of votes
200+
assert_eq!(420, votes_needed(420, Decimal::permille(999)));
199201

200202
// exact matches don't round
201203
assert_eq!(17, votes_needed(34, Decimal::percent(50)));
202204
assert_eq!(12, votes_needed(48, Decimal::percent(25)));
205+
206+
for x in [
207+
0,
208+
1,
209+
2,
210+
3,
211+
10,
212+
17,
213+
456,
214+
2020,
215+
7697987,
216+
18446744073709552,
217+
u64::MAX,
218+
] {
219+
assert_eq!(votes_needed(x, Decimal::zero()), 0);
220+
assert_eq!(votes_needed(x, Decimal::one()), x);
221+
if x % 2 == 0 {
222+
// even
223+
assert_eq!(votes_needed(x, Decimal::percent(50)), x / 2);
224+
} else {
225+
// odd
226+
assert_eq!(votes_needed(x, Decimal::percent(50)), x / 2 + 1);
227+
}
228+
}
203229
}
204230

205231
fn setup_prop(

0 commit comments

Comments
 (0)