From 782f9d54fb356c7f1d29ee4449f2e866de3d1717 Mon Sep 17 00:00:00 2001 From: chrisklus Date: Tue, 29 Jan 2019 13:19:36 -0700 Subject: [PATCH] Add boundary condition RangeWithValue tests, see https://github.com/phetsims/dot/issues/77 --- js/RangeWithValueTests.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/js/RangeWithValueTests.js b/js/RangeWithValueTests.js index 13bc558..bac63ce 100644 --- a/js/RangeWithValueTests.js +++ b/js/RangeWithValueTests.js @@ -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' ); @@ -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() @@ -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' + ); } ); } ); \ No newline at end of file