1 | const algebra = require('algebra')
|
2 |
|
3 | const R = algebra.Real
|
4 |
|
5 | const methodBinaryOperator = require('./features/methodBinaryOperator')
|
6 | const methodUnaryOperator = require('./features/methodUnaryOperator')
|
7 | const staticBinaryOperator = require('./features/staticBinaryOperator')
|
8 | const staticUnaryOperator = require('./features/staticUnaryOperator')
|
9 |
|
10 | describe('Real', () => {
|
11 | describe('zero', () => {
|
12 | it('is static', () => {
|
13 | R.zero.should.eql(0)
|
14 | })
|
15 | })
|
16 |
|
17 | describe('one', () => {
|
18 | it('is static', () => {
|
19 | R.one.should.eql(1)
|
20 | })
|
21 | })
|
22 |
|
23 | describe('addition', () => {
|
24 | const operator = 'addition'
|
25 |
|
26 | it('is a static method', staticBinaryOperator(R, operator, 2, 3, 5))
|
27 |
|
28 | it('is a class method', methodBinaryOperator(R, operator, 1, 2, 3))
|
29 |
|
30 | it('accepts many arguments', () => {
|
31 | const x = new R(1)
|
32 | x.addition(2, 3, 4).data.should.eql(10)
|
33 | })
|
34 | })
|
35 |
|
36 | describe('subtraction', () => {
|
37 | const operator = 'subtraction'
|
38 |
|
39 | it('is a static method', staticBinaryOperator(R, operator, 2, 3, -1))
|
40 |
|
41 | it('is a class method', methodBinaryOperator(R, operator, -1, -4, 3))
|
42 |
|
43 | it('accepts many arguments', () => {
|
44 | const x = new R(10)
|
45 | x.subtraction(1, 2, 3).data.should.eql(4)
|
46 | })
|
47 | })
|
48 |
|
49 | describe('multiplication', () => {
|
50 | const operator = 'multiplication'
|
51 |
|
52 | it('is a static method', staticBinaryOperator(R, operator, 8, -2, -16))
|
53 |
|
54 | it('is a class method', methodBinaryOperator(R, operator, 2, 2, 4))
|
55 |
|
56 | it('accepts many arguments', () => {
|
57 | const x = new R(2)
|
58 | x.multiplication(3, 4, 5).data.should.eql(120)
|
59 | })
|
60 | })
|
61 |
|
62 | describe('division', () => {
|
63 | const operator = 'division'
|
64 |
|
65 | it('is a static method', staticBinaryOperator(R, operator, 8, 2, 4))
|
66 |
|
67 | it('is a class method', methodBinaryOperator(R, operator, -2, 4, -0.5))
|
68 |
|
69 | it('accepts many arguments', () => {
|
70 | const x = new R(120)
|
71 | x.division(3, 4, 5).data.should.eql(2)
|
72 | })
|
73 | })
|
74 |
|
75 | describe('equality', () => {
|
76 | const operator = 'equality'
|
77 |
|
78 | it('is a static method', staticBinaryOperator(R, operator, 10, 10, true))
|
79 |
|
80 | it('is a class method', () => {
|
81 | const x = new R(10)
|
82 | x.equality(10).should.be.ok
|
83 | })
|
84 | })
|
85 |
|
86 | describe('disequality', () => {
|
87 | const operator = 'disequality'
|
88 |
|
89 | it('is a static method', staticBinaryOperator(R, operator, 10, 20, true))
|
90 |
|
91 | it('is a class method', () => {
|
92 | const x = new R(10)
|
93 | x.disequality(20).should.be.ok
|
94 | })
|
95 | })
|
96 |
|
97 | describe('negation', () => {
|
98 | const operator = 'negation'
|
99 |
|
100 | it('is a static method', staticUnaryOperator(R, operator, -2, 2))
|
101 |
|
102 | it('is a class method', methodUnaryOperator(R, operator, 8, -8))
|
103 |
|
104 | it('is an involution', () => {
|
105 | const x = new R(10)
|
106 | x.negation().negation().data.should.be.eql(10)
|
107 | })
|
108 | })
|
109 |
|
110 | describe('inversion', () => {
|
111 | const operator = 'inversion'
|
112 |
|
113 | it('is a static method', staticUnaryOperator(R, operator, 2, 0.5))
|
114 |
|
115 | it('is a class method', methodUnaryOperator(R, operator, -4, -0.25))
|
116 |
|
117 | it('is an involution', () => {
|
118 | const x = new R(10)
|
119 | x.inversion().inversion().data.should.be.eql(10)
|
120 | })
|
121 | })
|
122 | })
|