55 This file contains the test-suite for the linear algebra library.
66 The tests use javascript test-framework mocha
77*/
8+ /* eslint-disable */
89
910var assert = require ( 'assert' )
1011var fs = require ( 'fs' )
1112
1213// file is included here
1314eval ( fs . readFileSync ( 'src/la_lib.js' ) + '' )
14-
1515// Tests goes here
1616
1717// creating some vectors
1818describe ( 'Create Vectors' , function ( ) {
1919 describe ( '#toString()' , function ( ) {
2020 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)' )
2222 } )
2323 } )
2424 describe ( '#unitBasisVector()' , function ( ) {
2525 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)' )
2727 } )
2828 } )
2929} )
@@ -34,27 +34,27 @@ describe('Vector operations', function () {
3434 it ( 'should return vector (2,4,6)' , function ( ) {
3535 var x = new LinearAlgebra . Vector ( 3 , [ 1 , 2 , 3 ] )
3636 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)' )
3838 } )
3939 } )
4040 describe ( '#sub()' , function ( ) {
4141 it ( 'should return vector (0,0,0)' , function ( ) {
4242 var x = new LinearAlgebra . Vector ( 3 , [ 1 , 2 , 3 ] )
4343 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)' )
4545 } )
4646 } )
4747 describe ( '#dot()' , function ( ) {
4848 it ( 'should return the dot-product' , function ( ) {
4949 var x = new LinearAlgebra . Vector ( 3 , [ 1 , 2 , 3 ] )
5050 var y = new LinearAlgebra . Vector ( 3 , [ 5 , 6 , 7 ] )
51- assert . equal ( x . dot ( y ) , 38 )
51+ assert . strictEqual ( x . dot ( y ) , 38 )
5252 } )
5353 } )
5454 describe ( '#scalar()' , function ( ) {
5555 it ( 'should return the scalar product' , function ( ) {
5656 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)' )
5858 } )
5959 } )
6060 describe ( '#norm()' , function ( ) {
@@ -73,7 +73,7 @@ describe('Vector operations', function () {
7373 describe ( '#size()' , function ( ) {
7474 it ( 'should return the size (not eulidean length!) of the vector' , function ( ) {
7575 var x = LinearAlgebra . randomVectorInt ( 10 , 1 , 5 )
76- assert . equal ( x . size ( ) , 10 )
76+ assert . strictEqual ( x . size ( ) , 10 )
7777 } )
7878 } )
7979 describe ( '#equal()' , function ( ) {
@@ -90,20 +90,20 @@ describe('Methods on vectors', function () {
9090 describe ( '#component()' , function ( ) {
9191 it ( 'should return the specified component' , function ( ) {
9292 var x = new LinearAlgebra . Vector ( 3 , [ 1 , 2 , 2 ] )
93- assert . equal ( x . component ( 1 ) , 2 )
93+ assert . strictEqual ( x . component ( 1 ) , 2 )
9494 } )
9595 } )
9696 describe ( '#changeComponent()' , function ( ) {
9797 it ( 'should return the changed vector' , function ( ) {
9898 var x = new LinearAlgebra . Vector ( 3 , [ 1 , 2 , 2 ] )
9999 x . changeComponent ( 1 , 5 )
100- assert . equal ( x . toString ( ) , '(1,5,2)' )
100+ assert . strictEqual ( x . toString ( ) , '(1,5,2)' )
101101 } )
102102 } )
103103 describe ( '#toString()' , function ( ) {
104104 it ( 'should return a string representation of the vector' , function ( ) {
105105 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)' )
107107 } )
108108 } )
109109} )
@@ -112,58 +112,102 @@ describe('class Matrix', function () {
112112 describe ( '#component()' , function ( ) {
113113 it ( 'should return the specified component' , function ( ) {
114114 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 )
118121 } )
119122 } )
120123 describe ( '#toString()' , function ( ) {
121124 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|' )
124130 } )
125131 } )
126132 describe ( '#dimension()' , function ( ) {
127133 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 )
131141 } )
132142 } )
133143 describe ( '#changeComponent()' , function ( ) {
134144 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+ ] )
136150 A . changeComponent ( 1 , 0 , 5 )
137- assert . equal ( A . component ( 1 , 0 ) , 5 )
151+ assert . strictEqual ( A . component ( 1 , 0 ) , 5 )
138152 } )
139153 } )
140154 describe ( '#equal()' , function ( ) {
141155 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+ ] )
146174 assert . ok ( A . equal ( B ) )
147175 assert . ok ( ! A . equal ( C ) )
148176 assert . ok ( ! C . equal ( D ) )
149177 } )
150178 } )
151179 describe ( '#add()' , function ( ) {
152180 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+ ] )
155191 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 )
159195 } )
160196 } )
161197 describe ( '#scalar()' , function ( ) {
162198 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+ ] )
164204 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+ ] )
166210 assert . ok ( B . equal ( C ) )
167211 } )
168212 } )
169- } )
213+ } )
0 commit comments