@@ -4,17 +4,17 @@ const utils = new dfd.Utils();
44
55describe ( "Utils" , function ( ) {
66 it ( "removes an element from an array" , function ( ) {
7- let arr = [ 1 , 2 , 3 , 4 ] ;
8- assert . deepEqual ( utils . removeElementFromArray ( arr , 2 ) , [ 1 , 2 , 4 ] ) ;
7+ let arr = [ 1 , 2 , 3 , 4 ] ;
8+ assert . deepEqual ( utils . removeElementFromArray ( arr , 2 ) , [ 1 , 2 , 4 ] ) ;
99 } ) ;
1010
1111 it ( "Checks if variable is a string" , function ( ) {
12- let arr = [ "1" , "2" ] ;
12+ let arr = [ "1" , "2" ] ;
1313 assert . isTrue ( utils . isString ( arr [ 0 ] ) ) ;
1414 } ) ;
1515
1616 it ( "Checks if variable is a number" , function ( ) {
17- let arr = [ 1 , 2 , 3 , 4 ] ;
17+ let arr = [ 1 , 2 , 3 , 4 ] ;
1818 assert . isTrue ( utils . isNumber ( arr [ 0 ] ) ) ;
1919 } ) ;
2020
@@ -25,16 +25,6 @@ describe("Utils", function () {
2525 assert . isFalse ( utils . isNull ( val2 ) ) ;
2626 } ) ;
2727
28- it ( "Checks if value is a valid Date object" , function ( ) {
29- let date1 = new Date ( ) ;
30- let date2 = "2021-01-01 00:00:00" ;
31- let isoDate = "2021-01-01T00:00:00.000Z" ;
32-
33- assert . isTrue ( utils . isDate ( date1 ) ) ;
34- assert . isTrue ( utils . isDate ( date2 ) ) ;
35- assert . isTrue ( utils . isDate ( isoDate ) ) ;
36- } ) ;
37-
3828 it ( "Checks if value is undefined" , function ( ) {
3929 let arr ;
4030 assert . isTrue ( utils . isUndefined ( arr ) ) ;
@@ -43,150 +33,150 @@ describe("Utils", function () {
4333 it ( "Generate numbers between two set of values [both inclusive]" , function ( ) {
4434 let start = 0 ;
4535 let end = 5 ;
46- let data = [ 0 , 1 , 2 , 3 , 4 , 5 ] ;
36+ let data = [ 0 , 1 , 2 , 3 , 4 , 5 ] ;
4737 assert . deepEqual ( utils . range ( start , end ) , data ) ;
4838 } ) ;
4939
5040 it ( "transposes an array" , function ( ) {
51- let data = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 20 , 30 , 40 ] ] ;
52- let result = [ [ 1 , 4 , 20 ] , [ 2 , 5 , 30 ] , [ 3 , 6 , 40 ] ] ;
41+ let data = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 20 , 30 , 40 ] ] ;
42+ let result = [ [ 1 , 4 , 20 ] , [ 2 , 5 , 30 ] , [ 3 , 6 , 40 ] ] ;
5343 assert . deepEqual ( utils . transposeArray ( data ) , result ) ;
5444 } ) ;
5545
5646 describe ( "inferDtype" , function ( ) {
5747 it ( "Returns string type present in an 1D array" , function ( ) {
58- let data = [ 'Alice' , 'Boy' , 'Girl' , "39" ] ;
59- let result = [ 'string' ] ;
48+ let data = [ 'Alice' , 'Boy' , 'Girl' , "39" ] ;
49+ let result = [ 'string' ] ;
6050 assert . deepEqual ( utils . inferDtype ( data ) , result ) ;
6151 } ) ;
6252
6353 it ( "Returns float type present in an 1D array" , function ( ) {
64- let data = [ 1.1 , 2.1 , 3.2 , 4.4 ] ;
65- let result = [ 'float32' ] ;
54+ let data = [ 1.1 , 2.1 , 3.2 , 4.4 ] ;
55+ let result = [ 'float32' ] ;
6656 assert . deepEqual ( utils . inferDtype ( data ) , result ) ;
6757 } ) ;
6858
6959 it ( "Returns int type present in an 1D array" , function ( ) {
70- let data = [ 1 , 2 , 3 , 45 ] ;
71- let result = [ 'int32' ] ;
60+ let data = [ 1 , 2 , 3 , 45 ] ;
61+ let result = [ 'int32' ] ;
7262 assert . deepEqual ( utils . inferDtype ( data ) , result ) ;
7363 } ) ;
7464 it ( "Returns float when there's a mixture of int and float in a 1D array" , function ( ) {
75- let data = [ 1 , 2.1 , 3 , 45 ] ;
76- let result = [ 'float32' ] ;
65+ let data = [ 1 , 2.1 , 3 , 45 ] ;
66+ let result = [ 'float32' ] ;
7767 assert . deepEqual ( utils . inferDtype ( data ) , result ) ;
7868 } ) ;
7969
8070 it ( "Returns float type when NaN is present in an 1D array" , function ( ) {
81- let data = [ 1 , 2 , 3 , 45 , NaN ] ;
82- let result = [ 'float32' ] ;
71+ let data = [ 1 , 2 , 3 , 45 , NaN ] ;
72+ let result = [ 'float32' ] ;
8373 assert . deepEqual ( utils . inferDtype ( data ) , result ) ;
8474 } ) ;
8575
8676 it ( "Returns correct dtype if NaN present in data" , function ( ) {
8777 let data = utils . transposeArray ( [
88- [ 18.7 , 17.4 , 18 , NaN , 19.3 ] ,
89- [ 20 , NaN , 19 , 18 , 20 ] ] ) ;
90- let result = [ 'float32' , 'float32' ] ;
78+ [ 18.7 , 17.4 , 18 , NaN , 19.3 ] ,
79+ [ 20 , NaN , 19 , 18 , 20 ] ] ) ;
80+ let result = [ 'float32' , 'float32' ] ;
9181 assert . deepEqual ( utils . inferDtype ( data ) , result ) ;
9282 } ) ;
9383
9484 it ( "Returns the data type present in an 2D array" , function ( ) {
95- let data = utils . transposeArray ( [ [ 'Alice' , 'Boy' , 'Girl' , "39" ] , [ 2 , 5 , 30 , 89 ] , [ 3.1 , 6.1 , 40.1 , 78.2 ] ] ) ;
96- let result = [ 'string' , 'int32' , 'float32' ] ;
85+ let data = utils . transposeArray ( [ [ 'Alice' , 'Boy' , 'Girl' , "39" ] , [ 2 , 5 , 30 , 89 ] , [ 3.1 , 6.1 , 40.1 , 78.2 ] ] ) ;
86+ let result = [ 'string' , 'int32' , 'float32' ] ;
9787 assert . deepEqual ( utils . inferDtype ( data ) , result ) ;
9888 } ) ;
9989
10090 it ( "Returns the string dtype when there's a mixture of dtypes in a 2D array" , function ( ) {
101- let data = utils . transposeArray ( [ [ 'Alice' , 'Boy' , 'Girl' , 21 ] , [ 2 , 5 , 30 , "hey" ] , [ 3 , 6 , 40.1 , 78.2 ] ] ) ;
102- let result = [ 'string' , 'string' , 'float32' ] ;
91+ let data = utils . transposeArray ( [ [ 'Alice' , 'Boy' , 'Girl' , 21 ] , [ 2 , 5 , 30 , "hey" ] , [ 3 , 6 , 40.1 , 78.2 ] ] ) ;
92+ let result = [ 'string' , 'string' , 'float32' ] ;
10393 assert . deepEqual ( utils . inferDtype ( data ) , result ) ;
10494 } ) ;
10595
10696 it ( "Returns bool type in a 1D array" , function ( ) {
107- let data = [ true , true , false , false , false , true ] ;
108- let result = [ 'boolean' ] ;
97+ let data = [ true , true , false , false , false , true ] ;
98+ let result = [ 'boolean' ] ;
10999 assert . deepEqual ( utils . inferDtype ( data ) , result ) ;
110100 } ) ;
111101 it ( "Returns bool type in a 2D array" , function ( ) {
112- let data = utils . transposeArray ( [ [ true , false , true ] , [ "boy" , "girl" , "man" ] , [ 20 , 30 , 24 ] ] ) ;
113- let result = [ 'boolean' , 'string' , 'int32' ] ;
102+ let data = utils . transposeArray ( [ [ true , false , true ] , [ "boy" , "girl" , "man" ] , [ 20 , 30 , 24 ] ] ) ;
103+ let result = [ 'boolean' , 'string' , 'int32' ] ;
114104 assert . deepEqual ( utils . inferDtype ( data ) , result ) ;
115105 } ) ;
116106
117107 it ( "Returns string type if values are all NaN" , function ( ) {
118- let data = utils . transposeArray ( [ [ true , false , true ] , [ "boy" , "girl" , "boy" ] , [ NaN , NaN , NaN ] ] ) ;
119- let result = [ 'boolean' , 'string' , 'float32' ] ;
108+ let data = utils . transposeArray ( [ [ true , false , true ] , [ "boy" , "girl" , "boy" ] , [ NaN , NaN , NaN ] ] ) ;
109+ let result = [ 'boolean' , 'string' , 'float32' ] ;
120110 assert . deepEqual ( utils . inferDtype ( data ) , result ) ;
121111 } ) ;
122112
123113 } ) ;
124114
125115 describe ( "mapIntegersToBooleans" , function ( ) {
126116 it ( "map ints to bools in array of arrays" , function ( ) {
127- let data = [ [ 1 , 0 , 1 ] , [ 1 , 1 , 0 ] ] ;
128- assert . deepEqual ( utils . mapIntegersToBooleans ( data , 2 ) , [ [ true , false , true ] , [ true , true , false ] ] ) ;
117+ let data = [ [ 1 , 0 , 1 ] , [ 1 , 1 , 0 ] ] ;
118+ assert . deepEqual ( utils . mapIntegersToBooleans ( data , 2 ) , [ [ true , false , true ] , [ true , true , false ] ] ) ;
129119 } ) ;
130120
131121 it ( "map ints to bools in array" , function ( ) {
132- let data = [ 1 , 0 , 0 , 1 , 1 ] ;
133- assert . deepEqual ( utils . mapIntegersToBooleans ( data , 1 ) , [ true , false , false , true , true ] ) ;
122+ let data = [ 1 , 0 , 0 , 1 , 1 ] ;
123+ assert . deepEqual ( utils . mapIntegersToBooleans ( data , 1 ) , [ true , false , false , true , true ] ) ;
134124 } ) ;
135125 } ) ;
136126
137127 describe ( "round" , function ( ) {
138128 it ( "round elements in array to 1 dp" , function ( ) {
139- let data = [ 10.01 , 2.2 , 3.11 , 20.505 , 20.22 , 40.0909 ] ;
140- assert . deepEqual ( utils . round ( data , 1 , true ) , [ 10.0 , 2.2 , 3.1 , 20.5 , 20.2 , 40.1 ] ) ;
129+ let data = [ 10.01 , 2.2 , 3.11 , 20.505 , 20.22 , 40.0909 ] ;
130+ assert . deepEqual ( utils . round ( data , 1 , true ) , [ 10.0 , 2.2 , 3.1 , 20.5 , 20.2 , 40.1 ] ) ;
141131 } ) ;
142132
143133 it ( "round elements in array to 2 dp" , function ( ) {
144- let data = [ 10.019 , 2.2099 , 3.1145 , 20.506 , 20.22 , 40.0909 ] ;
145- assert . deepEqual ( utils . round ( data , 2 , true ) , [ 10.02 , 2.21 , 3.11 , 20.51 , 20.22 , 40.09 ] ) ;
134+ let data = [ 10.019 , 2.2099 , 3.1145 , 20.506 , 20.22 , 40.0909 ] ;
135+ assert . deepEqual ( utils . round ( data , 2 , true ) , [ 10.02 , 2.21 , 3.11 , 20.51 , 20.22 , 40.09 ] ) ;
146136 } ) ;
147137 } ) ;
148138
149139 describe ( "replaceUndefinedWithNaN" , function ( ) {
150140 it ( "replace undefined in Series with NaN" , function ( ) {
151- let data = [ 10.01 , 2.2 , undefined , 20.505 , 20.22 , undefined ] ;
152- assert . deepEqual ( utils . replaceUndefinedWithNaN ( data , true ) , [ 10.01 , 2.2 , NaN , 20.505 , 20.22 , NaN ] ) ;
141+ let data = [ 10.01 , 2.2 , undefined , 20.505 , 20.22 , undefined ] ;
142+ assert . deepEqual ( utils . replaceUndefinedWithNaN ( data , true ) , [ 10.01 , 2.2 , NaN , 20.505 , 20.22 , NaN ] ) ;
153143 } ) ;
154144
155145 it ( "replace undefined in DataFrame with NaN" , function ( ) {
156- let data = [ [ 10.01 , 2.2 , undefined , 20.505 , 20.22 , undefined ] ,
157- [ 10.01 , undefined , undefined , 20.505 , 20 , undefined ] ] ;
146+ let data = [ [ 10.01 , 2.2 , undefined , 20.505 , 20.22 , undefined ] ,
147+ [ 10.01 , undefined , undefined , 20.505 , 20 , undefined ] ] ;
158148
159- let result = [ [ 10.01 , 2.2 , NaN , 20.505 , 20.22 , NaN ] ,
160- [ 10.01 , NaN , NaN , 20.505 , 20 , NaN ] ] ;
149+ let result = [ [ 10.01 , 2.2 , NaN , 20.505 , 20.22 , NaN ] ,
150+ [ 10.01 , NaN , NaN , 20.505 , 20 , NaN ] ] ;
161151 assert . deepEqual ( utils . replaceUndefinedWithNaN ( data , false ) , result ) ;
162152 } ) ;
163153
164154 it ( "replace null in Series with NaN" , function ( ) {
165- let data = [ 10.01 , 2.2 , null , 20.505 , 20.22 , null ] ;
166- assert . deepEqual ( utils . replaceUndefinedWithNaN ( data , true ) , [ 10.01 , 2.2 , NaN , 20.505 , 20.22 , NaN ] ) ;
155+ let data = [ 10.01 , 2.2 , null , 20.505 , 20.22 , null ] ;
156+ assert . deepEqual ( utils . replaceUndefinedWithNaN ( data , true ) , [ 10.01 , 2.2 , NaN , 20.505 , 20.22 , NaN ] ) ;
167157 } ) ;
168158
169159 it ( "replace null in DataFrame with NaN" , function ( ) {
170- let data = [ [ 10.01 , 2.2 , null , 20.505 , 20.22 , null ] ,
171- [ 10.01 , null , null , 20.505 , 20 , null ] ] ;
160+ let data = [ [ 10.01 , 2.2 , null , 20.505 , 20.22 , null ] ,
161+ [ 10.01 , null , null , 20.505 , 20 , null ] ] ;
172162
173- let result = [ [ 10.01 , 2.2 , NaN , 20.505 , 20.22 , NaN ] ,
174- [ 10.01 , NaN , NaN , 20.505 , 20 , NaN ] ] ;
163+ let result = [ [ 10.01 , 2.2 , NaN , 20.505 , 20.22 , NaN ] ,
164+ [ 10.01 , NaN , NaN , 20.505 , 20 , NaN ] ] ;
175165 assert . deepEqual ( utils . replaceUndefinedWithNaN ( data , false ) , result ) ;
176166 } ) ;
177167 } ) ;
178168
179169 describe ( "convert2DArrayToSeriesArray" , function ( ) {
180170 it ( "convert 2D array of array to 1D of string values" , function ( ) {
181- let data = [ [ 10.01 , 2.2 , "a" ] , [ 20.505 , 20.22 , "boy" ] ] ;
182- assert . deepEqual ( utils . convert2DArrayToSeriesArray ( data ) , [ "10.01,2.2,a" , "20.505,20.22,boy" ] ) ;
171+ let data = [ [ 10.01 , 2.2 , "a" ] , [ 20.505 , 20.22 , "boy" ] ] ;
172+ assert . deepEqual ( utils . convert2DArrayToSeriesArray ( data ) , [ "10.01,2.2,a" , "20.505,20.22,boy" ] ) ;
183173 } ) ;
184174
185175 } ) ;
186176
187177 describe ( "throwErrorOnWrongParams" , function ( ) {
188178 it ( "check if the right params are passed to a function" , function ( ) {
189- let paramsNeeded = [ "replace" , "with" , "inplace" ] ;
179+ let paramsNeeded = [ "replace" , "with" , "inplace" ] ;
190180 let kwargs = { "replae" : 2 , "with" : 12 , "inplace" : true } ;
191181
192182 assert . throws ( ( ) => {
@@ -195,7 +185,7 @@ describe("Utils", function () {
195185 } ) ;
196186
197187 it ( "check if the right params are passed to a function 2" , function ( ) {
198- let paramsNeeded = [ "replace" , "with" , "inplace" ] ;
188+ let paramsNeeded = [ "replace" , "with" , "inplace" ] ;
199189 let kwargs = { "replace" : 2 , "with" : 12 , "inplace" : true } ;
200190 utils . throwErrorOnWrongParams ( kwargs , paramsNeeded ) ;
201191 } ) ;
@@ -204,22 +194,22 @@ describe("Utils", function () {
204194
205195 describe ( "getRowAndColValues" , function ( ) {
206196 it ( "retreive rows and labels from column object" , function ( ) {
207- let data = { "Alpha" : [ "A" , "B" , "C" , "D" ] , count : [ 1 , 2 , 3 , 4 ] , sum : [ 20.3 , 30.456 , 40.90 , 90.1 ] } ;
208- let res = [ [ "A" , 1 , 20.3 ] , [ "B" , 2 , 30.456 ] , [ "C" , 3 , 40.90 ] , [ "D" , 4 , 90.1 ] ] ;
197+ let data = { "Alpha" : [ "A" , "B" , "C" , "D" ] , count : [ 1 , 2 , 3 , 4 ] , sum : [ 20.3 , 30.456 , 40.90 , 90.1 ] } ;
198+ let res = [ [ "A" , 1 , 20.3 ] , [ "B" , 2 , 30.456 ] , [ "C" , 3 , 40.90 ] , [ "D" , 4 , 90.1 ] ] ;
209199 assert . deepEqual ( utils . getRowAndColValues ( data ) [ 0 ] , res ) ;
210- assert . deepEqual ( utils . getRowAndColValues ( data ) [ 1 ] , [ "Alpha" , "count" , "sum" ] ) ;
200+ assert . deepEqual ( utils . getRowAndColValues ( data ) [ 1 ] , [ "Alpha" , "count" , "sum" ] ) ;
211201 } ) ;
212202
213203 } ) ;
214204
215205
216206 describe ( "getDuplicate" , function ( ) {
217207 it ( "obtain duplicates and their index" , function ( ) {
218- let data = [ 1 , 2 , 3 , 4 , 5 , 3 , 4 , 6 , 4 , 5 ] ;
208+ let data = [ 1 , 2 , 3 , 4 , 5 , 3 , 4 , 6 , 4 , 5 ] ;
219209 let res = {
220- '3' : { count : 2 , index : [ 2 , 5 ] } ,
221- '4' : { count : 3 , index : [ 3 , 6 , 8 ] } ,
222- '5' : { count : 2 , index : [ 4 , 9 ] }
210+ '3' : { count : 2 , index : [ 2 , 5 ] } ,
211+ '4' : { count : 3 , index : [ 3 , 6 , 8 ] } ,
212+ '5' : { count : 2 , index : [ 4 , 9 ] }
223213 } ;
224214 assert . deepEqual ( utils . getDuplicate ( data ) , res ) ;
225215 } ) ;
0 commit comments