Skip to content

Commit 85ee67d

Browse files
committed
Update tests to work in browser
1 parent 95ec8af commit 85ee67d

15 files changed

Lines changed: 806 additions & 876 deletions

File tree

danfojs/tests/config/config.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
import { Configs } from '../../src/config/config';
2-
import { assert } from 'chai';
3-
4-
const config = new Configs();
5-
1+
/* eslint-disable no-undef */
2+
const config = new dfd.Configs();
63

74
describe("Config", function () {
85
it("gets the default config val for table width", function () {

danfojs/tests/core/concat.js

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
1-
import { assert } from "chai";
2-
import { DataFrame } from '../../src/core/frame';
3-
import { concat } from '../../src/core/concat';
4-
import { Series } from "../../src/core/series";
5-
61

72
describe("Concatenate", function () {
83

94
it("Check the axis 0 concatenation", function () {
105
let data = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 20, 30, 40 ], [ 39, 89, 78 ] ];
116
let cols = [ "A", "B", "C" ];
12-
let df = new DataFrame(data, { columns: cols });
7+
let df = new dfd.DataFrame(data, { columns: cols });
138

149
let data1 = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 20, 30, 40 ], [ 39, 89, 78 ] ];
1510
let cols1 = [ "A", "B", "C" ];
16-
let df1 = new DataFrame(data1, { columns: cols1 });
11+
let df1 = new dfd.DataFrame(data1, { columns: cols1 });
1712

1813
let data2 = [ [ 1, 2, 3, 5 ], [ 4, 5, 6, 8 ], [ 20, 30, 40, 10 ] ];
1914
let cols2 = [ "A", "B", "C", "D" ];
20-
let df2 = new DataFrame(data2, { columns: cols2 });
15+
let df2 = new dfd.DataFrame(data2, { columns: cols2 });
2116

22-
let new_df = concat({ "df_list": [ df, df1, df2 ], "axis": 0 });
17+
let new_df = dfd.concat({ "df_list": [ df, df1, df2 ], "axis": 0 });
2318

2419
let data_values = [ [ 1, 2, 3, NaN ], [ 4, 5, 6, NaN ], [ 20, 30, 40, NaN ], [ 39, 89, 78, NaN ],
2520
[ 1, 2, 3, NaN ], [ 4, 5, 6, NaN ], [ 20, 30, 40, NaN ], [ 39, 89, 78, NaN ],
@@ -31,35 +26,35 @@ describe("Concatenate", function () {
3126
it("Check the axis 1 concatenation", function () {
3227
let data = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 20, 30, 40 ], [ 39, 89, 78 ] ];
3328
let cols = [ "A", "B", "C" ];
34-
let df = new DataFrame(data, { columns: cols });
29+
let df = new dfd.DataFrame(data, { columns: cols });
3530

3631
let data1 = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 20, 30, 40 ], [ 39, 89, 78 ] ];
3732
let cols1 = [ "A", "B", "C" ];
38-
let df1 = new DataFrame(data1, { columns: cols1 });
33+
let df1 = new dfd.DataFrame(data1, { columns: cols1 });
3934

4035
let data2 = [ [ 1, 2, 3, 5 ], [ 4, 5, 6, 8 ], [ 20, 30, 40, 10 ] ];
4136
let cols2 = [ "A", "B", "C", "D" ];
42-
let df2 = new DataFrame(data2, { columns: cols2 });
37+
let df2 = new dfd.DataFrame(data2, { columns: cols2 });
4338

44-
let new_df = concat({ "df_list": [ df, df1, df2 ], "axis": 1 });
39+
let new_df = dfd.concat({ "df_list": [ df, df1, df2 ], "axis": 1 });
4540

4641
let data_values = [ [ 1, 2, 3, 1, 2, 3, 1, 2, 3, 5 ], [ 4, 5, 6, 4, 5, 6, 4, 5, 6, 8 ],
4742
[ 20, 30, 40, 20, 30, 40, 20, 30, 40, 10 ], [ 39, 89, 78, 39, 89, 78, NaN,
4843
NaN, NaN, NaN ] ];
4944
assert.deepEqual(new_df.values, data_values);
5045
});
5146

52-
it("concatenate dataframe and series along 0 axis", function(){
47+
it("concatenate dfd.dataframe and series along 0 axis", function(){
5348

5449
let data1 = [ 1, 2, 3, 4 ];
5550
let data2 = [ 3, 4, 5, 6 ];
5651

5752
let data = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 20, 30, 40 ], [ 39, 89, 78 ] ];
5853
let cols = [ "A", "B", "C" ];
59-
let df = new DataFrame(data, { columns: cols });
54+
let df = new dfd.DataFrame(data, { columns: cols });
6055

61-
let s1 = new Series(data1);
62-
let s2 = new Series(data2);
56+
let s1 = new dfd.Series(data1);
57+
let s2 = new dfd.Series(data2);
6358
let rslt = [
6459
[ 1, 2, 3, NaN ],
6560
[ 4, 5, 6, NaN ],
@@ -72,20 +67,20 @@ describe("Concatenate", function () {
7267
];
7368

7469

75-
let con = concat({ "df_list": [ df, s1 ], "axis": 0 });
70+
let con = dfd.concat({ "df_list": [ df, s1 ], "axis": 0 });
7671

7772
assert.deepEqual(con.values, rslt);
7873

7974
});
8075

81-
it("concatenate dataframe and series along axis 1", function(){
76+
it("concatenate dfd.dataframe and series along axis 1", function(){
8277

8378
let data = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 20, 30, 40 ], [ 39, 89, 78 ] ];
8479
let cols = [ "A", "B", "C" ];
85-
let df = new DataFrame(data, { columns: cols });
80+
let df = new dfd.DataFrame(data, { columns: cols });
8681

8782
let data1 = [ 1, 2, 3, 4 ];
88-
let s1 = new Series(data1);
83+
let s1 = new dfd.Series(data1);
8984
let rslt = [
9085
[ 1, 2, 3, 1 ],
9186
[ 4, 5, 6, 2 ],
@@ -94,7 +89,7 @@ describe("Concatenate", function () {
9489
];
9590

9691

97-
let con = concat({ "df_list": [ df, s1 ], "axis": 1 });
92+
let con = dfd.concat({ "df_list": [ df, s1 ], "axis": 1 });
9893

9994
assert.deepEqual(con.values, rslt);
10095

@@ -104,12 +99,12 @@ describe("Concatenate", function () {
10499
let data1 = [ 1, 2, 3, 4 ];
105100
let data2 = [ 3, 4, 5, 6 ];
106101

107-
let s1 = new Series(data1);
108-
let s2 = new Series(data2);
102+
let s1 = new dfd.Series(data1);
103+
let s2 = new dfd.Series(data2);
109104
let rslt = [ [ 1, 3 ], [ 2, 4 ], [ 3, 5 ], [ 4, 6 ] ];
110105

111106

112-
let con = concat({ "df_list": [ s1, s2 ], "axis": 1 });
107+
let con = dfd.concat({ "df_list": [ s1, s2 ], "axis": 1 });
113108

114109
assert.deepEqual(con.values, rslt);
115110

@@ -119,45 +114,45 @@ describe("Concatenate", function () {
119114
let data1 = [ 1, 2, 3, 4 ];
120115
let data2 = [ 3, 4, 5, 6 ];
121116

122-
let s1 = new Series(data1);
123-
let s2 = new Series(data2);
117+
let s1 = new dfd.Series(data1);
118+
let s2 = new dfd.Series(data2);
124119
let rslt = [
125120
1, 2, 3, 4,
126121
3, 4, 5, 6
127122
];
128123

129-
let con = concat({ "df_list": [ s1, s2 ], "axis": 0 });
124+
let con = dfd.concat({ "df_list": [ s1, s2 ], "axis": 0 });
130125

131126
assert.deepEqual(con.values, rslt);
132127

133128
});
134129

135130
it("test if df_list is an array", function(){
136131

137-
assert.throws(function () { concat({ "df_list":23, "axis":0 }); }, Error, 'df_list must be an Array of dataFrames/Series');
132+
assert.throws(function () { dfd.concat({ "df_list":23, "axis":0 }); }, Error, 'df_list must be an Array of dataFrames/Series');
138133

139134
});
140135
it("assign default axis for concating", function(){
141136
let data1 = [ 1, 2, 3, 4 ];
142137
let data2 = [ 3, 4, 5, 6 ];
143138

144-
let s1 = new Series(data1);
145-
let s2 = new Series(data2);
139+
let s1 = new dfd.Series(data1);
140+
let s2 = new dfd.Series(data2);
146141
let rslt = [ [ 1, 3 ], [ 2, 4 ], [ 3, 5 ], [ 4, 6 ] ];
147142

148143

149-
let con = concat({ "df_list": [ s1, s2 ], "axis": 12 });
144+
let con = dfd.concat({ "df_list": [ s1, s2 ], "axis": 12 });
150145

151146
assert.deepEqual(con.values, rslt);
152147
});
153148
it("ensure axis is a number", function(){
154149
let data1 = [ 1, 2, 3, 4 ];
155150
let data2 = [ 3, 4, 5, 6 ];
156151

157-
let s1 = new Series(data1);
158-
let s2 = new Series(data2);
152+
let s1 = new dfd.Series(data1);
153+
let s2 = new dfd.Series(data2);
159154

160-
assert.throws(function () { concat({ "df_list":[ s1, s2 ], "axis":"r" }); }, Error, 'axis must be a number');
155+
assert.throws(function () { dfd.concat({ "df_list":[ s1, s2 ], "axis":"r" }); }, Error, 'axis must be a number');
161156
});
162157

163158
});

danfojs/tests/core/date_range.js

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,10 @@
1-
import { assert } from "chai";
2-
import { date_range } from '../../src/core/date_range';
3-
// import {Utils} from '../../src/core/utils'
4-
5-
// const utils = new Utils
61

72
describe("date_range", function(){
83

9-
// it("Obtain date between start and end specified", function(){
10-
11-
// let d = new date_range({"start":'2018-04-24',"end":'2018-04-27'})
12-
// let rslt = [
13-
// '4/24/2018, 12:00:00 AM',
14-
// '4/25/2018, 12:00:00 AM',
15-
// '4/26/2018, 12:00:00 AM',
16-
// '4/27/2018, 12:00:00 AM'
17-
// ]
18-
19-
// assert.deepEqual(d,rslt)
20-
21-
22-
// });
234
it("Obtain date between start with end not specified, but period and freq specified", function(){
245

256

26-
let d = new date_range({ "start":'1/1/2018', period:5, freq:'M' });
7+
let d = new dfd.date_range({ "start":'1/1/2018', period:5, freq:'M' });
278
let rslt = [
289
'1/1/2018, 12:00:00 AM',
2910
'2/1/2018, 12:00:00 AM',
@@ -38,7 +19,7 @@ describe("date_range", function(){
3819
});
3920
it("Obtain date between start with end not specified, but period and freq specified, plus offset", function(){
4021

41-
let d = new date_range({ start:'1/1/2018', period:5, freq:'3M' });
22+
let d = new dfd.date_range({ start:'1/1/2018', period:5, freq:'3M' });
4223
let rslt = [
4324
'1/1/2018, 12:00:00 AM',
4425
'4/1/2018, 12:00:00 AM',
@@ -53,7 +34,7 @@ describe("date_range", function(){
5334
});
5435
it("Obtain date range with start not specified but end and period is given", function(){
5536

56-
let d = new date_range({ end:'1/1/2018', period:8 });
37+
let d = new dfd.date_range({ end:'1/1/2018', period:8 });
5738
let rslt = [
5839
'12/25/2017, 12:00:00 AM',
5940
'12/26/2017, 12:00:00 AM',
@@ -70,9 +51,9 @@ describe("date_range", function(){
7051

7152
});
7253
it("inputing wrong freq", function(){
73-
assert.throws(function () { new date_range({ end:'1/1/2018', period:8, freq:"d" }); }, Error, 'invalid freq d');
54+
assert.throws(function () { new dfd.date_range({ end:'1/1/2018', period:8, freq:"d" }); }, Error, 'invalid freq d');
7455
});
7556
it("inputing wrong freq with offset", function(){
76-
assert.throws(function () { new date_range({ end:'1/1/2018', period:8, freq:"4d" }); }, Error, 'invalid freq d');
57+
assert.throws(function () { new dfd.date_range({ end:'1/1/2018', period:8, freq:"4d" }); }, Error, 'invalid freq d');
7758
});
7859
});

0 commit comments

Comments
 (0)