diff --git a/test/.eslintrc.json b/test/.eslintrc.json index 4705d0c..09620cb 100644 --- a/test/.eslintrc.json +++ b/test/.eslintrc.json @@ -5,10 +5,11 @@ "node": true }, "parserOptions": { - "ecmaVersion": 5, + "ecmaVersion": 6, "sourceType": "script" }, "globals": { + "sinon": false, "expect": false, "PIXI": false }, diff --git a/test/.eslintrc.json b/test/.eslintrc.json index 4705d0c..09620cb 100644 --- a/test/.eslintrc.json +++ b/test/.eslintrc.json @@ -5,10 +5,11 @@ "node": true }, "parserOptions": { - "ecmaVersion": 5, + "ecmaVersion": 6, "sourceType": "script" }, "globals": { + "sinon": false, "expect": false, "PIXI": false }, diff --git a/test/core/Matrix.js b/test/core/Matrix.js new file mode 100644 index 0000000..9d2694b --- /dev/null +++ b/test/core/Matrix.js @@ -0,0 +1,116 @@ +'use strict'; + +describe('PIXI.Matrix', function () +{ + it('should create a new matrix', function () + { + const matrix = new PIXI.Matrix(); + + expect(matrix.a).to.equal(1); + expect(matrix.b).to.equal(0); + expect(matrix.c).to.equal(0); + expect(matrix.d).to.equal(1); + expect(matrix.tx).to.equal(0); + expect(matrix.ty).to.equal(0); + + const input = [0, 1, 2, 3, 4, 5]; + + matrix.fromArray(input); + + expect(matrix.a).to.equal(0); + expect(matrix.b).to.equal(1); + expect(matrix.c).to.equal(3); + expect(matrix.d).to.equal(4); + expect(matrix.tx).to.equal(2); + expect(matrix.ty).to.equal(5); + + let output = matrix.toArray(true); + + expect(output.length).to.equal(9); + expect(output[0]).to.equal(0); + expect(output[1]).to.equal(1); + expect(output[3]).to.equal(3); + expect(output[4]).to.equal(4); + expect(output[6]).to.equal(2); + expect(output[7]).to.equal(5); + + output = matrix.toArray(false); + + expect(output.length).to.equal(9); + expect(output[0]).to.equal(0); + expect(output[1]).to.equal(3); + expect(output[2]).to.equal(2); + expect(output[3]).to.equal(1); + expect(output[4]).to.equal(4); + expect(output[5]).to.equal(5); + }); + + it('should apply different transforms', function () + { + const matrix = new PIXI.Matrix(); + + matrix.translate(10, 20); + matrix.translate(1, 2); + expect(matrix.tx).to.equal(11); + expect(matrix.ty).to.equal(22); + + matrix.scale(2, 4); + expect(matrix.a).to.equal(2); + expect(matrix.b).to.equal(0); + expect(matrix.c).to.equal(0); + expect(matrix.d).to.equal(4); + expect(matrix.tx).to.equal(22); + expect(matrix.ty).to.equal(88); + + const m2 = matrix.clone(); + + expect(m2).to.not.equal(matrix); + expect(m2.a).to.equal(2); + expect(m2.b).to.equal(0); + expect(m2.c).to.equal(0); + expect(m2.d).to.equal(4); + expect(m2.tx).to.equal(22); + expect(m2.ty).to.equal(88); + + matrix.setTransform(14, 15, 0, 0, 4, 2, 0, 0, 0); + expect(matrix.a).to.equal(4); + expect(matrix.b).to.equal(0); + expect(matrix.c).to.equal(0); + expect(matrix.d).to.equal(2); + expect(matrix.tx).to.equal(14); + expect(matrix.ty).to.equal(15); + }); + + it('should allow rotatation', function () + { + const matrix = new PIXI.Matrix(); + + matrix.rotate(Math.PI); + + expect(matrix.a).to.equal(-1); + expect(matrix.b).to.equal(Math.sin(Math.PI)); + expect(matrix.c).to.equal(-Math.sin(Math.PI)); + expect(matrix.d).to.equal(-1); + }); + + it('should append matrix', function () + { + const m1 = new PIXI.Matrix(); + const m2 = new PIXI.Matrix(); + + m2.tx = 100; + m2.ty = 200; + + m1.append(m2); + + expect(m1.tx).to.equal(m2.tx); + expect(m1.ty).to.equal(m2.ty); + }); + + it('should get IDENTITY and TEMP_MATRIX', function () + { + expect(PIXI.Matrix.IDENTITY instanceof PIXI.Matrix).to.be.true; + expect(PIXI.Matrix.TEMP_MATRIX instanceof PIXI.Matrix).to.be.true; + }); +}); + diff --git a/test/.eslintrc.json b/test/.eslintrc.json index 4705d0c..09620cb 100644 --- a/test/.eslintrc.json +++ b/test/.eslintrc.json @@ -5,10 +5,11 @@ "node": true }, "parserOptions": { - "ecmaVersion": 5, + "ecmaVersion": 6, "sourceType": "script" }, "globals": { + "sinon": false, "expect": false, "PIXI": false }, diff --git a/test/core/Matrix.js b/test/core/Matrix.js new file mode 100644 index 0000000..9d2694b --- /dev/null +++ b/test/core/Matrix.js @@ -0,0 +1,116 @@ +'use strict'; + +describe('PIXI.Matrix', function () +{ + it('should create a new matrix', function () + { + const matrix = new PIXI.Matrix(); + + expect(matrix.a).to.equal(1); + expect(matrix.b).to.equal(0); + expect(matrix.c).to.equal(0); + expect(matrix.d).to.equal(1); + expect(matrix.tx).to.equal(0); + expect(matrix.ty).to.equal(0); + + const input = [0, 1, 2, 3, 4, 5]; + + matrix.fromArray(input); + + expect(matrix.a).to.equal(0); + expect(matrix.b).to.equal(1); + expect(matrix.c).to.equal(3); + expect(matrix.d).to.equal(4); + expect(matrix.tx).to.equal(2); + expect(matrix.ty).to.equal(5); + + let output = matrix.toArray(true); + + expect(output.length).to.equal(9); + expect(output[0]).to.equal(0); + expect(output[1]).to.equal(1); + expect(output[3]).to.equal(3); + expect(output[4]).to.equal(4); + expect(output[6]).to.equal(2); + expect(output[7]).to.equal(5); + + output = matrix.toArray(false); + + expect(output.length).to.equal(9); + expect(output[0]).to.equal(0); + expect(output[1]).to.equal(3); + expect(output[2]).to.equal(2); + expect(output[3]).to.equal(1); + expect(output[4]).to.equal(4); + expect(output[5]).to.equal(5); + }); + + it('should apply different transforms', function () + { + const matrix = new PIXI.Matrix(); + + matrix.translate(10, 20); + matrix.translate(1, 2); + expect(matrix.tx).to.equal(11); + expect(matrix.ty).to.equal(22); + + matrix.scale(2, 4); + expect(matrix.a).to.equal(2); + expect(matrix.b).to.equal(0); + expect(matrix.c).to.equal(0); + expect(matrix.d).to.equal(4); + expect(matrix.tx).to.equal(22); + expect(matrix.ty).to.equal(88); + + const m2 = matrix.clone(); + + expect(m2).to.not.equal(matrix); + expect(m2.a).to.equal(2); + expect(m2.b).to.equal(0); + expect(m2.c).to.equal(0); + expect(m2.d).to.equal(4); + expect(m2.tx).to.equal(22); + expect(m2.ty).to.equal(88); + + matrix.setTransform(14, 15, 0, 0, 4, 2, 0, 0, 0); + expect(matrix.a).to.equal(4); + expect(matrix.b).to.equal(0); + expect(matrix.c).to.equal(0); + expect(matrix.d).to.equal(2); + expect(matrix.tx).to.equal(14); + expect(matrix.ty).to.equal(15); + }); + + it('should allow rotatation', function () + { + const matrix = new PIXI.Matrix(); + + matrix.rotate(Math.PI); + + expect(matrix.a).to.equal(-1); + expect(matrix.b).to.equal(Math.sin(Math.PI)); + expect(matrix.c).to.equal(-Math.sin(Math.PI)); + expect(matrix.d).to.equal(-1); + }); + + it('should append matrix', function () + { + const m1 = new PIXI.Matrix(); + const m2 = new PIXI.Matrix(); + + m2.tx = 100; + m2.ty = 200; + + m1.append(m2); + + expect(m1.tx).to.equal(m2.tx); + expect(m1.ty).to.equal(m2.ty); + }); + + it('should get IDENTITY and TEMP_MATRIX', function () + { + expect(PIXI.Matrix.IDENTITY instanceof PIXI.Matrix).to.be.true; + expect(PIXI.Matrix.TEMP_MATRIX instanceof PIXI.Matrix).to.be.true; + }); +}); + diff --git a/test/core/ObservablePoint.js b/test/core/ObservablePoint.js new file mode 100644 index 0000000..54818a1 --- /dev/null +++ b/test/core/ObservablePoint.js @@ -0,0 +1,53 @@ +'use strict'; + +describe('PIXI.ObservablePoint', function () +{ + it('should create a new observable point', function () + { + const cb = sinon.spy(); + const pt = new PIXI.ObservablePoint(cb, this); + + expect(pt.x).to.equal(0); + expect(pt.y).to.equal(0); + + pt.set(2, 5); + expect(pt.x).to.equal(2); + expect(pt.y).to.equal(5); + + expect(cb.called).to.be.true; + + pt.set(2, 6); + expect(pt.x).to.equal(2); + expect(pt.y).to.equal(6); + + pt.set(2, 0); + expect(pt.x).to.equal(2); + expect(pt.y).to.equal(0); + + pt.set(); + expect(pt.x).to.equal(0); + expect(pt.y).to.equal(0); + + expect(cb.callCount).to.equal(4); + }); + + it('should copy a new observable point', function () + { + function cb() + { + // do nothing + } + + const p1 = new PIXI.ObservablePoint(cb, this, 10, 20); + const p2 = new PIXI.ObservablePoint(cb, this, 5, 2); + const p3 = new PIXI.ObservablePoint(cb, this, 5, 6); + + p1.copy(p2); + expect(p1.x).to.equal(p2.x); + expect(p1.y).to.equal(p2.y); + + p1.copy(p3); + expect(p1.y).to.equal(p3.y); + }); +}); + diff --git a/test/.eslintrc.json b/test/.eslintrc.json index 4705d0c..09620cb 100644 --- a/test/.eslintrc.json +++ b/test/.eslintrc.json @@ -5,10 +5,11 @@ "node": true }, "parserOptions": { - "ecmaVersion": 5, + "ecmaVersion": 6, "sourceType": "script" }, "globals": { + "sinon": false, "expect": false, "PIXI": false }, diff --git a/test/core/Matrix.js b/test/core/Matrix.js new file mode 100644 index 0000000..9d2694b --- /dev/null +++ b/test/core/Matrix.js @@ -0,0 +1,116 @@ +'use strict'; + +describe('PIXI.Matrix', function () +{ + it('should create a new matrix', function () + { + const matrix = new PIXI.Matrix(); + + expect(matrix.a).to.equal(1); + expect(matrix.b).to.equal(0); + expect(matrix.c).to.equal(0); + expect(matrix.d).to.equal(1); + expect(matrix.tx).to.equal(0); + expect(matrix.ty).to.equal(0); + + const input = [0, 1, 2, 3, 4, 5]; + + matrix.fromArray(input); + + expect(matrix.a).to.equal(0); + expect(matrix.b).to.equal(1); + expect(matrix.c).to.equal(3); + expect(matrix.d).to.equal(4); + expect(matrix.tx).to.equal(2); + expect(matrix.ty).to.equal(5); + + let output = matrix.toArray(true); + + expect(output.length).to.equal(9); + expect(output[0]).to.equal(0); + expect(output[1]).to.equal(1); + expect(output[3]).to.equal(3); + expect(output[4]).to.equal(4); + expect(output[6]).to.equal(2); + expect(output[7]).to.equal(5); + + output = matrix.toArray(false); + + expect(output.length).to.equal(9); + expect(output[0]).to.equal(0); + expect(output[1]).to.equal(3); + expect(output[2]).to.equal(2); + expect(output[3]).to.equal(1); + expect(output[4]).to.equal(4); + expect(output[5]).to.equal(5); + }); + + it('should apply different transforms', function () + { + const matrix = new PIXI.Matrix(); + + matrix.translate(10, 20); + matrix.translate(1, 2); + expect(matrix.tx).to.equal(11); + expect(matrix.ty).to.equal(22); + + matrix.scale(2, 4); + expect(matrix.a).to.equal(2); + expect(matrix.b).to.equal(0); + expect(matrix.c).to.equal(0); + expect(matrix.d).to.equal(4); + expect(matrix.tx).to.equal(22); + expect(matrix.ty).to.equal(88); + + const m2 = matrix.clone(); + + expect(m2).to.not.equal(matrix); + expect(m2.a).to.equal(2); + expect(m2.b).to.equal(0); + expect(m2.c).to.equal(0); + expect(m2.d).to.equal(4); + expect(m2.tx).to.equal(22); + expect(m2.ty).to.equal(88); + + matrix.setTransform(14, 15, 0, 0, 4, 2, 0, 0, 0); + expect(matrix.a).to.equal(4); + expect(matrix.b).to.equal(0); + expect(matrix.c).to.equal(0); + expect(matrix.d).to.equal(2); + expect(matrix.tx).to.equal(14); + expect(matrix.ty).to.equal(15); + }); + + it('should allow rotatation', function () + { + const matrix = new PIXI.Matrix(); + + matrix.rotate(Math.PI); + + expect(matrix.a).to.equal(-1); + expect(matrix.b).to.equal(Math.sin(Math.PI)); + expect(matrix.c).to.equal(-Math.sin(Math.PI)); + expect(matrix.d).to.equal(-1); + }); + + it('should append matrix', function () + { + const m1 = new PIXI.Matrix(); + const m2 = new PIXI.Matrix(); + + m2.tx = 100; + m2.ty = 200; + + m1.append(m2); + + expect(m1.tx).to.equal(m2.tx); + expect(m1.ty).to.equal(m2.ty); + }); + + it('should get IDENTITY and TEMP_MATRIX', function () + { + expect(PIXI.Matrix.IDENTITY instanceof PIXI.Matrix).to.be.true; + expect(PIXI.Matrix.TEMP_MATRIX instanceof PIXI.Matrix).to.be.true; + }); +}); + diff --git a/test/core/ObservablePoint.js b/test/core/ObservablePoint.js new file mode 100644 index 0000000..54818a1 --- /dev/null +++ b/test/core/ObservablePoint.js @@ -0,0 +1,53 @@ +'use strict'; + +describe('PIXI.ObservablePoint', function () +{ + it('should create a new observable point', function () + { + const cb = sinon.spy(); + const pt = new PIXI.ObservablePoint(cb, this); + + expect(pt.x).to.equal(0); + expect(pt.y).to.equal(0); + + pt.set(2, 5); + expect(pt.x).to.equal(2); + expect(pt.y).to.equal(5); + + expect(cb.called).to.be.true; + + pt.set(2, 6); + expect(pt.x).to.equal(2); + expect(pt.y).to.equal(6); + + pt.set(2, 0); + expect(pt.x).to.equal(2); + expect(pt.y).to.equal(0); + + pt.set(); + expect(pt.x).to.equal(0); + expect(pt.y).to.equal(0); + + expect(cb.callCount).to.equal(4); + }); + + it('should copy a new observable point', function () + { + function cb() + { + // do nothing + } + + const p1 = new PIXI.ObservablePoint(cb, this, 10, 20); + const p2 = new PIXI.ObservablePoint(cb, this, 5, 2); + const p3 = new PIXI.ObservablePoint(cb, this, 5, 6); + + p1.copy(p2); + expect(p1.x).to.equal(p2.x); + expect(p1.y).to.equal(p2.y); + + p1.copy(p3); + expect(p1.y).to.equal(p3.y); + }); +}); + diff --git a/test/core/Point.js b/test/core/Point.js new file mode 100644 index 0000000..0251918 --- /dev/null +++ b/test/core/Point.js @@ -0,0 +1,55 @@ +'use strict'; + +describe('PIXI.Point', function () +{ + it('should create a new point', function () + { + const pt = new PIXI.Point(); + + expect(pt.x).to.equal(0); + expect(pt.y).to.equal(0); + }); + + it('should clone a new point', function () + { + const p1 = new PIXI.Point(10, 20); + + expect(p1.x).to.equal(10); + expect(p1.y).to.equal(20); + + const p2 = p1.clone(); + + expect(p2.x).to.equal(10); + expect(p2.y).to.equal(20); + expect(p1).to.not.equal(p2); + expect(p1.equals(p2)).to.be.true; + }); + + it('should copy from one point to another', function () + { + const p1 = new PIXI.Point(10, 20); + const p2 = new PIXI.Point(2, 5); + + p1.copy(p2); + + expect(p1.x).to.equal(2); + expect(p1.y).to.equal(5); + }); + + it('should set a new value', function () + { + const p1 = new PIXI.Point(10, 20); + + p1.set(); + expect(p1.x).to.equal(0); + expect(p1.y).to.equal(0); + + p1.set(1); + expect(p1.x).to.equal(1); + expect(p1.y).to.equal(1); + + p1.set(1, 0); + expect(p1.x).to.equal(1); + expect(p1.y).to.equal(0); + }); +}); diff --git a/test/.eslintrc.json b/test/.eslintrc.json index 4705d0c..09620cb 100644 --- a/test/.eslintrc.json +++ b/test/.eslintrc.json @@ -5,10 +5,11 @@ "node": true }, "parserOptions": { - "ecmaVersion": 5, + "ecmaVersion": 6, "sourceType": "script" }, "globals": { + "sinon": false, "expect": false, "PIXI": false }, diff --git a/test/core/Matrix.js b/test/core/Matrix.js new file mode 100644 index 0000000..9d2694b --- /dev/null +++ b/test/core/Matrix.js @@ -0,0 +1,116 @@ +'use strict'; + +describe('PIXI.Matrix', function () +{ + it('should create a new matrix', function () + { + const matrix = new PIXI.Matrix(); + + expect(matrix.a).to.equal(1); + expect(matrix.b).to.equal(0); + expect(matrix.c).to.equal(0); + expect(matrix.d).to.equal(1); + expect(matrix.tx).to.equal(0); + expect(matrix.ty).to.equal(0); + + const input = [0, 1, 2, 3, 4, 5]; + + matrix.fromArray(input); + + expect(matrix.a).to.equal(0); + expect(matrix.b).to.equal(1); + expect(matrix.c).to.equal(3); + expect(matrix.d).to.equal(4); + expect(matrix.tx).to.equal(2); + expect(matrix.ty).to.equal(5); + + let output = matrix.toArray(true); + + expect(output.length).to.equal(9); + expect(output[0]).to.equal(0); + expect(output[1]).to.equal(1); + expect(output[3]).to.equal(3); + expect(output[4]).to.equal(4); + expect(output[6]).to.equal(2); + expect(output[7]).to.equal(5); + + output = matrix.toArray(false); + + expect(output.length).to.equal(9); + expect(output[0]).to.equal(0); + expect(output[1]).to.equal(3); + expect(output[2]).to.equal(2); + expect(output[3]).to.equal(1); + expect(output[4]).to.equal(4); + expect(output[5]).to.equal(5); + }); + + it('should apply different transforms', function () + { + const matrix = new PIXI.Matrix(); + + matrix.translate(10, 20); + matrix.translate(1, 2); + expect(matrix.tx).to.equal(11); + expect(matrix.ty).to.equal(22); + + matrix.scale(2, 4); + expect(matrix.a).to.equal(2); + expect(matrix.b).to.equal(0); + expect(matrix.c).to.equal(0); + expect(matrix.d).to.equal(4); + expect(matrix.tx).to.equal(22); + expect(matrix.ty).to.equal(88); + + const m2 = matrix.clone(); + + expect(m2).to.not.equal(matrix); + expect(m2.a).to.equal(2); + expect(m2.b).to.equal(0); + expect(m2.c).to.equal(0); + expect(m2.d).to.equal(4); + expect(m2.tx).to.equal(22); + expect(m2.ty).to.equal(88); + + matrix.setTransform(14, 15, 0, 0, 4, 2, 0, 0, 0); + expect(matrix.a).to.equal(4); + expect(matrix.b).to.equal(0); + expect(matrix.c).to.equal(0); + expect(matrix.d).to.equal(2); + expect(matrix.tx).to.equal(14); + expect(matrix.ty).to.equal(15); + }); + + it('should allow rotatation', function () + { + const matrix = new PIXI.Matrix(); + + matrix.rotate(Math.PI); + + expect(matrix.a).to.equal(-1); + expect(matrix.b).to.equal(Math.sin(Math.PI)); + expect(matrix.c).to.equal(-Math.sin(Math.PI)); + expect(matrix.d).to.equal(-1); + }); + + it('should append matrix', function () + { + const m1 = new PIXI.Matrix(); + const m2 = new PIXI.Matrix(); + + m2.tx = 100; + m2.ty = 200; + + m1.append(m2); + + expect(m1.tx).to.equal(m2.tx); + expect(m1.ty).to.equal(m2.ty); + }); + + it('should get IDENTITY and TEMP_MATRIX', function () + { + expect(PIXI.Matrix.IDENTITY instanceof PIXI.Matrix).to.be.true; + expect(PIXI.Matrix.TEMP_MATRIX instanceof PIXI.Matrix).to.be.true; + }); +}); + diff --git a/test/core/ObservablePoint.js b/test/core/ObservablePoint.js new file mode 100644 index 0000000..54818a1 --- /dev/null +++ b/test/core/ObservablePoint.js @@ -0,0 +1,53 @@ +'use strict'; + +describe('PIXI.ObservablePoint', function () +{ + it('should create a new observable point', function () + { + const cb = sinon.spy(); + const pt = new PIXI.ObservablePoint(cb, this); + + expect(pt.x).to.equal(0); + expect(pt.y).to.equal(0); + + pt.set(2, 5); + expect(pt.x).to.equal(2); + expect(pt.y).to.equal(5); + + expect(cb.called).to.be.true; + + pt.set(2, 6); + expect(pt.x).to.equal(2); + expect(pt.y).to.equal(6); + + pt.set(2, 0); + expect(pt.x).to.equal(2); + expect(pt.y).to.equal(0); + + pt.set(); + expect(pt.x).to.equal(0); + expect(pt.y).to.equal(0); + + expect(cb.callCount).to.equal(4); + }); + + it('should copy a new observable point', function () + { + function cb() + { + // do nothing + } + + const p1 = new PIXI.ObservablePoint(cb, this, 10, 20); + const p2 = new PIXI.ObservablePoint(cb, this, 5, 2); + const p3 = new PIXI.ObservablePoint(cb, this, 5, 6); + + p1.copy(p2); + expect(p1.x).to.equal(p2.x); + expect(p1.y).to.equal(p2.y); + + p1.copy(p3); + expect(p1.y).to.equal(p3.y); + }); +}); + diff --git a/test/core/Point.js b/test/core/Point.js new file mode 100644 index 0000000..0251918 --- /dev/null +++ b/test/core/Point.js @@ -0,0 +1,55 @@ +'use strict'; + +describe('PIXI.Point', function () +{ + it('should create a new point', function () + { + const pt = new PIXI.Point(); + + expect(pt.x).to.equal(0); + expect(pt.y).to.equal(0); + }); + + it('should clone a new point', function () + { + const p1 = new PIXI.Point(10, 20); + + expect(p1.x).to.equal(10); + expect(p1.y).to.equal(20); + + const p2 = p1.clone(); + + expect(p2.x).to.equal(10); + expect(p2.y).to.equal(20); + expect(p1).to.not.equal(p2); + expect(p1.equals(p2)).to.be.true; + }); + + it('should copy from one point to another', function () + { + const p1 = new PIXI.Point(10, 20); + const p2 = new PIXI.Point(2, 5); + + p1.copy(p2); + + expect(p1.x).to.equal(2); + expect(p1.y).to.equal(5); + }); + + it('should set a new value', function () + { + const p1 = new PIXI.Point(10, 20); + + p1.set(); + expect(p1.x).to.equal(0); + expect(p1.y).to.equal(0); + + p1.set(1); + expect(p1.x).to.equal(1); + expect(p1.y).to.equal(1); + + p1.set(1, 0); + expect(p1.x).to.equal(1); + expect(p1.y).to.equal(0); + }); +}); diff --git a/test/core/index.js b/test/core/index.js index 5f8d479..899c633 100755 --- a/test/core/index.js +++ b/test/core/index.js @@ -9,3 +9,6 @@ require('./toGlobal'); require('./toLocal'); require('./util'); +require('./Point'); +require('./ObservablePoint'); +require('./Matrix');