Debian Codegraph @

tests/types.rs

raw symbols SCIP
1 /// Expands to a unique module with a variety of tests for the given sample newtype.
2 ///
3 /// Tests include basic operations and over/underflow checks.
4 macro_rules! test_typerust-analyzer cargo dasp_sample 0.11.0 test_type! {
5 ($T:ident, $mod_name:ident) => {
6 mod $mod_name {
7 #[test]
8 fn ops() {
9 use dasp_sample::types::$mod_name::$T;
10 assert_eq!(
11 $T::new(8).unwrap() + $T::new(12).unwrap(),
12 $T::new(20).unwrap()
13 );
14 assert_eq!(
15 $T::new(12).unwrap() - $T::new(4).unwrap(),
16 $T::new(8).unwrap()
17 );
18 assert_eq!(
19 $T::new(2).unwrap() * $T::new(2).unwrap(),
20 $T::new(4).unwrap()
21 );
22 assert_eq!(
23 $T::new(3).unwrap() * $T::new(3).unwrap(),
24 $T::new(9).unwrap()
25 );
26 assert_eq!(
27 $T::new(5).unwrap() * $T::new(10).unwrap(),
28 $T::new(50).unwrap()
29 );
30 assert_eq!(
31 $T::new(16).unwrap() / $T::new(8).unwrap(),
32 $T::new(2).unwrap()
33 );
34 assert_eq!(
35 $T::new(8).unwrap() % $T::new(3).unwrap(),
36 $T::new(2).unwrap()
37 );
38 }
39
40 #[cfg(debug_assertions)]
41 #[test]
42 #[should_panic]
43 fn add_panic_debug() {
44 use dasp_sample::types::$mod_name::{self, $T};
45 let _ = $mod_name::MAX + $T::new(1).unwrap();
46 }
47
48 #[cfg(debug_assertions)]
49 #[test]
50 #[should_panic]
51 fn sub_panic_debug() {
52 use dasp_sample::types::$mod_name::{self, $T};
53 let _ = $mod_name::MIN - $T::new(1).unwrap();
54 }
55
56 #[cfg(debug_assertions)]
57 #[test]
58 #[should_panic]
59 fn mul_panic_debug() {
60 use dasp_sample::types::$mod_name::{self, $T};
61 let _ = $mod_name::MAX * $T::new(2).unwrap();
62 }
63
64 #[cfg(not(debug_assertions))]
65 #[test]
66 fn release_wrapping() {
67 use dasp_sample::types::$mod_name::{self, $T};
68 assert_eq!($mod_name::MIN - $T::new(1).unwrap(), $mod_name::MAX);
69 assert_eq!($mod_name::MAX + $T::new(1).unwrap(), $mod_name::MIN);
70 }
71 }
72 };
73 }
74
75 test_typerust-analyzer cargo dasp_sample 0.11.0 test_type!!(I11rust-analyzer cargo dasp_sample 0.11.0 types/i11/I11#, i11rust-analyzer cargo dasp_sample 0.11.0 i11/);
76 test_typerust-analyzer cargo dasp_sample 0.11.0 test_type!!(U11rust-analyzer cargo dasp_sample 0.11.0 types/u11/U11#, u11rust-analyzer cargo dasp_sample 0.11.0 u11/);
77 test_typerust-analyzer cargo dasp_sample 0.11.0 test_type!!(I20rust-analyzer cargo dasp_sample 0.11.0 types/i20/I20#, i20rust-analyzer cargo dasp_sample 0.11.0 i20/);
78 test_typerust-analyzer cargo dasp_sample 0.11.0 test_type!!(U20rust-analyzer cargo dasp_sample 0.11.0 types/u20/U20#, u20rust-analyzer cargo dasp_sample 0.11.0 u20/);
79 test_typerust-analyzer cargo dasp_sample 0.11.0 test_type!!(I24rust-analyzer cargo dasp_sample 0.11.0 types/i24/I24#, i24rust-analyzer cargo dasp_sample 0.11.0 i24/);
80 test_typerust-analyzer cargo dasp_sample 0.11.0 test_type!!(U24rust-analyzer cargo dasp_sample 0.11.0 types/u24/U24#, u24rust-analyzer cargo dasp_sample 0.11.0 u24/);
81 test_typerust-analyzer cargo dasp_sample 0.11.0 test_type!!(I48rust-analyzer cargo dasp_sample 0.11.0 types/i48/I48#, i48rust-analyzer cargo dasp_sample 0.11.0 i48/);
82 test_typerust-analyzer cargo dasp_sample 0.11.0 test_type!!(U48rust-analyzer cargo dasp_sample 0.11.0 types/u48/U48#, u48rust-analyzer cargo dasp_sample 0.11.0 u48/);