Debian Codegraph @

tests/tests.rs

raw symbols SCIP
1 use const_random::const_random;
2
3 #[test]
4 fn u32() {
5 const VALUE1: u32 = const_random!(u32);
6 const VALUE2: u32 = const_random!(u32);
7 assert_ne!(0, VALUE1, "A random generated constant was zero. (This can randomly occur one time in 2^32) If this reproduces, it is a bug.");
8 assert_ne!(0, VALUE2, "A random generated constant was zero. (This can randomly occur one time in 2^32) If this reproduces, it is a bug.");
9 assert_ne!(VALUE1, VALUE2, "A random generated constant was the same as another. (This can randomly occur one time in 2^32) If this reproduces, it is a bug.");
10 }
11
12 #[test]
13 fn i64() {
14 const VALUE1: i64 = const_random!(i64);
15 const VALUE2: i64 = const_random!(i64);
16 assert_ne!(0, VALUE1, "A random generated constant was zero. (This can randomly occur one time in 2^64) If this reproduces, it is a bug.");
17 assert_ne!(0, VALUE2, "A random generated constant was zero. (This can randomly occur one time in 2^64) If this reproduces, it is a bug.");
18 assert_ne!(VALUE1, VALUE2, "A random generated constant was the same as another. (This can randomly occur one time in 2^64) If this reproduces, it is a bug.");
19 }
20
21 #[test]
22 fn usize() {
23 const VALUE1: usize = const_random!(usize);
24 const VALUE2: usize = const_random!(usize);
25 assert_ne!(0, VALUE1, "A random generated constant was zero. (This can randomly occur one time in 2^64) If this reproduces, it is a bug.");
26 assert_ne!(0, VALUE2, "A random generated constant was zero. (This can randomly occur one time in 2^64) If this reproduces, it is a bug.");
27 assert_ne!(VALUE1, VALUE2, "A random generated constant was the same as another. (This can randomly occur one time in 2^64) If this reproduces, it is a bug.");
28 }
29
30 #[test]
31 fn u128() {
32 const VALUE1: u128 = const_random!(u128);
33 const VALUE2: u128 = const_random!(u128);
34 assert_ne!(0, VALUE1);
35 assert_ne!(0, VALUE2);
36 assert_ne!(VALUE1, VALUE2);
37 }
38
39 #[test]
40 fn suffixed() {
41 fn f<T>(_: T) {
42 // If const_random! emits an unsuffixed integer literal, this assertion
43 // would fail because T would be inferred as the default unsuffixed
44 // integer literal type i32.
45 assert_eq!("u8", std::any::type_name::<T>());
46 }
47 f(const_random!(u8));
48 }
49
50 #[test]
51 fn array() {
52 const VALUE1: &[u8] = &const_random!([u8; 30]);
53 const VALUE2: [u8; 30] = const_random!([u8; 30]);
54 assert_ne!([0u8; 30], VALUE1);
55 assert_ne!([0u8; 30], VALUE2);
56 assert_ne!(VALUE1, VALUE2);
57 }