5
5
This file contains the test-suite for the linear algebra library.
6
6
The tests use javascript test-framework mocha
7
7
*/
8
+ /* eslint-disable */
8
9
9
10
var assert = require ( 'assert' )
10
11
var fs = require ( 'fs' )
11
12
12
13
// file is included here
13
14
eval ( fs . readFileSync ( 'src/la_lib.js' ) + '' )
14
-
15
15
// Tests goes here
16
16
17
17
// creating some vectors
18
18
describe ( 'Create Vectors' , function ( ) {
19
19
describe ( '#toString()' , function ( ) {
20
20
it ( 'should return a string representation' , function ( ) {
21
- assert . equal ( ( new LinearAlgebra . Vector ( 3 , [ 1 , 2 , 3 ] ) ) . toString ( ) , '(1,2,3)' )
21
+ assert . strictEqual ( ( new LinearAlgebra . Vector ( 3 , [ 1 , 2 , 3 ] ) ) . toString ( ) , '(1,2,3)' )
22
22
} )
23
23
} )
24
24
describe ( '#unitBasisVector()' , function ( ) {
25
25
it ( 'should return a unit basis vector' , function ( ) {
26
- assert . equal ( LinearAlgebra . unitBasisVector ( 3 , 1 ) . toString ( ) , '(0,1,0)' )
26
+ assert . strictEqual ( LinearAlgebra . unitBasisVector ( 3 , 1 ) . toString ( ) , '(0,1,0)' )
27
27
} )
28
28
} )
29
29
} )
@@ -34,27 +34,27 @@ describe('Vector operations', function () {
34
34
it ( 'should return vector (2,4,6)' , function ( ) {
35
35
var x = new LinearAlgebra . Vector ( 3 , [ 1 , 2 , 3 ] )
36
36
var y = new LinearAlgebra . Vector ( 3 , [ 1 , 2 , 3 ] )
37
- assert . equal ( ( x . add ( y ) ) . toString ( ) , '(2,4,6)' )
37
+ assert . strictEqual ( ( x . add ( y ) ) . toString ( ) , '(2,4,6)' )
38
38
} )
39
39
} )
40
40
describe ( '#sub()' , function ( ) {
41
41
it ( 'should return vector (0,0,0)' , function ( ) {
42
42
var x = new LinearAlgebra . Vector ( 3 , [ 1 , 2 , 3 ] )
43
43
var y = new LinearAlgebra . Vector ( 3 , [ 1 , 2 , 3 ] )
44
- assert . equal ( ( x . sub ( y ) ) . toString ( ) , '(0,0,0)' )
44
+ assert . strictEqual ( ( x . sub ( y ) ) . toString ( ) , '(0,0,0)' )
45
45
} )
46
46
} )
47
47
describe ( '#dot()' , function ( ) {
48
48
it ( 'should return the dot-product' , function ( ) {
49
49
var x = new LinearAlgebra . Vector ( 3 , [ 1 , 2 , 3 ] )
50
50
var y = new LinearAlgebra . Vector ( 3 , [ 5 , 6 , 7 ] )
51
- assert . equal ( x . dot ( y ) , 38 )
51
+ assert . strictEqual ( x . dot ( y ) , 38 )
52
52
} )
53
53
} )
54
54
describe ( '#scalar()' , function ( ) {
55
55
it ( 'should return the scalar product' , function ( ) {
56
56
var x = new LinearAlgebra . Vector ( 3 , [ 1 , 2 , 3 ] )
57
- assert . equal ( x . scalar ( 2 ) . toString ( ) , '(2,4,6)' )
57
+ assert . strictEqual ( x . scalar ( 2 ) . toString ( ) , '(2,4,6)' )
58
58
} )
59
59
} )
60
60
describe ( '#norm()' , function ( ) {
@@ -73,7 +73,7 @@ describe('Vector operations', function () {
73
73
describe ( '#size()' , function ( ) {
74
74
it ( 'should return the size (not eulidean length!) of the vector' , function ( ) {
75
75
var x = LinearAlgebra . randomVectorInt ( 10 , 1 , 5 )
76
- assert . equal ( x . size ( ) , 10 )
76
+ assert . strictEqual ( x . size ( ) , 10 )
77
77
} )
78
78
} )
79
79
describe ( '#equal()' , function ( ) {
@@ -90,20 +90,20 @@ describe('Methods on vectors', function () {
90
90
describe ( '#component()' , function ( ) {
91
91
it ( 'should return the specified component' , function ( ) {
92
92
var x = new LinearAlgebra . Vector ( 3 , [ 1 , 2 , 2 ] )
93
- assert . equal ( x . component ( 1 ) , 2 )
93
+ assert . strictEqual ( x . component ( 1 ) , 2 )
94
94
} )
95
95
} )
96
96
describe ( '#changeComponent()' , function ( ) {
97
97
it ( 'should return the changed vector' , function ( ) {
98
98
var x = new LinearAlgebra . Vector ( 3 , [ 1 , 2 , 2 ] )
99
99
x . changeComponent ( 1 , 5 )
100
- assert . equal ( x . toString ( ) , '(1,5,2)' )
100
+ assert . strictEqual ( x . toString ( ) , '(1,5,2)' )
101
101
} )
102
102
} )
103
103
describe ( '#toString()' , function ( ) {
104
104
it ( 'should return a string representation of the vector' , function ( ) {
105
105
var x = new LinearAlgebra . Vector ( 4 , [ 9 , 0 , 3 , 1 ] )
106
- assert . equal ( x . toString ( ) , '(9,0,3,1)' )
106
+ assert . strictEqual ( x . toString ( ) , '(9,0,3,1)' )
107
107
} )
108
108
} )
109
109
} )
@@ -112,58 +112,102 @@ describe('class Matrix', function () {
112
112
describe ( '#component()' , function ( ) {
113
113
it ( 'should return the specified component' , function ( ) {
114
114
var A = new LinearAlgebra . Matrix ( 2 , 2 )
115
- assert . equal ( A . component ( 0 , 1 ) , 0 )
116
- var B = new LinearAlgebra . Matrix ( 2 , 2 , [ [ 1 , 2 ] , [ 3 , 4 ] ] )
117
- assert . equal ( B . component ( 1 , 0 ) , 3 )
115
+ assert . strictEqual ( A . component ( 0 , 1 ) , 0 )
116
+ var B = new LinearAlgebra . Matrix ( 2 , 2 , [
117
+ [ 1 , 2 ] ,
118
+ [ 3 , 4 ]
119
+ ] )
120
+ assert . strictEqual ( B . component ( 1 , 0 ) , 3 )
118
121
} )
119
122
} )
120
123
describe ( '#toString()' , function ( ) {
121
124
it ( 'should return a string representation of the matrix' , function ( ) {
122
- var A = new LinearAlgebra . Matrix ( 2 , 2 , [ [ 1 , 2 ] , [ 3 , 4 ] ] )
123
- assert . equal ( A . toString ( ) , '|1,2|\n|3,4|' )
125
+ var A = new LinearAlgebra . Matrix ( 2 , 2 , [
126
+ [ 1 , 2 ] ,
127
+ [ 3 , 4 ]
128
+ ] )
129
+ assert . strictEqual ( A . toString ( ) , '|1,2|\n|3,4|' )
124
130
} )
125
131
} )
126
132
describe ( '#dimension()' , function ( ) {
127
133
it ( 'should return the dimension of the matrix as number array' , function ( ) {
128
- var A = new LinearAlgebra . Matrix ( 3 , 2 , [ [ 1 , 2 ] , [ 3 , 4 ] , [ 5 , 6 ] ] )
129
- assert . equal ( A . dimension ( ) [ 0 ] , 3 )
130
- assert . equal ( A . dimension ( ) [ 1 ] , 2 )
134
+ var A = new LinearAlgebra . Matrix ( 3 , 2 , [
135
+ [ 1 , 2 ] ,
136
+ [ 3 , 4 ] ,
137
+ [ 5 , 6 ]
138
+ ] )
139
+ assert . strictEqual ( A . dimension ( ) [ 0 ] , 3 )
140
+ assert . strictEqual ( A . dimension ( ) [ 1 ] , 2 )
131
141
} )
132
142
} )
133
143
describe ( '#changeComponent()' , function ( ) {
134
144
it ( 'should change the specified component of the matrix' , function ( ) {
135
- var A = new LinearAlgebra . Matrix ( 3 , 2 , [ [ 1 , 2 ] , [ 3 , 4 ] , [ 5 , 6 ] ] )
145
+ var A = new LinearAlgebra . Matrix ( 3 , 2 , [
146
+ [ 1 , 2 ] ,
147
+ [ 3 , 4 ] ,
148
+ [ 5 , 6 ]
149
+ ] )
136
150
A . changeComponent ( 1 , 0 , 5 )
137
- assert . equal ( A . component ( 1 , 0 ) , 5 )
151
+ assert . strictEqual ( A . component ( 1 , 0 ) , 5 )
138
152
} )
139
153
} )
140
154
describe ( '#equal()' , function ( ) {
141
155
it ( 'should compares the matrices' , function ( ) {
142
- var A = new LinearAlgebra . Matrix ( 3 , 2 , [ [ 1 , 2 ] , [ 3 , 4 ] , [ 5 , 6 ] ] )
143
- var B = new LinearAlgebra . Matrix ( 3 , 2 , [ [ 1 , 2 ] , [ 3 , 4 ] , [ 5 , 6 ] ] )
144
- var C = new LinearAlgebra . Matrix ( 2 , 2 , [ [ 1 , 2 ] , [ 3 , 4 ] ] )
145
- var D = new LinearAlgebra . Matrix ( 2 , 2 , [ [ 1 , 2 ] , [ 5 , 4 ] ] )
156
+ var A = new LinearAlgebra . Matrix ( 3 , 2 , [
157
+ [ 1 , 2 ] ,
158
+ [ 3 , 4 ] ,
159
+ [ 5 , 6 ]
160
+ ] )
161
+ var B = new LinearAlgebra . Matrix ( 3 , 2 , [
162
+ [ 1 , 2 ] ,
163
+ [ 3 , 4 ] ,
164
+ [ 5 , 6 ]
165
+ ] )
166
+ var C = new LinearAlgebra . Matrix ( 2 , 2 , [
167
+ [ 1 , 2 ] ,
168
+ [ 3 , 4 ]
169
+ ] )
170
+ var D = new LinearAlgebra . Matrix ( 2 , 2 , [
171
+ [ 1 , 2 ] ,
172
+ [ 5 , 4 ]
173
+ ] )
146
174
assert . ok ( A . equal ( B ) )
147
175
assert . ok ( ! A . equal ( C ) )
148
176
assert . ok ( ! C . equal ( D ) )
149
177
} )
150
178
} )
151
179
describe ( '#add()' , function ( ) {
152
180
it ( 'should return the result of the matrix addition' , function ( ) {
153
- var A = new LinearAlgebra . Matrix ( 3 , 2 , [ [ 1 , 2 ] , [ 3 , 4 ] , [ 5 , 6 ] ] )
154
- var B = new LinearAlgebra . Matrix ( 3 , 2 , [ [ 1 , 2 ] , [ 3 , 4 ] , [ 5 , 6 ] ] )
181
+ var A = new LinearAlgebra . Matrix ( 3 , 2 , [
182
+ [ 1 , 2 ] ,
183
+ [ 3 , 4 ] ,
184
+ [ 5 , 6 ]
185
+ ] )
186
+ var B = new LinearAlgebra . Matrix ( 3 , 2 , [
187
+ [ 1 , 2 ] ,
188
+ [ 3 , 4 ] ,
189
+ [ 5 , 6 ]
190
+ ] )
155
191
var C = A . add ( B )
156
- assert . equal ( C . component ( 1 , 0 ) , 6 )
157
- assert . equal ( C . component ( 1 , 1 ) , 8 )
158
- assert . equal ( C . component ( 0 , 0 ) , 2 )
192
+ assert . strictEqual ( C . component ( 1 , 0 ) , 6 )
193
+ assert . strictEqual ( C . component ( 1 , 1 ) , 8 )
194
+ assert . strictEqual ( C . component ( 0 , 0 ) , 2 )
159
195
} )
160
196
} )
161
197
describe ( '#scalar()' , function ( ) {
162
198
it ( 'should return the result of the matrix-scalar multiplication' , function ( ) {
163
- var A = new LinearAlgebra . Matrix ( 3 , 2 , [ [ 1 , 2 ] , [ 3 , 4 ] , [ 5 , 6 ] ] )
199
+ var A = new LinearAlgebra . Matrix ( 3 , 2 , [
200
+ [ 1 , 2 ] ,
201
+ [ 3 , 4 ] ,
202
+ [ 5 , 6 ]
203
+ ] )
164
204
var B = A . scalar ( 2 )
165
- var C = new LinearAlgebra . Matrix ( 3 , 2 , [ [ 2 , 4 ] , [ 6 , 8 ] , [ 10 , 12 ] ] )
205
+ var C = new LinearAlgebra . Matrix ( 3 , 2 , [
206
+ [ 2 , 4 ] ,
207
+ [ 6 , 8 ] ,
208
+ [ 10 , 12 ]
209
+ ] )
166
210
assert . ok ( B . equal ( C ) )
167
211
} )
168
212
} )
169
- } )
213
+ } )
0 commit comments