Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added approx_eq! macro for expm1 tests. #665

Merged
merged 4 commits into from
Aug 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

3 changes: 2 additions & 1 deletion boa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ once_cell = { version = "1.4.0", 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 All @@ -57,4 +58,4 @@ harness = false

[[bench]]
name = "full"
harness = false
harness = false
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