Skip to content

Commit

Permalink
Fix unit-tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaker committed Dec 13, 2023
1 parent 01fec74 commit 95c8195
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

- [\#689](https://github.com/arkworks-rs/algebra/pull/689) (`ark-serialize`) Add `CanonicalSerialize` and `CanonicalDeserialize` impls for `VecDeque` and `LinkedList`.
- [\#693](https://github.com/arkworks-rs/algebra/pull/693) (`ark-serialize`) Add `serialize_to_vec!` convenience macro.
- [\#713](https://github.com/arkworks-rs/algebra/pull/713) (`ark-ff`) Add support for bitwise operations AND, OR, NOT, and XOR between `BigInteger`.
- [\#713](https://github.com/arkworks-rs/algebra/pull/713) (`ark-ff`) Add support for bitwise operations AND, OR, and XOR between `BigInteger`.

### Breaking changes

Expand Down
33 changes: 14 additions & 19 deletions ff/src/biginteger/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::{biginteger::BigInteger, BigInt, UniformRand};
use num_bigint::BigUint;
use ark_std::rand::Rng;

// Test elementary math operations for BigInteger.
fn biginteger_arithmetic_test<B: BigInteger>(a: B, b: B, zero: B) {
Expand Down Expand Up @@ -58,46 +59,40 @@ fn biginteger_bitwise_ops_test<B: BigInteger>() {
// Test XOR
// a xor a = 0
let a: BigInt<4> = UniformRand::rand(&mut rng);
let a_clone = a.clone();
assert_eq!(a ^ a_clone, BigInt::from(0_u64));
assert_eq!(a ^ &a, BigInt::from(0_u64));

// Testing a xor b xor b
let a: BigInt<4> = UniformRand::rand(&mut rng);
let b: BigInt<4> = UniformRand::rand(&mut rng);
let a_clone = a.clone();
let b_clone = b.clone();
let xor_ab = a ^ b;
assert_eq!(xor_ab ^ b_clone, a_clone);
assert_eq!(xor_ab ^ b, a);

// Test OR
// a or a = a
let a: BigInt<4> = UniformRand::rand(&mut rng);
let a_clone = a.clone();
assert_eq!(a | a_clone, a);
let a = rng.gen::<BigInt<4>>();
assert_eq!(a | &a, a);

// Testing a or b or b
let a: BigInt<4> = UniformRand::rand(&mut rng);
let b: BigInt<4> = UniformRand::rand(&mut rng);
let b_clone = b.clone();
let a = rng.gen::<BigInt<4>>();
let b = rng.gen::<BigInt<4>>();
let or_ab = a | b;
assert_eq!(or_ab | b_clone, a | b);
assert_eq!(or_ab | &b, a | b);

// Test AND
// a and a = a
let a: BigInt<4> = UniformRand::rand(&mut rng);
let a_clone = a.clone();
assert_eq!(a & a_clone, a);
let a = rng.gen::<BigInt<4>>();
assert_eq!(a & (&a), a);

// Testing a and a and b.
let a: BigInt<4> = UniformRand::rand(&mut rng);
let b: BigInt<4> = UniformRand::rand(&mut rng);
let a = rng.gen::<BigInt<4>>();
let b = rng.gen::<BigInt<4>>();
let b_clone = b.clone();
let and_ab = a & b;
assert_eq!(and_ab & b_clone, a & b);

// Testing De Morgan's law
let a: BigInt<4> = UniformRand::rand(&mut rng);
let b = UniformRand::rand(&mut rng);
let a = rng.gen::<BigInt<4>>();
let b = rng.gen::<BigInt<4>>();
let de_morgan_lhs = !(a | b);
let de_morgan_rhs = (!a) & (!b);
assert_eq!(de_morgan_lhs, de_morgan_rhs);
Expand Down

0 comments on commit 95c8195

Please sign in to comment.