@@ -5,6 +5,9 @@ const dot = math.dot
55const matrix = math . matrix
66const sparse = math . sparse
77const complex = math . complex
8+ const unit = math . unit
9+ const bignumber = math . bignumber
10+ const fraction = math . fraction
811
912describe ( 'dot' , function ( ) {
1013 it ( 'should calculate dot product for two 1-dim arrays' , function ( ) {
@@ -57,6 +60,40 @@ describe('dot', function () {
5760 assert . strictEqual ( dot ( matrix ( [ [ 7 ] , [ 3 ] ] ) , matrix ( [ 2 , 4 ] ) ) , 26 )
5861 } )
5962
63+ it ( 'should calculate dot product for two 1-dim unit arrays' , function ( ) {
64+ assert . strictEqual ( dot ( [ unit ( '2m' ) , unit ( '4m' ) , unit ( '1m' ) ] , [ 2 , 2 , 3 ] ) . toString ( ) , '15 m' )
65+ assert . strictEqual ( dot ( [ 7 , 3 ] , [ unit ( '2m' ) , unit ( '4m' ) ] ) . toString ( ) , '26 m' )
66+ assert . strictEqual ( dot ( [ unit ( '2m' ) , unit ( '4m' ) , unit ( '1m' ) ] , [ unit ( '2m' ) , unit ( '2m' ) , unit ( '3m' ) ] ) . toString ( ) , '15 m^2' )
67+ } )
68+
69+ it ( 'should calculate dot product for two column unit arrays' , function ( ) {
70+ assert . strictEqual ( dot ( [ [ unit ( '2g' ) ] , [ unit ( '4g' ) ] , [ unit ( '1g' ) ] ] , [ [ 2 ] , [ 2 ] , [ 3 ] ] ) . toString ( ) , '15 g' )
71+ assert . strictEqual ( dot ( [ [ unit ( '7g' ) ] , [ unit ( '3g' ) ] ] , [ [ 2 ] , [ 4 ] ] ) . toString ( ) , '26 g' )
72+ } )
73+
74+ it ( 'should calculate dot product for two 1-dim unit vectors' , function ( ) {
75+ assert . strictEqual ( dot ( matrix ( [ 2 , 4 , 1 ] ) , matrix ( [ unit ( '2g' ) , unit ( '2g' ) , unit ( '3g' ) ] ) ) . toString ( ) , '15 g' )
76+ assert . strictEqual ( dot ( matrix ( [ unit ( '7m' ) , unit ( '3m' ) ] ) , matrix ( [ unit ( '2m' ) , unit ( '4m' ) ] ) ) . toString ( ) , '26 m^2' )
77+ } )
78+
79+ it ( 'should calculate dot product for two column unit vectors' , function ( ) {
80+ assert . strictEqual ( dot ( matrix ( [ [ unit ( '2m' ) ] , [ unit ( '4m' ) ] , [ unit ( '1m' ) ] ] ) , matrix ( [ [ unit ( '2m' ) ] , [ unit ( '2m' ) ] , [ unit ( '3m' ) ] ] ) ) . toString ( ) , '15 m^2' )
81+ assert . strictEqual ( dot ( matrix ( [ [ 7 ] , [ 3 ] ] ) , matrix ( [ [ unit ( '2g' ) ] , [ unit ( '4g' ) ] ] ) ) . toString ( ) , '26 g' )
82+ } )
83+
84+ it ( 'should calculate dot product for two 1-dim unit with complex value vectors' , function ( ) {
85+ assert . deepEqual ( dot ( matrix ( [ unit ( complex ( 2 , 3 ) , 'm' ) , unit ( complex ( 4 , 5 ) , 'm' ) ] ) , matrix ( [ unit ( complex ( 1 , 1 ) , 'm' ) , unit ( complex ( 2 , 4 ) , 'm' ) ] ) ) . toNumeric ( ) , complex ( 33 , 5 ) )
86+ assert . strictEqual ( dot ( matrix ( [ unit ( complex ( 2 , 3 ) , 'm' ) , unit ( complex ( 4 , 5 ) , 'm' ) ] ) , matrix ( [ unit ( complex ( 1 , 1 ) , 'm' ) , unit ( complex ( 2 , 4 ) , 'm' ) ] ) ) . toString ( ) , '(33 + 5i) m^2' )
87+ } )
88+
89+ it ( 'should calculate dot product for two 1-dim unit with BigNumber value vectors' , function ( ) {
90+ assert . strictEqual ( dot ( matrix ( [ [ unit ( bignumber ( 7 ) , 'g' ) ] , [ unit ( bignumber ( 3 ) , 'g' ) ] ] ) , matrix ( [ [ unit ( bignumber ( 2 ) , 'g' ) ] , [ unit ( bignumber ( 4 ) , 'g' ) ] ] ) ) . toString ( ) , '26 g^2' )
91+ } )
92+
93+ it ( 'should calculate dot product for two 1-dim unit with Fraction value vectors' , function ( ) {
94+ assert . strictEqual ( dot ( matrix ( [ [ unit ( fraction ( 0.4 ) , 'm' ) ] , [ unit ( fraction ( '0.5' ) , 'm' ) ] ] ) , matrix ( [ [ unit ( fraction ( 1 , 4 ) , 'm' ) ] , [ unit ( fraction ( '3/4' ) , 'm' ) ] ] ) ) . toString ( ) , '19/40 m^2' )
95+ } )
96+
6097 it ( 'should calculate dot product for sparse vectors' , function ( ) {
6198 assert . strictEqual ( dot ( sparse ( [ 0 , 0 , 2 , 4 , 4 , 1 ] ) , sparse ( [ 1 , 0 , 2 , 2 , 0 , 3 ] ) ) , 15 )
6299 assert . strictEqual ( dot ( sparse ( [ 7 , 1 , 2 , 3 ] ) , sparse ( [ 2 , 0 , 0 , 4 ] ) ) , 26 )
0 commit comments