@@ -123,14 +123,50 @@ fn mp_u256_add() {
123123 }
124124}
125125
126+ #[ test]
127+ fn mp_u256_sub ( ) {
128+ let mut rng = ChaCha8Rng :: from_seed ( * SEED ) ;
129+ let mut bx = BigInt :: new ( ) ;
130+ let mut by = BigInt :: new ( ) ;
131+
132+ for _ in 0 ..bigint_fuzz_iteration_count ( ) {
133+ let x = random_u256 ( & mut rng) ;
134+ let y = random_u256 ( & mut rng) ;
135+ assign_bigint ( & mut bx, x) ;
136+ assign_bigint ( & mut by, y) ;
137+
138+ // since the operators (may) panic on overflow,
139+ // we should test something that doesn't
140+ let actual = if x >= y { x - y } else { y - x } ;
141+ bx -= & by;
142+ bx. abs_mut ( ) ;
143+ check_one ( || hexu ( x) , || Some ( hexu ( y) ) , actual, & mut bx) ;
144+ }
145+ }
146+
147+ #[ test]
148+ fn mp_u256_shl ( ) {
149+ let mut rng = ChaCha8Rng :: from_seed ( * SEED ) ;
150+ let mut bx = BigInt :: new ( ) ;
151+
152+ for _ in 0 ..bigint_fuzz_iteration_count ( ) {
153+ let x = random_u256 ( & mut rng) ;
154+ let shift: u32 = rng. random_range ( 0 ..256 ) ;
155+ assign_bigint ( & mut bx, x) ;
156+ let actual = x << shift;
157+ bx <<= shift;
158+ check_one ( || hexu ( x) , || Some ( shift. to_string ( ) ) , actual, & mut bx) ;
159+ }
160+ }
161+
126162#[ test]
127163fn mp_u256_shr ( ) {
128164 let mut rng = ChaCha8Rng :: from_seed ( * SEED ) ;
129165 let mut bx = BigInt :: new ( ) ;
130166
131167 for _ in 0 ..bigint_fuzz_iteration_count ( ) {
132168 let x = random_u256 ( & mut rng) ;
133- let shift: u32 = rng. random_range ( 0 ..255 ) ;
169+ let shift: u32 = rng. random_range ( 0 ..256 ) ;
134170 assign_bigint ( & mut bx, x) ;
135171 let actual = x >> shift;
136172 bx >>= shift;
0 commit comments