UNPKG

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