Auto merge of #18 - ebfull:primefieldreprtests, r=ebfull
Random encoding/decoding tests for `PrimeFieldRepr`
This commit is contained in:
commit
8fc026bb61
@ -1750,3 +1750,8 @@ fn test_fq_ordering() {
|
||||
assert!(Fq::from_repr(FqRepr::from(i+1)).unwrap() > Fq::from_repr(FqRepr::from(i)).unwrap());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fq_repr_tests() {
|
||||
::tests::repr::random_repr_tests::<FqRepr>();
|
||||
}
|
||||
|
@ -1453,3 +1453,8 @@ fn fr_field_tests() {
|
||||
::tests::field::random_sqrt_tests::<Fr>();
|
||||
::tests::field::random_frobenius_tests::<Fr, _>(Fr::char(), 13);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fr_repr_tests() {
|
||||
::tests::repr::random_repr_tests::<FrRepr>();
|
||||
}
|
||||
|
@ -332,6 +332,7 @@ pub trait PrimeFieldRepr: Sized +
|
||||
Ord +
|
||||
Send +
|
||||
Sync +
|
||||
Default +
|
||||
fmt::Debug +
|
||||
fmt::Display +
|
||||
'static +
|
||||
|
@ -1,3 +1,4 @@
|
||||
pub mod curve;
|
||||
pub mod field;
|
||||
pub mod engine;
|
||||
pub mod repr;
|
||||
|
21
src/tests/repr.rs
Normal file
21
src/tests/repr.rs
Normal file
@ -0,0 +1,21 @@
|
||||
use rand::{SeedableRng, XorShiftRng};
|
||||
use ::{PrimeFieldRepr};
|
||||
|
||||
pub fn random_repr_tests<R: PrimeFieldRepr>() {
|
||||
random_encoding_tests::<R>();
|
||||
}
|
||||
|
||||
fn random_encoding_tests<R: PrimeFieldRepr>() {
|
||||
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
|
||||
|
||||
for _ in 0..1000 {
|
||||
let r = R::rand(&mut rng);
|
||||
let mut rdecoded = R::default();
|
||||
|
||||
let mut v: Vec<u8> = vec![];
|
||||
r.write_be(&mut v).unwrap();
|
||||
rdecoded.read_be(&v[0..]).unwrap();
|
||||
|
||||
assert_eq!(r, rdecoded);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user