That’s the correct solution but why is that?
test('#approximately', function() {
assert.approximately(weirdNumbers(0.5) , 1, /*edit this*/0.5 );
assert.approximately(weirdNumbers(0.2) , 1, /*edit this*/ 0.8 );
});
});
Am I not supposed to check the range of the values that can be returned by the weirdNumbers function?
delta=0.5
1+0.5 - random number (0-1.0)
The range should be[0.5,1.5]
1+0.5-1=0.5 1+0.5-0.0=1.5
delta=0.2
1+0.2 - random number (0-1.0)
[0.2,1.2]
/*
function weirdNumbers(delta) {
return (1 + delta - Math.random());
}
*/
/** 10 - .approximately **/
// .approximately(actual, expected, range, [message])
// actual = expected +/- range
// Choose the minimum range (3rd parameter) to make the test always pass
// it should be less than 1
test('#approximately', function() {
assert.approximately(weirdNumbers(0.5) , 1.5, /*edit this*/0.5 );
assert.approximately(weirdNumbers(0.2) , 1.2, /*edit this*/ 0.2 );
});
});
I am probably missing some math behind it
/*
.approximately(actual, expected, range, [message])
actual = expected +/- range
*/
The only thing I notice is that it could be 1-delta
ex: 1-0.2=0.8 or 1-0.5=0.5