Skip to content

Commit

Permalink
Merge pull request #20 from ngfelixl/remove-chai
Browse files Browse the repository at this point in the history
refactor(tests): remove chai, rewrite tests for jest expect
  • Loading branch information
ngfelixl committed Feb 13, 2019
2 parents 66701c2 + 0142072 commit 11232ec
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 215 deletions.
61 changes: 1 addition & 60 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@geometric/vector",
"version": "0.4.2",
"version": "0.4.3",
"description": "Extend JavaScript arrays with vector capabilities",
"main": "dist/lib/index.js",
"module": "dist/lib-esm/index.js",
Expand Down Expand Up @@ -39,9 +39,7 @@
],
"homepage": "https://github.com/ngfelixl/vectormath#readme",
"devDependencies": {
"@types/chai": "^4.1.7",
"@types/jest": "^23.3.14",
"chai": "^4.2.0",
"copy-webpack-plugin": "^4.6.0",
"coveralls": "^3.0.2",
"jest": "^23.6.0",
Expand Down
27 changes: 13 additions & 14 deletions test/convex-hull.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Vector, convexHull } from "../src/index";
import { expect } from 'chai';

describe('convexHull', () => {
let data: Vector[];
Expand All @@ -15,7 +14,7 @@ describe('convexHull', () => {
it('should not remove an element on example triangle', () => {
data = convexHull(data);

expect(data.length).to.equal(3);
expect(data.length).toBe(3);
});

it('should not remove any elements on 100 random triangles', () => {
Expand All @@ -26,34 +25,34 @@ describe('convexHull', () => {
new Vector(Math.random(), Math.random())
];
data = convexHull(data);
expect(data.length).to.equal(3);
expect(data.length).toBe(3);
}
});

it('should do nothing when element count < 3', () => {
const data1: Vector[] = [];
const data2 = [new Vector(1, 2)];
const data3 = [new Vector(2, -1), new Vector(1, 4)];
expect(convexHull(data1)).to.eql(data1);
expect(convexHull(data2)).to.eql(data2);
expect(convexHull(data3)).to.eql(data3);
expect(convexHull(data1)).toEqual(data1);
expect(convexHull(data2)).toEqual(data2);
expect(convexHull(data3)).toEqual(data3);
});

it('should remove inner point', () => {
const testData: Vector[] = [...data, new Vector(0.01, 0)];
const hull = convexHull(testData);

expect(hull.length).to.equal(3);
expect(data).to.contain(hull[0])
.and.to.contain(hull[1])
.and.to.contain(hull[2]);
expect(hull.length).toBe(3);
expect(data).toContain(hull[0]);
expect(data).toContain(hull[1]);
expect(data).toContain(hull[2]);
});

it('should not remove outer points', () => {
const testData: Vector[] = [...data, new Vector(1, 1)];
const hull = convexHull(testData);

expect(hull.length).to.equal(4);
expect(hull.length).toBe(4);
});

it('should not remove a point out of 100 points on circle surface', () => {
Expand All @@ -66,7 +65,7 @@ describe('convexHull', () => {
}
const hull = convexHull(data);

expect(hull.length).to.equal(100);
expect(hull.length).toBe(100);
});

it('should not remove a point out of 100 points on circle surface', () => {
Expand All @@ -85,7 +84,7 @@ describe('convexHull', () => {
));
}
const hull = convexHull(data);
expect(hull.length).to.equal(100);
expect(hull.length).toBe(100);
});

it('should remove 100 elements out of a bounding rect', () => {
Expand All @@ -96,6 +95,6 @@ describe('convexHull', () => {
));
}
const hull = convexHull(data);
expect(hull.length).to.equal(4);
expect(hull.length).toBe(4);
});
});
11 changes: 5 additions & 6 deletions test/doubly-connected-edge-list.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Vector } from '../src/vector';
import { doublyConnectedEdgeList } from '../src/index';
import { expect } from 'chai';

