Skip to content
Permalink
Browse files

Merge branch 't/12309'

  • Loading branch information...
Reinmar committed Sep 4, 2014
2 parents ac30879 + 0b338f4 commit b60bb80fcafa124582c8c7acee6bc86ae7aeb346
@@ -80,6 +80,32 @@
}
};

/**
* Assert that expected value is in range (between min and max).
*
* @param {Number} expected
* @param {Number} min
* @param {Number} max
* @param {String} [message]
*/
bender.assert.isNumberInRange = function( expected, min, max, message ) {
YTest.Assert._increment();

YTest.Assert.isNumber( expected, 'Expected value should be number type.' );
YTest.Assert.isNumber( min, 'Min value should be number type.' );
YTest.Assert.isNumber( max, 'Max value should be number type.' );

if ( min >= max ) {
throw new YUITest.AssertionError( 'Min value is greater or equal than max.' );
}

if ( expected < min || expected > max ) {
throw new YUITest.ComparisonFailure(
YUITest.Assert._formatMessage( message ),
expected
);
}
};

// add support test ignore
YUITest.Ignore = function() {};
@@ -526,10 +526,11 @@ bender.test( appendDomObjectTests(
Y.one( '#DocPositionTarget' ).setXY( [ 350, 450 ] );
var pos = CKEDITOR.document.getById( 'DocPositionTarget' ).getDocumentPosition(),
x = Math.round( pos.x ),
y = Math.round( pos.y );
y = Math.round( pos.y ),
accOffset = 1;

assert.areEqual( 350, x, 'Position coordinates:x relative to document doesn\'t match.' );
assert.areEqual( 450, y, 'Position coordinates:y relative to document doesn\'t match.' );
assert.isNumberInRange( x, 350 - accOffset, 350 + accOffset, 'Position coordinates:x(350) relative to document doesn\'t match ' + x + ' with offset ' + accOffset + '.' );
assert.isNumberInRange( y, 450 - accOffset, 450 + accOffset, 'Position coordinates:y(450) relative to document doesn\'t match ' + y + 'with offset ' + accOffset + '.' );
} );
} );

@@ -0,0 +1,45 @@
/* bender-tags: editor,unit,utils */

( function () {
'use strict';

var assert = bender.assert;

bender.test( {
'test invalid arguments': function() {
// Invalid arguments.
assert.throwsError( YUITest.AssertionError, function() {
assert.isNumberInRange( 100, 102, 101 );
}, 'min > max' );
assert.throwsError( YUITest.AssertionError, function() {
assert.isNumberInRange( 101, 101, 101 );
}, 'min == max' );
assert.throwsError( YUITest.AssertionError, function() {
assert.isNumberInRange( null, 99, 101 );
}, 'expected not a number' );
assert.throwsError( YUITest.AssertionError, function() {
assert.isNumberInRange( 100, '99', 101 );
}, 'min not a number' );
assert.throwsError( YUITest.AssertionError, function() {
assert.isNumberInRange( 100, 100 );
}, 'max not a number' );
},

'test number not in range': function() {
// Number is not in range.
assert.throwsError( YUITest.ComparisonFailure, function() {
assert.isNumberInRange( 100, 101, 102 );
}, 'lower < min' );
assert.throwsError( YUITest.ComparisonFailure, function() {
assert.isNumberInRange( 100, 98, 99 );
}, 'expected > max' );
},

'test passing and passed assertions number increasing': function() {
// Number is in range.
assert.isNumberInRange( 100, 99, 101, '99 <= 100 <= 101' );
assert.isNumberInRange( 100, 100, 101, '100 <= 100 <= 101' );
assert.isNumberInRange( 100, 98, 100, '98 <= 100 <= 100' );
}
} );
} )();

0 comments on commit b60bb80

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.