Skip to content

Commit

Permalink
Added approx_eq! macro for expm1 tests. (#665)
Browse files Browse the repository at this point in the history
* Added approx_eq! macro for expm1 tests.

Added approx_eq! macro for expm1 tests due to floating point arithmetic
inaccuracies, using default ULP & epsilon values. approx_eq! macro does
not work for NaN values, however, for tests this should be okay anyway!
Solves #664.

* Modified Cargo.toml to remove unneeded feature.

Removed std feature as was unused in test.

* Moves `float-cmp` to Dev Dependencies

Refactors tan() unit test, previously unused, to use approx_eq!() macro
for assertion to pass on CI.

* Fixes cargo fmt errors
  • Loading branch information
neeldug committed Aug 28, 2020
1 parent cb93472 commit 2d31ea3
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 17 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions boa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ once_cell = { version = "1.4.1", optional = true }

[dev-dependencies]
criterion = "=0.3.2"
float-cmp = "0.8.0"

[target.x86_64-unknown-linux-gnu.dev-dependencies]
jemallocator = "0.3.2"
Expand Down
52 changes: 35 additions & 17 deletions boa/src/builtins/math/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,26 @@ fn expm1() {

assert_eq!(a, String::from("NaN"));
assert_eq!(b, String::from("NaN"));
assert_eq!(c.to_number(&mut engine).unwrap(), 1.718_281_828_459_045);
assert_eq!(d.to_number(&mut engine).unwrap(), -0.632_120_558_828_557_7);
assert_eq!(e.to_number(&mut engine).unwrap(), 0_f64);
assert_eq!(f.to_number(&mut engine).unwrap(), 6.389_056_098_930_65);
assert!(float_cmp::approx_eq!(
f64,
c.to_number(&mut engine).unwrap(),
1.718_281_828_459_045
));
assert!(float_cmp::approx_eq!(
f64,
d.to_number(&mut engine).unwrap(),
-0.632_120_558_828_557_7
));
assert!(float_cmp::approx_eq!(
f64,
e.to_number(&mut engine).unwrap(),
0_f64
));
assert!(float_cmp::approx_eq!(
f64,
f.to_number(&mut engine).unwrap(),
6.389_056_098_930_65
));
}

#[test]
Expand Down Expand Up @@ -690,22 +706,24 @@ fn sqrt() {
assert_eq!(c.to_number(&mut engine).unwrap(), 3_f64);
}

// TODO: Precision is always off between ci and local. We proably need a better way to compare floats anyways

// #[test]
// fn tan() {
// let realm = Realm::create();
// let mut engine = Interpreter::new(realm);
// let init = r#"
// var a = Math.tan(1.1);
// "#;
#[test]
fn tan() {
let realm = Realm::create();
let mut engine = Interpreter::new(realm);
let init = r#"
var a = Math.tan(1.1);
"#;

// eprintln!("{}", forward(&mut engine, init));
eprintln!("{}", forward(&mut engine, init));

// let a = forward_val(&mut engine, "a").unwrap();
let a = forward_val(&mut engine, "a").unwrap();

// assert_eq!(a.to_number(), f64::from(1.964_759_657_248_652_5));
// }
assert!(float_cmp::approx_eq!(
f64,
a.to_number(&mut engine).unwrap(),
f64::from(1.964_759_657_248_652_5)
));
}

#[test]
fn tanh() {
Expand Down

0 comments on commit 2d31ea3

Please sign in to comment.