Skip to content

Commit 6acc29f

Browse files
author
Lukas Markeffsky
committed
add tests for panicking integer logarithms
1 parent 69cafc0 commit 6acc29f

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

library/core/tests/num/int_log.rs

+30
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,33 @@ fn ilog10_u64() {
164164
fn ilog10_u128() {
165165
ilog10_loop! { u128, 38 }
166166
}
167+
168+
#[test]
169+
#[should_panic(expected = "argument of integer logarithm must be positive")]
170+
fn ilog2_of_0_panic() {
171+
let _ = 0u32.ilog2();
172+
}
173+
174+
#[test]
175+
#[should_panic(expected = "argument of integer logarithm must be positive")]
176+
fn ilog10_of_0_panic() {
177+
let _ = 0u32.ilog10();
178+
}
179+
180+
#[test]
181+
#[should_panic(expected = "argument of integer logarithm must be positive")]
182+
fn ilog3_of_0_panic() {
183+
let _ = 0u32.ilog(3);
184+
}
185+
186+
#[test]
187+
#[should_panic(expected = "base of integer logarithm must be at least 2")]
188+
fn ilog0_of_1_panic() {
189+
let _ = 1u32.ilog(0);
190+
}
191+
192+
#[test]
193+
#[should_panic(expected = "base of integer logarithm must be at least 2")]
194+
fn ilog1_of_1_panic() {
195+
let _ = 1u32.ilog(1);
196+
}

0 commit comments

Comments
 (0)