Commit 48de3222 authored by hongchan's avatar hongchan Committed by Commit bot

Implement should().notBeConstantValueOf(x)

This CL adds the new assertion to audit; it checks if an array has
values other than the expected value. This is useful when checking
the non-zero array.

BUG=678695
TEST=
LayoutTests/webaudio/unit-tests/audit.html
LayoutTests/webaudio/unit-tests/audit-failures.html

Review-Url: https://codereview.chromium.org/2618053002
Cr-Commit-Position: refs/heads/master@{#442095}
parent a439a069
......@@ -540,6 +540,47 @@ window.Audit = (function () {
return this._assert(passed, passDetail, failDetail);
}
/**
* Check if |actual| array is not filled with a constant |expected| value.
*
* @example
* should([1, 0, 1]).notBeConstantValueOf(1);
* should([0, 0, 0]).notBeConstantValueOf(0);
*
* @result
* "PASS [1,0,1] is not constantly 1 (contains 1 different value)."
* "FAIL X [0,0,0] should have contain at least one value different
* from 0."
*/
notBeConstantValueOf () {
this._processArguments(arguments);
this._printActualForFailure = false;
let passed = true;
let passDetail;
let failDetail;
let differences = {};
for (let index in this._actual) {
if (this._actual[index] !== this._expected)
differences[index] = this._actual[index];
}
let numberOfDifferences = Object.keys(differences).length;
passed = numberOfDifferences > 0;
if (passed) {
let valueString = numberOfDifferences > 1 ? 'values' : 'value';
passDetail = '${actual} is not constantly ${expected} (contains ' +
numberOfDifferences + ' different ' + valueString + ').';
} else {
failDetail = '${actual} should have contain at least one value ' +
'different from ${expected}.';
}
return this._assert(passed, passDetail, failDetail);
}
/**
* Check if |actual| array is identical to |expected| array element-wise.
*
......
......@@ -4,10 +4,12 @@ PASS # AUDIT TASK RUNNER STARTED.
PASS > [numerical] Numerical assertion unit test.
PASS 2.3 is 2 within an error of 0.3.
PASS [1,1,1] contains only the constant 1.
PASS [1,0,1] is not constantly 1 (contains 1 different value).
PASS [1,0,0,1] is not constantly 1 (contains 2 different values).
PASS [1,1,1] is identical to the array [1,1,1].
PASS [1,1,1,1,2,2,3,3,3] contains all the expected values in the correct order: one, two, three.
PASS [0.5,0.5,0.55,0.5,0.45,0.5] has no glitch above the threshold of 0.06.
PASS < [numerical] All assertions passed. (total 5 assertions)
PASS < [numerical] All assertions passed. (total 7 assertions)
PASS > [basic] Simple unit tests for basic assertions.
PASS OfflineAudioContext does exist.
PASS Setting foo1 to 0 did not throw an exception.
......
......@@ -26,6 +26,7 @@ FAIL X Expected 5 for all values but found 7 unexpected values:
[2] 11
[3] 18
...and 3 more errors. assert_true: expected true got false
FAIL X [0,0,0] should have contain at least one value different from 0. assert_true: expected true got false
FAIL X [1,8,11,18,6,5,5,5,123,49] expected to be equal to the array [1,8,10,18,6,5,6,5,123,48] but differs in 3 places:
Index Actual Expected
[2] 1.1000000000000000e+1 1.0000000000000000e+1
......@@ -60,7 +61,7 @@ FAIL X [0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.9] does not equal [0.7,0.6,0.5,0.4,0.3,0.2
[5] 5.9999999999999998e-1 2.0000000000000001e-1 3.9999999999999997e-1 1.9999999999999998e+0 2.0000000000000004e-2
Max AbsError of 5.9999999999999998e-1 at index of 0.
Max RelError of 5.9999999999999991e+0 at index of 6. assert_true: expected true got false
FAIL < [numerical-failures] 9 out of 9 assertions were failed. assert_true: expected true got false
FAIL < [numerical-failures] 10 out of 10 assertions were failed. assert_true: expected true got false
FAIL # AUDIT TASK RUNNER FINISHED: 2 out of 2 tasks were failed. assert_true: expected true got false
Harness: the test ran to completion.
......@@ -51,6 +51,7 @@
should(0).beCloseTo(0.1, { threshold: 0 });
should(59, 'The measured decibel').beCloseTo(62, { threshold: 0.01 });
should([1, 8, 11, 18, 6, 5, 5, 5, 123, 49]).beConstantValueOf(5);
should([0, 0, 0]).notBeConstantValueOf(0);
should([1, 8, 11, 18, 6, 5, 5, 5, 123, 49])
.beEqualToArray([1, 8, 10, 18, 6, 5, 6, 5, 123, 48]);
should([1, 1, 1, 1, 2, 2, 3, 3, 3]).containValues([1, 3, 2]);
......
......@@ -46,6 +46,8 @@
should(2.3).beCloseTo(2, { threshold: 0.3 });
should([1, 1, 1]).beConstantValueOf(1);
should([1, 0, 1]).notBeConstantValueOf(1);
should([1, 0, 0, 1]).notBeConstantValueOf(1);
should([1, 1, 1]).beEqualToArray([1, 1, 1]);
should([1, 1, 1, 1, 2, 2, 3, 3, 3])
.containValues([1, 2, 3], 'one, two, three');
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment