Skip to content

Commit

Permalink
Add boundary condition RangeWithValue tests, see #77
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisklus committed Jan 29, 2019
1 parent 846b97f commit 782f9d5
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions js/RangeWithValueTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ define( require => {

QUnit.test( 'constructor', assert => {
assert.ok( new RangeWithValue( 1, 10, 2 ), 'valid range with value' );
assert.ok( new RangeWithValue( 1, 10, 1 ), 'valid range with value' );
assert.ok( new RangeWithValue( 1, 10, 10 ), 'valid range with value' );
assert.ok( new RangeWithValue( 10, 10, 10 ), 'valid range with value' );
window.assert && assert.throws( () => {
new RangeWithValue( 1, 10, 11 ); // eslint-disable-line
}, 'invalid range with value, default value is out of range' );
Expand All @@ -27,16 +29,20 @@ define( require => {

QUnit.test( 'methods', assert => {

// test a valid and invalid setMin()
// test valid and invalid setMin()
let rangeWithValue = new RangeWithValue( 1, 10, 3 );
rangeWithValue.setMin( 2 );
assert.equal( rangeWithValue.min, 2, 'setMin() succeeds when min <= defaultValue <= max' );
rangeWithValue.setMin( 3 );
assert.equal( rangeWithValue.min, 3, 'setMin() succeeds when min <= defaultValue <= max' );
window.assert && assert.throws( () => { rangeWithValue.setMin( 4 ); }, 'setMin() fails when defaultValue < min' );

// test a valid and invalid setMax()
// test valid and invalid setMax()
rangeWithValue = new RangeWithValue( 1, 10, 8 );
rangeWithValue.setMax( 9 );
assert.equal( rangeWithValue.max, 9, 'setMax() succeeds when max >= defaultValue >= min' );
rangeWithValue.setMax( 8 );
assert.equal( rangeWithValue.max, 8, 'setMax() succeeds when max >= defaultValue >= min' );
window.assert && assert.throws( () => { rangeWithValue.setMax( 7 ); }, 'setMax() fails when defaultValue > max' );

// test a true and false equals()
Expand All @@ -50,13 +56,23 @@ define( require => {
'equals() fails when rangeWithValue1 !== rangeWithValue2'
);

// test a valid and invalid setMinMax()
// test valid and invalid setMinMax()
rangeWithValue = new RangeWithValue( 1, 10, 5 );
rangeWithValue.setMinMax( 2, 9 );
assert.ok( rangeWithValue.equals( new RangeWithValue( 2, 9, 5 ) ), 'setMinMax() succeeds when min <= defaultValue <= max' );
rangeWithValue.setMinMax( 2, 5 );
assert.ok( rangeWithValue.equals( new RangeWithValue( 2, 5, 5 ) ), 'setMinMax() succeeds when min <= defaultValue <= max' );
rangeWithValue.setMinMax( 5, 9 );
assert.ok( rangeWithValue.equals( new RangeWithValue( 5, 9, 5 ) ), 'setMinMax() succeeds when min <= defaultValue <= max' );
rangeWithValue.setMinMax( 5, 5 );
assert.ok( rangeWithValue.equals( new RangeWithValue( 5, 5, 5 ) ), 'setMinMax() succeeds when min <= defaultValue <= max' );
window.assert && assert.throws( () => {
rangeWithValue.setMinMax( 3, 4 );
}, 'setMinMax() fails when default value is out of range'
);
window.assert && assert.throws( () => {
rangeWithValue.setMinMax( 6, 7 );
}, 'setMinMax() fails when default value is out of range'
);
} );
} );

0 comments on commit 782f9d5

Please sign in to comment.