@@ -59,3 +59,65 @@ fn widen_mul_u128() {
59
59
}
60
60
assert ! ( errors. is_empty( ) ) ;
61
61
}
62
+
63
+ #[ test]
64
+ fn not_u128 ( ) {
65
+ assert_eq ! ( !u256:: ZERO , u256:: MAX ) ;
66
+ }
67
+
68
+ #[ test]
69
+ fn shr_u128 ( ) {
70
+ let lo_a = [ 1 , 2 , 3 , 10 , u16:: MAX as u128 , u32:: MAX as u128 , u128:: MAX ] ;
71
+ let b = [ 0 , 1 , 2 , 4 , 10 , 31 , 32 , 33 , 64 , 96 , 127 ] ;
72
+
73
+ let mut errors = Vec :: new ( ) ;
74
+
75
+ for a in lo_a {
76
+ for b in b {
77
+ let res = a. widen ( ) >> b;
78
+ let expected = ( a >> b) . widen ( ) ;
79
+ if res != expected {
80
+ errors. push ( ( a, b, res, expected) ) ;
81
+ }
82
+ }
83
+ }
84
+
85
+ for ( a, b, res, expected) in & errors {
86
+ eprintln ! (
87
+ "FAILURE: {a:#034x} >> {b} = {} got {}" ,
88
+ hexu( * expected) ,
89
+ hexu( * res) ,
90
+ ) ;
91
+ }
92
+ assert ! ( errors. is_empty( ) ) ;
93
+ }
94
+
95
+ // #[test]
96
+ // fn shr_u128() {
97
+ // let tests = [
98
+ // (u128::MAX / 2, 2_u128, u256([u64::MAX - 1, u64::MAX, 0, 0])),
99
+ // (u128::MAX, 2_u128, u256([u64::MAX - 1, u64::MAX, 1, 0])),
100
+ // (u128::MAX, u128::MAX, u256([1, 0, u64::MAX - 1, u64::MAX])),
101
+ // (u128::MIN, u128::MIN, u256::ZERO),
102
+ // (1234, 0, u256::ZERO),
103
+ // (0, 1234, u256::ZERO),
104
+ // ];
105
+
106
+ // let mut errors = Vec::new();
107
+ // for (i, (a, b, exp)) in tests.iter().copied().enumerate() {
108
+ // let res = a.widen_mul(b);
109
+ // assert_eq!(res, res_z);
110
+ // if res != exp {
111
+ // errors.push((i, a, b, exp, res));
112
+ // }
113
+ // }
114
+
115
+ // for (i, a, b, exp, res) in &errors {
116
+ // eprintln!(
117
+ // "FAILURE ({i}): {a:#034x} * {b:#034x} = {} got {}",
118
+ // hexu(*exp),
119
+ // hexu(*res)
120
+ // );
121
+ // }
122
+ // assert!(errors.is_empty());
123
+ // }
0 commit comments