UNPKG

1.1 kBJavaScriptView Raw
1const CompositionAlgebra = require('../src/CompositionAlgebra')
2const realField = require('../src/realField')
3
4describe('CompositionAlgebra', () => {
5 it('checks n is 1, 2, 4 or 8', () => {
6 ;(() => {
7 CompositionAlgebra(realField, 3)
8 }).should.throw()
9 })
10
11 it('has signature (field, num)', () => {
12 const R = CompositionAlgebra(realField, 1)
13 const C = CompositionAlgebra(realField, 2)
14 const H = CompositionAlgebra(realField, 4)
15 const O = CompositionAlgebra(realField, 8)
16
17 R.should.be.instanceOf(Function)
18 C.should.be.instanceOf(Function)
19 H.should.be.instanceOf(Function)
20 O.should.be.instanceOf(Function)
21 })
22
23 it('returns a Scalar class', () => {
24 const R = CompositionAlgebra(realField, 1)
25 const C = CompositionAlgebra(realField, 2)
26
27 R.addition(2, 3).should.be.eql(5)
28
29 const x = new R(2)
30 x.data.should.be.eql(2)
31
32 x.addition(3).data.should.be.eql(5)
33
34 C.addition([1, 2], [3, 4]).should.be.eql([4, 6])
35
36 const z = new C([1, 2])
37 z.data.should.be.eql([1, 2])
38
39 z.addition([3, 4]).data.should.be.eql([4, 6])
40 })
41})