Skip to content

Commit

Permalink
[boa-dev#524] add tests for more states
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-rodgers committed Jun 26, 2020
1 parent 4649739 commit e51ee81
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions boa/src/builtins/math/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ fn fround() {
var d = Math.fround(5.5);
var e = Math.fround(5.05);
var f = Math.fround(-5.05);
var g = Math.fround();
"#;

eprintln!("{}", forward(&mut engine, init));
Expand All @@ -351,13 +352,15 @@ fn fround() {
let d = forward_val(&mut engine, "d").unwrap();
let e = forward_val(&mut engine, "e").unwrap();
let f = forward_val(&mut engine, "f").unwrap();
let g = forward(&mut engine, "g");

assert_eq!(a, String::from("NaN"));
assert_eq!(b, String::from("Infinity"));
assert_eq!(c.to_number(), 5f64);
assert_eq!(d.to_number(), 5.5f64);
assert_eq!(e.to_number(), 5.050_000_190_734_863);
assert_eq!(f.to_number(), -5.050_000_190_734_863);
assert_eq!(g, String::from("NaN"));
}

#[test]
Expand All @@ -371,6 +374,7 @@ fn hypot() {
var d = Math.hypot(3, 4, -5);
var e = Math.hypot(4, [5], 6);
var f = Math.hypot(3, -Infinity);
var g = Math.hypot(12);
"#;

eprintln!("{}", forward(&mut engine, init));
Expand All @@ -381,13 +385,15 @@ fn hypot() {
let d = forward_val(&mut engine, "d").unwrap();
let e = forward(&mut engine, "e");
let f = forward(&mut engine, "f");
let g = forward_val(&mut engine, "g").unwrap();

assert_eq!(a.to_number(), 0f64);
assert_eq!(b.to_number(), 5f64);
assert_eq!(c.to_number(), 13f64);
assert_eq!(d.to_number(), 7.071_067_811_865_475_5);
assert_eq!(e, String::from("NaN"));
assert_eq!(f, String::from("Infinity"));
assert_eq!(g.to_number(), 12f64);
}

#[test]
Expand All @@ -399,6 +405,8 @@ fn imul() {
var b = Math.imul(-5, 12);
var c = Math.imul(0xffffffff, 5);
var d = Math.imul(0xfffffffe, 5);
var e = Math.imul(12);
var f = Math.imul();
"#;

eprintln!("{}", forward(&mut engine, init));
Expand All @@ -407,11 +415,15 @@ fn imul() {
let b = forward_val(&mut engine, "b").unwrap();
let c = forward_val(&mut engine, "c").unwrap();
let d = forward_val(&mut engine, "d").unwrap();
let e = forward_val(&mut engine, "e").unwrap();
let f = forward_val(&mut engine, "f").unwrap();

assert_eq!(a.to_number(), 12f64);
assert_eq!(b.to_number(), -60f64);
assert_eq!(c.to_number(), -5f64);
assert_eq!(d.to_number(), -10f64);
assert_eq!(e.to_number(), 0f64);
assert_eq!(f.to_number(), 0f64);
}

#[test]
Expand Down Expand Up @@ -446,6 +458,7 @@ fn log1p() {
var d = Math.log1p(-1);
var e = Math.log1p(-1.000000000000001);
var f = Math.log1p(-2);
var g = Math.log1p();
"#;

eprintln!("{}", forward(&mut engine, init));
Expand All @@ -456,13 +469,15 @@ fn log1p() {
let d = forward(&mut engine, "d");
let e = forward(&mut engine, "e");
let f = forward(&mut engine, "f");
let g = forward(&mut engine, "g");

assert_eq!(a.to_number(), f64::consts::LN_2);
assert_eq!(b.to_number(), 0f64);
assert_eq!(c.to_number(), -36.736_800_569_677_1);
assert_eq!(d, "-Infinity");
assert_eq!(e, String::from("NaN"));
assert_eq!(f, String::from("NaN"));
assert_eq!(g, String::from("NaN"));
}

#[test]
Expand Down Expand Up @@ -514,7 +529,7 @@ fn max() {
let init = r#"
var a = Math.max(10, 20);
var b = Math.max(-10, -20);
var c = Math.max(-10, 20);
var c = Math.max(-10, 20);
"#;

eprintln!("{}", forward(&mut engine, init));
Expand All @@ -535,7 +550,7 @@ fn min() {
let init = r#"
var a = Math.min(10, 20);
var b = Math.min(-10, -20);
var c = Math.min(-10, 20);
var c = Math.min(-10, 20);
"#;

eprintln!("{}", forward(&mut engine, init));
Expand Down Expand Up @@ -598,7 +613,7 @@ fn sign() {
let init = r#"
var a = Math.sign(3);
var b = Math.sign(-3);
var c = Math.sign(0);
var c = Math.sign(0);
"#;

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

0 comments on commit e51ee81

Please sign in to comment.