Skip to content

Commit

Permalink
Added core tests for Matrix, Ellipse, Circle and TilingSprite (#3699)
Browse files Browse the repository at this point in the history
* Added matrix tests for prepend() and identity()

* Added contains if branch tests for Circle and Ellipse

* Removed trailing whitespace in circle.js

* Added TilingSprite tests for contains, width and height

* Removed .only tag in TilingSprite test

* Changed test values for prepand and identity tests, as per change request
  • Loading branch information
JessicaNeary authored and bigtimebuddy committed Feb 21, 2017
1 parent 86a36f8 commit 00bbfcb
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 1 deletion.
4 changes: 4 additions & 0 deletions test/core/Circle.js
Expand Up @@ -53,6 +53,10 @@ describe('PIXI.Circle', function ()
expect(circ1.contains(10, 16)).to.be.false;
expect(circ1.contains(11, 15)).to.be.false;
expect(circ1.contains(0, 0)).to.be.false;

const circ2 = new PIXI.Circle(10, 10, 0);

expect(circ2.contains(10, 10)).to.be.false;
});

it('should return framing rectangle', function ()
Expand Down
4 changes: 4 additions & 0 deletions test/core/Ellipse.js
Expand Up @@ -56,6 +56,10 @@ describe('PIXI.Ellipse', function ()
expect(ellipse1.contains(10, 16)).to.be.false;
expect(ellipse1.contains(11, 15)).to.be.false;
expect(ellipse1.contains(0, 0)).to.be.false;

const ellipse2 = new PIXI.Ellipse(10, 10, 0, 0);

expect(ellipse2.contains(10, 10)).to.be.false;
});

it('should return framing rectangle', function ()
Expand Down
52 changes: 51 additions & 1 deletion test/core/Matrix.js
Expand Up @@ -107,10 +107,60 @@ describe('PIXI.Matrix', function ()
expect(m1.ty).to.equal(m2.ty);
});

it('should prepend matrix', function ()
{
const m1 = new PIXI.Matrix();
const m2 = new PIXI.Matrix();

m2.set(2, 3, 4, 5, 100, 200);
m1.prepend(m2);

expect(m1.a).to.equal(m2.a);
expect(m1.b).to.equal(m2.b);
expect(m1.c).to.equal(m2.c);
expect(m1.d).to.equal(m2.d);
expect(m1.tx).to.equal(m2.tx);
expect(m1.ty).to.equal(m2.ty);

const m3 = new PIXI.Matrix();
const m4 = new PIXI.Matrix();

m3.prepend(m4);

expect(m3.a).to.equal(m4.a);
expect(m3.b).to.equal(m4.b);
expect(m3.c).to.equal(m4.c);
expect(m3.d).to.equal(m4.d);
expect(m3.tx).to.equal(m4.tx);
expect(m3.ty).to.equal(m4.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;
});
});

it('should reset matrix to default when identity() is called', function ()
{
const matrix = new PIXI.Matrix();

matrix.set(2, 3, 4, 5, 100, 200);

expect(matrix.a).to.equal(2);
expect(matrix.b).to.equal(3);
expect(matrix.c).to.equal(4);
expect(matrix.d).to.equal(5);
expect(matrix.tx).to.equal(100);
expect(matrix.ty).to.equal(200);

matrix.identity();

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);
});
});
21 changes: 21 additions & 0 deletions test/core/TilingSprite.js
Expand Up @@ -24,4 +24,25 @@ describe('PIXI.TilingSprite', function ()
expect(bounds.height).to.equal(600);
});
});

it('checks if tilingSprite contains a point', function ()
{
const texture = new PIXI.Texture(new PIXI.BaseTexture());
const tilingSprite = new PIXI.extras.TilingSprite(texture, 200, 300);

expect(tilingSprite.containsPoint(new PIXI.Point(1, 1))).to.equal(true);
expect(tilingSprite.containsPoint(new PIXI.Point(300, 400))).to.equal(false);
});

it('gets and sets height and width correctly', function ()
{
const texture = new PIXI.Texture(new PIXI.BaseTexture());
const tilingSprite = new PIXI.extras.TilingSprite(texture, 200, 300);

tilingSprite.width = 400;
tilingSprite.height = 600;

expect(tilingSprite.width).to.equal(400);
expect(tilingSprite.height).to.equal(600);
});
});

0 comments on commit 00bbfcb

Please sign in to comment.