Skip to content

Commit

Permalink
Test improved
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Delmas <[email protected]>
  • Loading branch information
tdelmas committed Jul 7, 2023
1 parent a77b7ee commit 2ee254c
Show file tree
Hide file tree
Showing 9 changed files with 346 additions and 186 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Build
run: cargo build --verbose
run: |
du -sh
cargo build --verbose
du -sh
- name: Run tests
run: cargo test --verbose
run: |
du -sh
cargo test --verbose
du -sh
- name: Run clippy
run: cargo clippy --verbose
7 changes: 7 additions & 0 deletions typed_floats/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ description = "Types for handling floats with type checking at compile time."
repository = "https://github.com/tdelmas/floats"
readme = "./README.md"

[profile.dev]
incremental = false

[profile.test]
incremental = false

[dependencies]
serde_json = { version = "1.0"}
thiserror = "1.0"
typed_floats_macros = { version = "0.1.6" }

35 changes: 0 additions & 35 deletions typed_floats/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,38 +97,3 @@ pub const MIN: StrictlyNegativeFinite = StrictlyNegativeFinite(f64::MIN);
pub const MIN_POSITIVE: StrictlyPositiveFinite = StrictlyPositiveFinite(f64::MIN_POSITIVE);
pub const ZERO: PositiveFinite = PositiveFinite(0.0f64);
pub const NEGATIVE_ZERO: NegativeFinite = NegativeFinite(-0.0f64);

#[cfg(test)]
mod tests {

use crate::*;

typed_floats_macros::generate_tests!();

#[test]
fn test_others() {
let values = [
(f64::NAN, false),
(f64::INFINITY, true),
(f64::NEG_INFINITY, true),
(0.0f64, true),
(-0.0f64, true),
(1.0f64, true),
(-1.0f64, true),
];

for (value, expected) in &values {
let num = NonNaN::try_from(*value);
let result = num.is_ok();
assert_eq!(result, *expected);

match num {
Ok(num) => {
let v: f64 = num.into();
assert_eq!(v, *value);
}
Err(_) => {}
}
}
}
}
30 changes: 30 additions & 0 deletions typed_floats/tests/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use typed_floats::*;

typed_floats_macros::generate_tests!();

#[test]
fn test_others() {
let values = [
(f64::NAN, false),
(f64::INFINITY, true),
(f64::NEG_INFINITY, true),
(0.0f64, true),
(-0.0f64, true),
(1.0f64, true),
(-1.0f64, true),
];

for (value, expected) in &values {
let num = NonNaN::try_from(*value);
let result = num.is_ok();
assert_eq!(result, *expected);

match num {
Ok(num) => {
let v: f64 = num.into();
assert_eq!(v, *value);
}
Err(_) => {}
}
}
}
6 changes: 6 additions & 0 deletions typed_floats_macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ description = "Crate only used to generate the `typed_floats` crate."
repository = "https://github.com/tdelmas/floats"
readme = "./README.md"

[profile.dev]
incremental = false

[profile.test]
incremental = false

[lib]
proc-macro = true

Expand Down
Loading

0 comments on commit 2ee254c

Please sign in to comment.