-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); | ||
}); | ||
}); |