Skip to content

Commit 5c36cdb

Browse files
committed
Rename MillerRabin::check() to test() for uniformity with other methods
1 parent 1b89029 commit 5c36cdb

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010

1111
- `sieve_once()` was removed ([#22]).
1212
- `MillerRabin::new()` and `test_random_base()` will panic if the input is invalid. ([#22])
13+
- `MillerRabin::check()` renamed to `test()`. ([#22])
1314

1415

1516
### Added

src/hazmat/miller_rabin.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl<const L: usize> MillerRabin<L> {
5656
}
5757

5858
/// Perform a Miller-Rabin check with a given base.
59-
pub fn check(&self, base: &Uint<L>) -> Primality {
59+
pub fn test(&self, base: &Uint<L>) -> Primality {
6060
// TODO: it may be faster to first check that gcd(base, candidate) == 1,
6161
// otherwise we can return `Composite` right away.
6262

@@ -79,7 +79,7 @@ impl<const L: usize> MillerRabin<L> {
7979

8080
/// Perform a Miller-Rabin check with base 2.
8181
pub fn test_base_two(&self) -> Primality {
82-
self.check(&Uint::<L>::from(2u32))
82+
self.test(&Uint::<L>::from(2u32))
8383
}
8484

8585
/// Perform a Miller-Rabin check with a random base (in the range `[3, candidate-2]`)
@@ -98,7 +98,7 @@ impl<const L: usize> MillerRabin<L> {
9898
let range_nonzero = NonZero::new(range).unwrap();
9999
let random =
100100
Uint::<L>::random_mod(rng, &range_nonzero).wrapping_add(&Uint::<L>::from(3u32));
101-
self.check(&random)
101+
self.test(&random)
102102
}
103103
}
104104

@@ -188,10 +188,8 @@ mod tests {
188188
let mr = MillerRabin::new(&num);
189189

190190
// Trivial tests, must always be true.
191-
assert!(mr.check(&1u32.into()).is_probably_prime());
192-
assert!(mr
193-
.check(&num.wrapping_sub(&1u32.into()))
194-
.is_probably_prime());
191+
assert!(mr.test(&1u32.into()).is_probably_prime());
192+
assert!(mr.test(&num.wrapping_sub(&1u32.into())).is_probably_prime());
195193
}
196194
}
197195

@@ -246,10 +244,10 @@ mod tests {
246244

247245
// It is known to pass MR tests for all prime bases <307
248246
assert!(mr.test_base_two().is_probably_prime());
249-
assert!(mr.check(&U1536::from(293u64)).is_probably_prime());
247+
assert!(mr.test(&U1536::from(293u64)).is_probably_prime());
250248

251249
// A test with base 307 correctly reports the number as composite.
252-
assert!(!mr.check(&U1536::from(307u64)).is_probably_prime());
250+
assert!(!mr.test(&U1536::from(307u64)).is_probably_prime());
253251
}
254252

255253
fn test_large_primes<const L: usize>(nums: &[Uint<L>]) {

0 commit comments

Comments
 (0)