Browse Source

Added approx_eq! macro for expm1 tests. (#665)

* 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
pull/671/head
neeldug 4 years ago committed by GitHub
parent
commit
2d31ea3481
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      Cargo.lock
  2. 1
      boa/Cargo.toml
  3. 52
      boa/src/builtins/math/tests.rs

10
Cargo.lock generated

@ -7,6 +7,7 @@ dependencies = [
"bitflags",
"chrono",
"criterion",
"float-cmp",
"gc",
"indexmap",
"jemallocator",
@ -345,6 +346,15 @@ version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd56b59865bce947ac5958779cfa508f6c3b9497cc762b7e24a12d11ccde2c4f"
[[package]]
name = "float-cmp"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e1267f4ac4f343772758f7b1bdcbe767c218bbab93bb432acbf5162bbf85a6c4"
dependencies = [
"num-traits",
]
[[package]]
name = "fs_extra"
version = "1.1.0"

1
boa/Cargo.toml

@ -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"

52
boa/src/builtins/math/tests.rs

@ -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]
@ -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() {

Loading…
Cancel
Save