Skip to content

Commit

Permalink
Merge pull request #154 from artichoke/lopopolo/mutation-coverage
Browse files Browse the repository at this point in the history
Add additional tests and doc examples
  • Loading branch information
lopopolo authored Jul 31, 2022
2 parents a143d92 + 6aed13f commit 27b9dc2
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rand_mt"
version = "4.1.2" # remember to set `html_root_url` in `src/lib.rs`.
version = "4.1.3" # remember to set `html_root_url` in `src/lib.rs`.
authors = ["David Creswick <dcrewi@gyrae.net>", "Ryan Lopopolo <rjl@hyperbo.la>"]
license = "MIT OR Apache-2.0"
edition = "2018"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Add this to your `Cargo.toml`:

```toml
[dependencies]
rand_mt = "4.1.2"
rand_mt = "4.1.3"
```

Then create a RNG like:
Expand Down
27 changes: 26 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
//! [`rand_core`]: https://crates.io/crates/rand_core
//! [`std::error::error`]: https://doc.rust-lang.org/std/error/trait.Error.html

#![doc(html_root_url = "https://docs.rs/rand_mt/4.1.2")]
#![doc(html_root_url = "https://docs.rs/rand_mt/4.1.3")]
#![no_std]

// Ensure code blocks in README.md compile
Expand Down Expand Up @@ -166,3 +166,28 @@ impl fmt::Display for RecoverRngError {

#[cfg(feature = "std")]
impl std::error::Error for RecoverRngError {}

#[cfg(test)]
mod tests {
#[cfg(feature = "std")]
use super::RecoverRngError;

#[test]
#[cfg(feature = "std")]
fn error_display_is_not_empty() {
use core::fmt::Write as _;
use std::string::String;

let test_cases = [
RecoverRngError::TooFewSamples(0),
RecoverRngError::TooFewSamples(124),
RecoverRngError::TooManySamples(0),
RecoverRngError::TooManySamples(987),
];
for tc in test_cases {
let mut buf = String::new();
write!(&mut buf, "{}", tc).unwrap();
assert!(!buf.is_empty());
}
}
}
17 changes: 17 additions & 0 deletions src/mt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,23 @@ impl From<u32> for Mt19937GenRand32 {
///
/// This function is equivalent to [`new`].
///
/// # Examples
///
/// ```
/// # use rand_mt::Mt19937GenRand32;
/// // Default MT seed
/// let seed = 5489_u32;
/// let mt1 = Mt19937GenRand32::from(seed);
/// let mt2 = Mt19937GenRand32::new(seed);
/// assert_eq!(mt1, mt2);
///
/// // Non-default MT seed
/// let seed = 9927_u32;
/// let mt1 = Mt19937GenRand32::from(seed);
/// let mt2 = Mt19937GenRand32::new(seed);
/// assert_eq!(mt1, mt2);
/// ```
///
/// [`new`]: Self::new
#[inline]
fn from(seed: u32) -> Self {
Expand Down
17 changes: 17 additions & 0 deletions src/mt64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,23 @@ impl From<u64> for Mt19937GenRand64 {
///
/// This function is equivalent to [`new`].
///
/// # Examples
///
/// ```
/// # use rand_mt::Mt19937GenRand64;
/// // Default MT seed
/// let seed = 5489_u64;
/// let mt1 = Mt19937GenRand64::from(seed);
/// let mt2 = Mt19937GenRand64::new(seed);
/// assert_eq!(mt1, mt2);
///
/// // Non-default MT seed
/// let seed = 9927_u64;
/// let mt1 = Mt19937GenRand64::from(seed);
/// let mt2 = Mt19937GenRand64::new(seed);
/// assert_eq!(mt1, mt2);
/// ```
///
/// [`new`]: Self::new
#[inline]
fn from(seed: u64) -> Self {
Expand Down

0 comments on commit 27b9dc2

Please sign in to comment.