Trevor Gross 2d857e1c21 Replace HasDomain to enable multi-argument edge case and domain tests
This also allows reusing the same generator logic between logspace tests
and extensive tests, so comes with a nice bit of cleanup.

Changes:

* Make the generator part of `CheckCtx` since a `Generator` and
  `CheckCtx` are almost always passed together.
* Rename `domain_logspace` to `spaced` since this no longer only
  operates within a domain and we may want to handle integer spacing.
* Domain is now calculated at runtime rather than using traits, which is
  much easier to work with.
* With the above, domains for multidimensional functions are added.
* The extensive test generator code tests has been combined with the
  domain_logspace generator code. With this, the domain tests have just
  become a subset of extensive tests. These were renamed to "quickspace"
  since, technically, the extensive tests are also "domain" or "domain
  logspace" tests.
* Edge case generators now handle functions with multiple inputs.
* The test runners can be significantly cleaned up and deduplicated.
2025-01-16 01:10:26 +00:00

43 lines
1.0 KiB
Rust

//! Different generators that can create random or systematic bit patterns.
pub mod edge_cases;
pub mod random;
pub mod spaced;
/// A wrapper to turn any iterator into an `ExactSizeIterator`. Asserts the final result to ensure
/// the provided size was correct.
#[derive(Debug)]
pub struct KnownSize<I> {
total: u64,
current: u64,
iter: I,
}
impl<I> KnownSize<I> {
pub fn new(iter: I, total: u64) -> Self {
Self { total, current: 0, iter }
}
}
impl<I: Iterator> Iterator for KnownSize<I> {
type Item = I::Item;
fn next(&mut self) -> Option<Self::Item> {
let next = self.iter.next();
if next.is_some() {
self.current += 1;
return next;
}
assert_eq!(self.current, self.total, "total items did not match expected");
None
}
fn size_hint(&self) -> (usize, Option<usize>) {
let remaining = usize::try_from(self.total - self.current).unwrap();
(remaining, Some(remaining))
}
}
impl<I: Iterator> ExactSizeIterator for KnownSize<I> {}