Skip to content

Commit

Permalink
Merge 44209fa into 6766fd3
Browse files Browse the repository at this point in the history
  • Loading branch information
ngfelixl committed Feb 12, 2019
2 parents 6766fd3 + 44209fa commit 899f3fc
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@geometric/vector",
"version": "0.4.1",
"version": "0.4.2",
"description": "Extend JavaScript arrays with vector capabilities",
"main": "dist/lib/index.js",
"module": "dist/lib-esm/index.js",
Expand Down
62 changes: 62 additions & 0 deletions test/vector-array.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { Vector } from '../src/vector';
import { expect } from 'chai';

describe('vector', () => {
it('should use map correctly', () => {
const vec = new Vector(0, 1, 2);

expect(vec.map(entry => entry * 2)).to.eql([0, 2, 4]);
});

it('should use reduce correctly', () => {
const vec = new Vector(0, 1, 2);

expect(vec.reduce((acc, cur) => acc+cur)).to.equal(3);
});

it('should be accessible via indexed structure', () => {
const vec = new Vector(0, 1, 2);

expect(vec[0]).to.equal(0);
expect(vec[1]).to.equal(1);
expect(vec[2]).to.equal(2);
});

it('should be sortable', () => {
const vec = new Vector(2, 0, 1);

expect(vec.sort()).to.eql([0, 1, 2]);
});

it('should remove an element with splice', () => {
const vec = new Vector(2, 0, 1);

vec.splice(1, 1);

expect(vec).to.eql([2, 1]);
});

it('should add an element with push', () => {
const vec = new Vector(2, 0, 1);

vec.push(3);

expect(vec).to.eql([2, 0, 1, 3]);
});

it('should concat two vectors', () => {
const vec = new Vector(2, 0, 1);

const res = vec.concat(vec);

expect(res).to.eql([2, 0, 1, 2, 0, 1]);
});

it('should filter entries', () => {
const vec = new Vector(2, 0, 1);

const res = vec.filter(o => o > 0);

expect(res).to.eql([2, 1]);
});
});

0 comments on commit 899f3fc

Please sign in to comment.