diff --git a/dist/all.js b/dist/all.js index ba4650c4..283dc039 100644 --- a/dist/all.js +++ b/dist/all.js @@ -5916,7 +5916,7 @@ Canvas.base.getElementOffset = getElementOffset; */ toObject: function() { return Canvas.base.object.extend(this.callSuper('toObject'), { - points: this.points.clone() + points: this.points.concat() }); }, @@ -7236,7 +7236,7 @@ Canvas.base.getElementOffset = getElementOffset; * @return {Canvas.Text} an instance */ Canvas.Text.fromObject = function(object) { - return new Canvas.Text(object.text, Object.clone(object)); + return new Canvas.Text(object.text, Canvas.base.object.clone(object)); }; /** diff --git a/src/canvas_polygon.class.js b/src/canvas_polygon.class.js index f56188e0..ca8bdbf2 100644 --- a/src/canvas_polygon.class.js +++ b/src/canvas_polygon.class.js @@ -68,7 +68,7 @@ */ toObject: function() { return Canvas.base.object.extend(this.callSuper('toObject'), { - points: this.points.clone() + points: this.points.concat() }); }, diff --git a/src/canvas_text.class.js b/src/canvas_text.class.js index d401f056..16f6d7a0 100644 --- a/src/canvas_text.class.js +++ b/src/canvas_text.class.js @@ -177,7 +177,7 @@ * @return {Canvas.Text} an instance */ Canvas.Text.fromObject = function(object) { - return new Canvas.Text(object.text, Object.clone(object)); + return new Canvas.Text(object.text, Canvas.base.object.clone(object)); }; /** diff --git a/test/unit/canvas_parser.js b/test/unit/canvas_parser.js index e14dd9ea..610f5de8 100644 --- a/test/unit/canvas_parser.js +++ b/test/unit/canvas_parser.js @@ -130,7 +130,7 @@ function init() { this.assert(Canvas.parseElements); function getOptions(options) { - return Object.extend(Object.clone({ + return Canvas.base.object.extend(Canvas.base.object.clone({ left: 10, top: 20, width: 30, height: 40 }), options || { }); } diff --git a/test/unit/canvas_polyline.html b/test/unit/canvas_polyline.html index 15b6852a..6488c61b 100644 --- a/test/unit/canvas_polyline.html +++ b/test/unit/canvas_polyline.html @@ -3,26 +3,22 @@ - Canvas.Polyline unit tests + Canvas.Polyline unit tests + - + + - - - - - - - + -

Canvas.Polyline unit tests

-
+

Canvas.Polyline unit tests

+

+

+
    \ No newline at end of file diff --git a/test/unit/canvas_polyline.js b/test/unit/canvas_polyline.js index 0116d1fc..39b75b7c 100644 --- a/test/unit/canvas_polyline.js +++ b/test/unit/canvas_polyline.js @@ -1,4 +1,4 @@ -function init() { +(function() { function getPoints() { return [ @@ -26,76 +26,86 @@ function init() { 'points': getPoints() }; - new Test.Unit.Runner({ - testConstructor: function() { - this.assert(Canvas.Polyline); - - var polyline = new Canvas.Polyline(getPoints()); - - this.assertInstanceOf(Canvas.Polyline, polyline); - this.assertInstanceOf(Canvas.Object, polyline); - - this.assertIdentical('polyline', polyline.type); - this.assertObjectIdentical(getPoints(), polyline.get('points')); - }, - testComplexity: function() { - var polyline = new Canvas.Polyline(getPoints()); - this.assertRespondsTo('complexity', polyline); - }, - testToObject: function() { - var polyline = new Canvas.Polyline(getPoints()); - this.assertRespondsTo('toObject', polyline); - - this.assertObjectIdentical(REFERENCE_OBJECT, polyline.toObject()); - }, - testCanvasPolylineFromObject: function() { - this.assertRespondsTo('fromObject', Canvas.Polyline); - var polyline = Canvas.Polyline.fromObject(REFERENCE_OBJECT); - this.assertInstanceOf(Canvas.Polyline, polyline); - this.assertObjectIdentical(REFERENCE_OBJECT, polyline.toObject()); - }, - testCanvasPolylineFromElement: function() { - this.assertRespondsTo('fromElement', Canvas.Polyline); - - var elPolyline = document.createElement('polyline'); - - elPolyline.setAttribute('points', '10,12 20,22'); - - var polyline = Canvas.Polyline.fromElement(elPolyline); - - this.assertInstanceOf(Canvas.Polyline, polyline); - this.assertObjectIdentical(REFERENCE_OBJECT, polyline.toObject()); - - var elPolylineWithAttrs = document.createElement('polyline'); - elPolylineWithAttrs.setAttribute('points', '10,10 20,20 30,30 10,10'); - elPolylineWithAttrs.setAttribute('fill', 'rgb(255,255,255)'); - elPolylineWithAttrs.setAttribute('fill-opacity', '0.34'); - elPolylineWithAttrs.setAttribute('stroke-width', '3'); - elPolylineWithAttrs.setAttribute('stroke', 'blue'); - elPolylineWithAttrs.setAttribute('transform', 'translate(-10,-20) scale(2)'); - - var polylineWithAttrs = Canvas.Polyline.fromElement(elPolylineWithAttrs); - var expectedPoints = [{x: 10, y: 10}, {x: 20, y: 20}, {x: 30, y: 30}, {x: 10, y: 10}]; - - this.assertObjectIdentical(Object.extend(REFERENCE_OBJECT, { - 'width': 20, - 'height': 20, - 'fill': 'rgb(255,255,255)', - 'stroke': 'blue', - 'strokeWidth': 3, - 'opacity': 0.34, - 'points': expectedPoints - }), polylineWithAttrs.toObject()); - - this.assertEnumEqual([ 2, 0, 0, 2, -10, -20 ], polylineWithAttrs.get('transformMatrix')); - - var elPolylineWithoutPoints = document.createElement('polyline'); - - this.assertRaise('TypeError', function(){ - Canvas.Polyline.fromElement(elPolylineWithoutPoints); - }, 'missing points attribute should result in error'); - - this.assertNull(Canvas.Polyline.fromElement()); - } + test('constructor', function(){ + ok(Canvas.Polyline); + + var polyline = new Canvas.Polyline(getPoints()); + + ok(polyline instanceof Canvas.Polyline); + ok(polyline instanceof Canvas.Object); + + equals(polyline.type, 'polyline'); + same(polyline.get('points'), getPoints()); }); -} \ No newline at end of file + + test('complexity', function(){ + var polyline = new Canvas.Polyline(getPoints()); + ok(typeof polyline.complexity == 'function'); + }); + + test('toObject', function(){ + var polyline = new Canvas.Polyline(getPoints()); + ok(typeof polyline.toObject == 'function'); + + same(polyline.toObject(), REFERENCE_OBJECT); + }); + + test('Canvas.Polyline.fromObject', function(){ + ok(typeof Canvas.Polyline.fromObject == 'function'); + var polyline = Canvas.Polyline.fromObject(REFERENCE_OBJECT); + ok(polyline instanceof Canvas.Polyline); + same(polyline.toObject(), REFERENCE_OBJECT); + }); + + /* + testCanvasPolylineFromObject: function() { + this.assertRespondsTo('fromObject', Canvas.Polyline); + var polyline = Canvas.Polyline.fromObject(REFERENCE_OBJECT); + this.assertInstanceOf(Canvas.Polyline, polyline); + this.assertObjectIdentical(REFERENCE_OBJECT, polyline.toObject()); + }, + testCanvasPolylineFromElement: function() { + this.assertRespondsTo('fromElement', Canvas.Polyline); + + var elPolyline = document.createElement('polyline'); + + elPolyline.setAttribute('points', '10,12 20,22'); + + var polyline = Canvas.Polyline.fromElement(elPolyline); + + this.assertInstanceOf(Canvas.Polyline, polyline); + this.assertObjectIdentical(REFERENCE_OBJECT, polyline.toObject()); + + var elPolylineWithAttrs = document.createElement('polyline'); + elPolylineWithAttrs.setAttribute('points', '10,10 20,20 30,30 10,10'); + elPolylineWithAttrs.setAttribute('fill', 'rgb(255,255,255)'); + elPolylineWithAttrs.setAttribute('fill-opacity', '0.34'); + elPolylineWithAttrs.setAttribute('stroke-width', '3'); + elPolylineWithAttrs.setAttribute('stroke', 'blue'); + elPolylineWithAttrs.setAttribute('transform', 'translate(-10,-20) scale(2)'); + + var polylineWithAttrs = Canvas.Polyline.fromElement(elPolylineWithAttrs); + var expectedPoints = [{x: 10, y: 10}, {x: 20, y: 20}, {x: 30, y: 30}, {x: 10, y: 10}]; + + this.assertObjectIdentical(Object.extend(REFERENCE_OBJECT, { + 'width': 20, + 'height': 20, + 'fill': 'rgb(255,255,255)', + 'stroke': 'blue', + 'strokeWidth': 3, + 'opacity': 0.34, + 'points': expectedPoints + }), polylineWithAttrs.toObject()); + + this.assertEnumEqual([ 2, 0, 0, 2, -10, -20 ], polylineWithAttrs.get('transformMatrix')); + + var elPolylineWithoutPoints = document.createElement('polyline'); + + this.assertRaise('TypeError', function(){ + Canvas.Polyline.fromElement(elPolylineWithoutPoints); + }, 'missing points attribute should result in error'); + + this.assertNull(Canvas.Polyline.fromElement()); + } + */ +})(); \ No newline at end of file diff --git a/test/unit/canvas_rect.html b/test/unit/canvas_rect.html index 05214c36..7327df47 100644 --- a/test/unit/canvas_rect.html +++ b/test/unit/canvas_rect.html @@ -3,30 +3,22 @@ - Canvas.Rect unit tests - - + Canvas.Rect unit tests + - + + - - - - - - - + -

    Canvas.Rect unit tests

    -
    +

    Canvas.Rect unit tests

    +

    +

    +
      \ No newline at end of file diff --git a/test/unit/canvas_rect.js b/test/unit/canvas_rect.js index fb28b1af..d91ba5a1 100644 --- a/test/unit/canvas_rect.js +++ b/test/unit/canvas_rect.js @@ -1,4 +1,4 @@ -function init() { +(function() { var REFERENCE_RECT = { 'type': 'rect', @@ -18,73 +18,76 @@ function init() { 'opacity': 1 }; - new Test.Unit.Runner({ - testConstructor: function() { - - this.assert(Canvas.Rect); - - var rect = new Canvas.Rect(); - - this.assertInstanceOf(Canvas.Rect, rect); - this.assertInstanceOf(Canvas.Object, rect); - - this.assertIdentical('rect', rect.get('type')); - }, - testComplexity: function() { - var rect = new Canvas.Rect(); - this.assertRespondsTo('complexity', rect); - }, - testToObject: function() { - var rect = new Canvas.Rect(); - this.assertRespondsTo('toObject', rect); - - var object = rect.toObject(); - this.assertObjectIdentical(REFERENCE_RECT, object); - }, - testCanvasRectFromObject: function() { - this.assertRespondsTo('fromObject', Canvas.Rect); - var rect = Canvas.Rect.fromObject(REFERENCE_RECT); - this.assertInstanceOf(Canvas.Rect, rect); - this.assertObjectIdentical(REFERENCE_RECT, rect.toObject()); - }, - testCanvasRectFromElement: function() { - this.assertRespondsTo('fromElement', Canvas.Rect); - - var elRect = document.createElement('rect'); - var rect = Canvas.Rect.fromElement(elRect); - - this.assertInstanceOf(Canvas.Rect, rect); - this.assertObjectIdentical(REFERENCE_RECT, rect.toObject()); - - var elRectWithAttrs = document.createElement('rect'); - elRectWithAttrs.setAttribute('x', 10); - elRectWithAttrs.setAttribute('y', 20); - elRectWithAttrs.setAttribute('width', 222); - elRectWithAttrs.setAttribute('height', 333); - elRectWithAttrs.setAttribute('rx', 11); - elRectWithAttrs.setAttribute('ry', 12); - elRectWithAttrs.setAttribute('fill', 'rgb(255,255,255)'); - elRectWithAttrs.setAttribute('fill-opacity', 0.45); - elRectWithAttrs.setAttribute('stroke', 'blue'); - elRectWithAttrs.setAttribute('stroke-width', 3); - //elRectWithAttrs.setAttribute('transform', 'translate(-10,-20) scale(2) rotate(45) translate(5,10)'); - - var rectWithAttrs = Canvas.Rect.fromElement(elRectWithAttrs); - this.assertInstanceOf(Canvas.Rect, rectWithAttrs); - - var expectedObject = Object.extend(REFERENCE_RECT, { - left: 121, - top: 186.5, - width: 222, - height: 333, - fill: 'rgb(255,255,255)', - opacity: 0.45, - stroke: 'blue', - strokeWidth: 3 - }); - this.assertObjectIdentical(expectedObject, rectWithAttrs.toObject()); - - this.assertNull(Canvas.Rect.fromElement()); - } + test('constructor', function(){ + ok(Canvas.Rect); + + var rect = new Canvas.Rect(); + + ok(rect instanceof Canvas.Rect); + ok(rect instanceof Canvas.Object); + + same(rect.get('type'), 'rect'); }); -} \ No newline at end of file + + test('complexity', function() { + var rect = new Canvas.Rect(); + + ok(typeof rect.complexity == 'function'); + }); + + test('toObject', function() { + var rect = new Canvas.Rect(); + ok(typeof rect.toObject == 'function'); + + var object = rect.toObject(); + same(object, REFERENCE_RECT); + }); + + test('Canvas.Rect.fromObject', function() { + ok(typeof Canvas.Rect.fromObject == 'function'); + + var rect = Canvas.Rect.fromObject(REFERENCE_RECT); + ok(rect instanceof Canvas.Rect); + same(rect.toObject(), REFERENCE_RECT); + }); + + test('Canvas.Rect.fromElement', function() { + ok(typeof Canvas.Rect.fromElement == 'function'); + + var elRect = document.createElement('rect'); + var rect = Canvas.Rect.fromElement(elRect); + + ok(rect instanceof Canvas.Rect); + same(rect.toObject(), REFERENCE_RECT); + + var elRectWithAttrs = document.createElement('rect'); + elRectWithAttrs.setAttribute('x', 10); + elRectWithAttrs.setAttribute('y', 20); + elRectWithAttrs.setAttribute('width', 222); + elRectWithAttrs.setAttribute('height', 333); + elRectWithAttrs.setAttribute('rx', 11); + elRectWithAttrs.setAttribute('ry', 12); + elRectWithAttrs.setAttribute('fill', 'rgb(255,255,255)'); + elRectWithAttrs.setAttribute('fill-opacity', 0.45); + elRectWithAttrs.setAttribute('stroke', 'blue'); + elRectWithAttrs.setAttribute('stroke-width', 3); + //elRectWithAttrs.setAttribute('transform', 'translate(-10,-20) scale(2) rotate(45) translate(5,10)'); + + var rectWithAttrs = Canvas.Rect.fromElement(elRectWithAttrs); + ok(rectWithAttrs instanceof Canvas.Rect); + + var expectedObject = Canvas.base.object.extend(REFERENCE_RECT, { + left: 121, + top: 186.5, + width: 222, + height: 333, + fill: 'rgb(255,255,255)', + opacity: 0.45, + stroke: 'blue', + strokeWidth: 3 + }); + same(rectWithAttrs.toObject(), expectedObject); + + ok(Canvas.Rect.fromElement() === null); + }); +})(); \ No newline at end of file diff --git a/test/unit/canvas_text.html b/test/unit/canvas_text.html index de30ea07..9da081e5 100644 --- a/test/unit/canvas_text.html +++ b/test/unit/canvas_text.html @@ -3,15 +3,22 @@ - Canvas.Text unit tests + Canvas.Text unit tests + - + - - + + + + -

      Canvas.Text unit tests

      -
      +

      Canvas.Text unit tests

      +

      +

      +
        \ No newline at end of file diff --git a/test/unit/canvas_text.js b/test/unit/canvas_text.js index 195405d7..46ab81fa 100644 --- a/test/unit/canvas_text.js +++ b/test/unit/canvas_text.js @@ -1,4 +1,4 @@ -function init(){ +(function() { var REFERENCE_TEXT_OBJECT = { 'type': 'text', @@ -6,7 +6,7 @@ function init(){ 'top': 10, 'width': 100, 'height': 100, - 'fill': '#000000', + 'fill': 'rgb(0,0,0)', 'overlayFill': null, 'stroke': null, 'strokeWidth': 1, @@ -23,86 +23,106 @@ function init(){ 'path': null }; - new Test.Unit.Runner({ - testConstructor: function() { - this.assert(Canvas.Text); - var text = new Canvas.Text('foo'); - - this.assertInstanceOf(Canvas.Text, text); - this.assertInstanceOf(Canvas.Object, text); - - this.assertIdentical('text', text.get('type')); - this.assertIdentical('foo', text.get('text')); - }, - testToString: function() { - var text = new Canvas.Text('foo'); - this.assertRespondsTo('toString', text); - this.assertIdentical('#', text.toString()); - }, - testToObject: function() { - var text = new Canvas.Text('foo'); - this.assertRespondsTo('toObject', text); - this.assertObjectIdentical(REFERENCE_TEXT_OBJECT, text.toObject()); - }, - testComplexity: function() { - var text = new Canvas.Text('foo'); - this.assertRespondsTo('complexity', text); - }, - testSet: function() { - var text = new Canvas.Text('foo'); - this.assertRespondsTo('set', text); - this.assertIdentical(text, text.set('text', 'bar'), 'should be chainable'); - }, - testSetColor: function() { - var text = new Canvas.Text('foo'); - this.assertRespondsTo('setColor', text); - this.assertIdentical(text, text.setColor('123456'), 'should be chainable'); - this.assertIdentical('123456', text.get('fill')); - }, - testSetFontsize: function() { - var text = new Canvas.Text('foo'); - this.assertRespondsTo('setFontsize', text); - this.assertIdentical(text, text.setFontsize(12)); - this.assertIdentical(12, text.get('fontsize')); - }, - testGetText: function() { - var text = new Canvas.Text('foo'); - this.assertRespondsTo('getText', text); - this.assertIdentical('foo', text.getText()); - this.assertIdentical(text.get('text'), text.getText()); - }, - testSetText: function() { - var text = new Canvas.Text('foo'); - this.assertRespondsTo('setText', text); - this.assertIdentical(text, text.setText('bar'), 'should be chainable'); - this.assertIdentical('bar', text.getText()); - }, - testCanvasTextFromObject: function() { - this.assertRespondsTo('fromObject', Canvas.Text); - var text = Canvas.Text.fromObject(REFERENCE_TEXT_OBJECT); - this.assertObjectIdentical(REFERENCE_TEXT_OBJECT, text.toObject()); - }, - testCanvasTextAlreadyDefined: function() { - var warnWasCalled = false; - console.warn = function() { - warnWasCalled = true; - } - loadScript('../../canvas/canvas_text.class.js'); - this.wait(1000, function(){ - this.assert(warnWasCalled); - }); - }, - testCanvasObjectDoesntExist: function() { - var warnWasCalled = false; - console.warn = function() { - warnWasCalled = true; - } - delete Canvas.Text; - delete Canvas.Object; - loadScript('../../canvas/canvas_text.class.js'); - this.wait(1000, function() { - this.assert(warnWasCalled); - }); - } + test('constructor', function() { + ok(Canvas.Text); + var text = new Canvas.Text('foo'); + + ok(text instanceof Canvas.Text); + ok(text instanceof Canvas.Object); + + equals(text.get('type'), 'text'); + equals(text.get('text'), 'foo'); }); -} + + test('toString', function() { + var text = new Canvas.Text('foo'); + ok(typeof text.toString == 'function'); + equals(text.toString(), '#'); + }); + + test('toObject', function() { + var text = new Canvas.Text('foo'); + ok(typeof text.toObject == 'function'); + same(text.toObject(), REFERENCE_TEXT_OBJECT); + }); + + test('complexity', function(){ + var text = new Canvas.Text('foo'); + ok(typeof text.complexity == 'function'); + }); + + test('set', function() { + var text = new Canvas.Text('foo'); + ok(typeof text.set == 'function'); + equals(text.set('text', 'bar'), text, 'should be chainable'); + }); + + test('setColor', function(){ + var text = new Canvas.Text('foo'); + ok(typeof text.setColor == 'function'); + equals(text.setColor('123456'), text, 'should be chainable'); + equals(text.get('fill'), '123456'); + }); + + test('setFontsize', function(){ + var text = new Canvas.Text('foo'); + ok(typeof text.setFontsize == 'function'); + equals(text.setFontsize(12), text); + equals(text.get('fontsize'), 12); + }); + + test('getText', function(){ + var text = new Canvas.Text('foo'); + ok(typeof text.getText == 'function'); + equals(text.getText(), 'foo'); + equals(text.getText(), text.get('text')); + }); + + test('setText', function(){ + var text = new Canvas.Text('foo'); + ok(typeof text.setText == 'function'); + equals(text.setText('bar'), text, 'should be chainable'); + equals(text.getText(), 'bar'); + }); + + test('Canvas.Text.fromObject', function(){ + ok(typeof Canvas.Text.fromObject == 'function'); + var text = Canvas.Text.fromObject(REFERENCE_TEXT_OBJECT); + same(text.toObject(), REFERENCE_TEXT_OBJECT); + }); + + asyncTest('Text already defined', function() { + var warnWasCalled = false; + console.warn = function() { + warnWasCalled = true; + }; + + var el = document.createElement('script'); + el.src = '../../src/canvas_text.class.js'; + document.body.appendChild(el); + + setTimeout(function() { + ok(warnWasCalled); + start(); + }, 500); + }); + + asyncTest('Object doesn\'t exist', function() { + var warnWasCalled = false; + console.warn = function() { + warnWasCalled = true; + } + delete Canvas.Text; + delete Canvas.Object; + + var el = document.createElement('script'); + el.src = '../../src/canvas_text.class.js'; + document.body.appendChild(el); + + setTimeout(function(){ + ok(warnWasCalled); + start(); + }, 500); + }); + +})(); \ No newline at end of file diff --git a/test/unit/canvas_util.html b/test/unit/canvas_util.html index 0d4a4b26..ff3e7982 100644 --- a/test/unit/canvas_util.html +++ b/test/unit/canvas_util.html @@ -5,20 +5,21 @@ Canvas.util unit tests - + - - - + - + + - + -

        Canvas.util.* unit tests

        -
        +

        Canvas.util unit tests

        +

        +

        +
          \ No newline at end of file diff --git a/test/unit/canvas_util.js b/test/unit/canvas_util.js index 8ee01d88..f51d1bdd 100644 --- a/test/unit/canvas_util.js +++ b/test/unit/canvas_util.js @@ -1,76 +1,74 @@ -function init(){ - var runner = new Test.Unit.Runner({ +(function(){ + + test('toFixed', function(){ + ok(typeof Canvas.util.toFixed == 'function'); - testToFixed: function() { - this.assertRespondsTo('toFixed', Canvas.util); + function test(what) { + equals(Canvas.util.toFixed(what, 2), 166.67, 'should leave 2 fractional digits'); + equals(Canvas.util.toFixed(what, 5), 166.66667, 'should leave 5 fractional digits'); + equals(Canvas.util.toFixed(what, 0), 167, 'should leave 0 fractional digits'); - function test(what) { - this.assertIdentical(166.67, Canvas.util.toFixed(what, 2), 'should leave 2 fractional digits'); - this.assertIdentical(166.66667, Canvas.util.toFixed(what, 5), 'should leave 5 fractional digits'); - this.assertIdentical(167, Canvas.util.toFixed(what, 0), 'should leave 0 fractional digits'); + var fractionless = (typeof what == 'number') + ? parseInt(what) + : what.substring(0, what.indexOf('.')); - var fractionless = (typeof what == 'number') - ? parseInt(what) - : what.substring(0, what.indexOf('.')); - - this.assertIdentical(166, Canvas.util.toFixed(fractionless, 2), 'should leave fractionless number as is'); - } - - test.call(this, '166.66666666666666666666'); // string - test.call(this, 166.66666666666666666666); // number - }, - - testRemoveFromArray: function() { - var testArray = [1,2,3,4,5]; - - this.assertRespondsTo('removeFromArray', Canvas.util); - - Canvas.util.removeFromArray(testArray, 2); - this.assertEnumEqual([1,3,4,5], testArray); - this.assertIdentical(testArray, Canvas.util.removeFromArray(testArray, 1), 'should return reference to original array'); - - testArray = [1,2,3,1]; - Canvas.util.removeFromArray(testArray, 1); - this.assertEnumEqual([2,3,1], testArray, 'only first occurance of value should be deleted'); - - testArray = [1,2,3]; - Canvas.util.removeFromArray(testArray, 12); - this.assertEnumEqual([1,2,3], testArray, 'deleting unexistent value should not affect array'); - - testArray = []; - Canvas.util.removeFromArray(testArray, 1); - this.assertEnumEqual([], testArray, 'deleting any value from empty array should not affect it'); - - testArray = ['0']; - Canvas.util.removeFromArray(testArray, 0); - this.assertEnumEqual(['0'], testArray, 'should use (strict) identity comparison, rather than equality one'); - }, - - testDegreesToRadians: function() { - this.assertRespondsTo('degreesToRadians', Canvas.util); - this.assertIdentical(0, Canvas.util.degreesToRadians(0)); - this.assertIdentical(Math.PI / 2, Canvas.util.degreesToRadians(90)); - this.assertIdentical(Math.PI, Canvas.util.degreesToRadians(180)); - - this.assertNaN(Canvas.util.degreesToRadians()); - }, - - testGetRandomInt: function() { - this.assertRespondsTo('getRandomInt', Canvas.util); - - var randomInts = []; - for (var i = 100; i--; ) { - var randomInt = Canvas.util.getRandomInt(100, 200); - randomInts.push(randomInt); - this.assert(randomInt >= 100 && randomInt <= 200); - } - - var areAllTheSame = randomInts.every(function(value){ - return value === randomInts[0]; - }); - - this.assert(!areAllTheSame); - + equals(Canvas.util.toFixed(fractionless, 2), 166, 'should leave fractionless number as is'); } + + test.call(this, '166.66666666666666666666'); // string + test.call(this, 166.66666666666666666666); // number }); -} \ No newline at end of file + + test('removeFromArray', function() { + var testArray = [1,2,3,4,5]; + + ok(typeof Canvas.util.removeFromArray == 'function'); + + Canvas.util.removeFromArray(testArray, 2); + same([1,3,4,5], testArray); + equals(Canvas.util.removeFromArray(testArray, 1), testArray, 'should return reference to original array'); + + testArray = [1,2,3,1]; + Canvas.util.removeFromArray(testArray, 1); + same([2,3,1], testArray, 'only first occurance of value should be deleted'); + + testArray = [1,2,3]; + Canvas.util.removeFromArray(testArray, 12); + same([1,2,3], testArray, 'deleting unexistent value should not affect array'); + + testArray = []; + Canvas.util.removeFromArray(testArray, 1); + same([], testArray, 'deleting any value from empty array should not affect it'); + + testArray = ['0']; + Canvas.util.removeFromArray(testArray, 0); + same(['0'], testArray, 'should use (strict) identity comparison, rather than equality one'); + }); + + test('degreesToRadians', function(){ + ok(typeof Canvas.util.degreesToRadians == 'function'); + equals(Canvas.util.degreesToRadians(0), 0); + equals(Canvas.util.degreesToRadians(90), Math.PI / 2); + equals(Canvas.util.degreesToRadians(180), Math.PI); + + same(Canvas.util.degreesToRadians(), NaN); + }); + + test('getRandomInt', function(){ + ok(typeof Canvas.util.getRandomInt == 'function'); + + var randomInts = []; + for (var i = 100; i--; ) { + var randomInt = Canvas.util.getRandomInt(100, 200); + randomInts.push(randomInt); + ok(randomInt >= 100 && randomInt <= 200); + } + + var areAllTheSame = randomInts.every(function(value){ + return value === randomInts[0]; + }); + + ok(!areAllTheSame); + }); + +})(); \ No newline at end of file