Skip to content

Commit

Permalink
add propertytesting for i32
Browse files Browse the repository at this point in the history
  • Loading branch information
pacman82 committed Dec 24, 2023
1 parent 7a637ba commit 1bfd9e3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ num-traits = { version = "0.2.14", default-features = false }

[dev-dependencies]
criterion = "0.5.1"
proptest = "1.4.0"

[[bench]]
name = "benches"
Expand Down
24 changes: 24 additions & 0 deletions tests/i32.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use proptest::prelude::proptest;
use atoi::{FromRadix10, FromRadix10Signed};

type N = i32;

proptest! {
#[test]
fn roundtrip_without_sign(n in 0..=N::MAX) {
let text = n.to_string();
let (actual, len) = N::from_radix_10(text.as_bytes());

assert_eq!(text.len(), len);
assert_eq!(n, actual);
}

#[test]
fn roundtrip_with_sign(n in N::MIN..=N::MAX) {
let text = n.to_string();
let (actual, len) = N::from_radix_10_signed(text.as_bytes());

assert_eq!(text.len(), len);
assert_eq!(n, actual);
}
}

0 comments on commit 1bfd9e3

Please sign in to comment.