describe('doubly-connected-edge-list', () => {
it('should compute the double connected edge list for 3 vectors', () => {
Expand All @@ -12,7 +11,7 @@ describe('doubly-connected-edge-list', () => {

const edgeList = doublyConnectedEdgeList(vectors);

expect(edgeList).to.eql([
expect(edgeList).toEqual([
{ edge: [ 0, 1 ],
start: [ 1, 0 ],
end: [ 1, 1 ],
Expand Down Expand Up @@ -48,7 +47,7 @@ describe('doubly-connected-edge-list', () => {

const edgeList = doublyConnectedEdgeList(vectors);

expect(edgeList).to.eql([
expect(edgeList).toEqual([
{ edge: [ 0, 1 ],
start: [ 1, 0 ],
end: [ 1, 1 ],
Expand Down Expand Up @@ -90,7 +89,7 @@ describe('doubly-connected-edge-list', () => {

const edgeList = doublyConnectedEdgeList(vectors);

expect(edgeList).to.eql([
expect(edgeList).toEqual([
{ edge: [ 1, 0 ],
start: [ -2, -1 ],
end: [ -1, -1 ],
Expand Down Expand Up @@ -122,7 +121,7 @@ describe('doubly-connected-edge-list', () => {
];

expect(() => { doublyConnectedEdgeList(vectors); })
.to.throw(new RegExp('Vectors must be 2-dimensional'));
.toThrow(new RegExp('Vectors must be 2-dimensional'));
});

it('should return null if there is an intersection', () => {
Expand All @@ -135,6 +134,6 @@ describe('doubly-connected-edge-list', () => {

const list = doublyConnectedEdgeList(vectors);

expect(list).to.be.null;
expect(list).toBeFalsy;
});
});
25 changes: 12 additions & 13 deletions test/intersection.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { intersection, Vector } from '../src/index';
import { expect } from 'chai';

describe('intersection', () => {
it('should return [0.5, 0.5] as intersection point for [0,0]->[1,1], [0,1]->[1,0]', () => {
Expand All @@ -8,7 +7,7 @@ describe('intersection', () => {

const point = intersection(segment0, segment1);

expect(point).to.eql([0.5, 0.5]);
expect(point).toEqual([0.5, 0.5]);
});

it('should return [0, 0] as intersection point for [-1,-1]->[1,1], [-1,1]->[1,-1]', () => {
Expand All @@ -17,7 +16,7 @@ describe('intersection', () => {

const point = intersection(segment0, segment1);

expect(point).to.eql([0, 0]);
expect(point).toEqual([0, 0]);
});

it('should return [0.5, 0] as intersection point for [0,0]->[1,0], [1,1]->[0,-1]', () => {
Expand All @@ -26,7 +25,7 @@ describe('intersection', () => {

const point = intersection(segment0, segment1);

expect(point).to.eql([0.5, 0]);
expect(point).toEqual([0.5, 0]);
});

it('should return [0.5, 0] as intersection point for [1,1]->[0,-1] and [0,0]->[1,0]', () => {
Expand All @@ -36,7 +35,7 @@ describe('intersection', () => {

const point = intersection(segment0, segment1);

expect(point).to.eql([0.5, 0]);
expect(point).toEqual([0.5, 0]);
})

it('should return null for non-intersecting segments', () => {
Expand All @@ -45,7 +44,7 @@ describe('intersection', () => {

const point = intersection(segment0, segment1);

expect(point).to.be.null;
expect(point).toBeNull;
});

it('should return null if intersecting not between these points', () => {
Expand All @@ -54,7 +53,7 @@ describe('intersection', () => {

const point = intersection(segment0, segment1);

expect(point).to.be.null;
expect(point).toBeNull;
});

it('should return null if starting point is the intersection', () => {
Expand All @@ -63,7 +62,7 @@ describe('intersection', () => {

const point = intersection(segment0, segment1);

expect(point).to.be.null;
expect(point).toBeNull;
});

it('should return null if end point is the intersection', () => {
Expand All @@ -72,29 +71,29 @@ describe('intersection', () => {

const point = intersection(segment0, segment1);

expect(point).to.be.null;
expect(point).toBeNull;
});

it('should return return an Error for 3D inputs', () => {
const segment0: [Vector, Vector] = [new Vector(0, 0, 0), new Vector(1, 1, 1)];
const segment1: [Vector, Vector] = [new Vector(0, 0.5, 0.5), new Vector(1, 0.5, 0.5)];

expect(() => { intersection(segment0, segment1); })
.to.throw(new RegExp(`To compute the 2 dimensional intersection`));
.toThrow(new RegExp(`To compute the 2 dimensional intersection`));
});

it('should return an error if input is empty', () => {
expect(() => { intersection(undefined as any, null as any); })
.to.throw(new RegExp(`Intersection requires Vectors as input`));
.toThrow(new RegExp(`Intersection requires Vectors as input`));
});

it('should return an error if input is empty', () => {
expect(() => { intersection(new Array<Vector>() as any, new Array<Vector>() as any); })
.to.throw(new RegExp(`To compute the 2 dimensional intersection, 2 dimensional vectors are required`));
.toThrow(new RegExp(`To compute the 2 dimensional intersection, 2 dimensional vectors are required`));
});

it('should return an error if input is string', () => {
expect(() => { intersection('fjdskjsd' as any, null as any); })
.to.throw(new RegExp(`Intersection requires Vectors as input`));
.toThrow(new RegExp(`Intersection requires Vectors as input`));
});
});

0 comments on commit 11232ec

Please sign in to comment.