Skip to content

Commit

Permalink
Add RangeWithValue tests, see #77
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisklus committed Jan 7, 2019
1 parent e9d8ba2 commit 1502d72
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
2 changes: 1 addition & 1 deletion js/RangeTests.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018, University of Colorado Boulder
// Copyright 2019, University of Colorado Boulder

/**
* Range tests
Expand Down
62 changes: 62 additions & 0 deletions js/RangeWithValueTests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright 2019, University of Colorado Boulder

/**
* RangeWithValue tests
*
* @author Chris Klusendorf (PhET Interactive Simulations)
*/

define( require => {
'use strict';

// modules
const RangeWithValue = require( 'DOT/RangeWithValue' );

QUnit.module( 'RangeWithValue' );

QUnit.test( 'constructor', assert => {
assert.ok( new RangeWithValue( 1, 10, 2 ), 'valid range with value' );
assert.ok( new RangeWithValue( 1, 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' );
window.assert && assert.throws( () => {
new RangeWithValue( 1, 10 ); // eslint-disable-line
}, 'invalid range with value, default value is required' );
} );

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

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

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

// test a true and false equals()
const rangeWithValue3 = new RangeWithValue( 1, 10, 5 );
assert.ok(
rangeWithValue3.equals( new RangeWithValue( 1, 10, 5 ) ),
'equals() succeeds when rangeWithValue1 === rangeWithValue2'
);
assert.notOk(
rangeWithValue3.equals( new RangeWithValue( 1, 10, 6 ) ),
'equals() fails when rangeWithValue1 !== rangeWithValue2'
);

// test a valid and invalid setMinMax()
const rangeWithValue5 = new RangeWithValue( 1, 10, 5 );
rangeWithValue5.setMinMax( 2, 9 );
assert.ok( rangeWithValue5.equals( new RangeWithValue( 2, 9, 5 ) ), 'setMinMax() succeeds when min < defaultValue < max' );
window.assert && assert.throws( () => {
rangeWithValue5.setMinMax( 3, 4 );
}, 'setMinMax() fails when default value is out of range'
);
} );
} );
1 change: 1 addition & 0 deletions js/dot-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ define( function( require ) {
require( 'DOT/MatrixOps3Tests' );
require( 'DOT/OpenRangeTests' );
require( 'DOT/RangeTests' );
require( 'DOT/RangeWithValueTests' );
require( 'DOT/UtilTests' );
require( 'DOT/Transform3Tests' );
require( 'DOT/LinearFunctionTests' );
Expand Down

0 comments on commit 1502d72

Please sign in to comment.