/
tablesawTest.js
279 lines (246 loc) · 10.8 KB
/
tablesawTest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
/*
* Copyright 2018 TWO SIGMA OPEN SOURCE, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var BeakerXPageObject = require('../beakerx.po.js');
var PlotHelperObject = require('../plot.helper.js');
var beakerxPO;
describe('Tests for combination of code and magics. ', function () {
beforeAll(function () {
beakerxPO = new BeakerXPageObject();
plotHelper = new PlotHelperObject();
beakerxPO.runNotebookByUrl('/test/ipynb/groovy/TablesawTest.ipynb');
beakerxPO.openUIWindow();
});
afterAll(function () {
beakerxPO.closeAndHaltNotebook();
});
var cellIndex;
var imageDir = 'groovy/tablesaw';
describe('UI options. ', function () {
it("Use new table widget. ", function () {
beakerxPO.setDataGridForTable(true, false);
});
});
describe('Import tablesaw jars. ', function () {
it('Output contains names of jars. ', function () {
cellIndex = 0;
beakerxPO.runCodeCellByIndex(cellIndex);
beakerxPO.waitAndCheckOutputTextOfStdout(cellIndex, /tablesaw-plot/);
beakerxPO.waitAndCheckOutputTextOfStdout(cellIndex, /tablesaw-smile/);
beakerxPO.waitAndCheckOutputTextOfStdout(cellIndex, /tablesaw-beakerx/);
});
});
describe('Call tech.tablesaw.beakerx.TablesawDisplayer.register() method. ', function () {
it('Output displays "null". ', function () {
cellIndex += 1;
beakerxPO.runCodeCellByIndex(cellIndex);
beakerxPO.waitAndCheckOutputTextOfExecuteResult(cellIndex, /null/);
});
});
describe('Call table.read() method. ', function () {
it('Should displays table. ', function () {
var width = 700, height = 100;
cellIndex += 1;
var codeCell = beakerxPO.runCodeCellByIndex(cellIndex);
var canvas = codeCell.$('canvas');
var imageData = beakerxPO.getCanvasImageData(canvas, width, height);
beakerxPO.checkImageData(imageData.value, imageDir, 'cell3_case1.png');
});
});
describe('Call table.structure() method. ', function () {
it('Should displays table structure. ', function () {
var width = 250, height = 200;
cellIndex += 2;
var codeCell = beakerxPO.runCodeCellByIndex(cellIndex);
var canvas = codeCell.$('canvas');
var imageData = beakerxPO.getCanvasImageData(canvas, width, height);
beakerxPO.checkImageData(imageData.value, imageDir, 'cell4_case1.png');
});
});
describe('Call table.columnNames() method. ', function () {
it('Should displays column names. ', function () {
cellIndex += 2;
beakerxPO.runCodeCellByIndex(cellIndex);
beakerxPO.waitAndCheckOutputTextOfExecuteResult(cellIndex,
/Date.*Time.*State.*State No.*Scale.*Injuries.*Fatalities.*Start Lat.*Start Lon.*Length.*Width/);
});
});
describe('Call table.shape() method. ', function () {
it('Should displays the row and column counts. ', function () {
cellIndex += 1;
beakerxPO.runCodeCellByIndex(cellIndex);
beakerxPO.waitAndCheckOutputTextOfExecuteResult(cellIndex, /908 rows.*11 cols/);
});
});
describe('Call table.first(10) method. ', function () {
it('Should displays the first 10 rows. ', function () {
var width = 700, height = 100;
cellIndex += 1;
var codeCell = beakerxPO.runCodeCellByIndex(cellIndex);
var canvas = codeCell.$('canvas');
var imageData = beakerxPO.getCanvasImageData(canvas, width, height);
beakerxPO.checkImageData(imageData.value, imageDir, 'cell7_case1.png');
});
});
describe('Select all columns by "float" type. ', function () {
it('Should display 4 columns. ', function () {
var width = 250, height = 115;
cellIndex += 2;
var codeCell = beakerxPO.runCodeCellByIndex(cellIndex);
var canvas = codeCell.$('canvas');
var imageData = beakerxPO.getCanvasImageData(canvas, width, height);
beakerxPO.checkImageData(imageData.value, imageDir, 'cell8_case1.png');
});
});
describe('Call table.summary() method. ', function () {
it('Should summarize the data in each column. ', function () {
cellIndex += 2;
beakerxPO.runCodeCellByIndex(cellIndex);
beakerxPO.waitAndCheckOutputTextOfExecuteResult(cellIndex, /Table summary for: tornadoes_2014.csv/);
beakerxPO.waitAndCheckOutputTextOfExecuteResult(cellIndex, /Count.*908/);
beakerxPO.waitAndCheckOutputTextOfExecuteResult(cellIndex, /GA.*32 /);
});
});
describe('Mapping operations (add column). ', function () {
it('Should display new column name. ', function () {
cellIndex += 1;
beakerxPO.runCodeCellByIndex(cellIndex);
beakerxPO.waitAndCheckOutputTextOfExecuteResult(cellIndex,
/Date.*Time.*State.*State No.*Scale.*Injuries.*Fatalities.*Start Lat.*Start Lon.*Length.*Width.*Date month/);
});
});
describe('Sorting by column. ', function () {
it('Should sort "Fatalities" column. ', function () {
var width = 700, height = 100;
cellIndex += 1;
var codeCell = beakerxPO.runCodeCellByIndex(cellIndex);
var canvas = codeCell.$('canvas');
var imageData = beakerxPO.getCanvasImageData(canvas, width, height);
beakerxPO.checkImageData(imageData.value, imageDir, 'cell11_case1.png');
});
});
describe('Descriptive statistics. ', function () {
it('Should display summary statistic. ', function () {
var width = 160, height = 210;
cellIndex += 2;
var codeCell = beakerxPO.runCodeCellByIndex(cellIndex);
var canvas = codeCell.$('canvas');
var imageData = beakerxPO.getCanvasImageData(canvas, width, height);
beakerxPO.checkImageData(imageData.value, imageDir, 'cell12_case1.png');
});
});
describe('Performing totals and sub-totals. ', function () {
it('Should display totals and sub-totals. ', function () {
var width = 180, height = 140;
cellIndex += 2;
var codeCell = beakerxPO.runCodeCellByIndex(cellIndex);
var canvas = codeCell.$('canvas');
var imageData = beakerxPO.getCanvasImageData(canvas, width, height);
beakerxPO.checkImageData(imageData.value, imageDir, 'cell13_case1.png');
});
});
describe('Call CrossTab.xCount() method. ', function () {
it('Should display cross tabs. ', function () {
var width = 410, height = 200;
cellIndex += 2;
var codeCell = beakerxPO.runCodeCellByIndex(cellIndex);
var canvas = codeCell.$('canvas');
var imageData = beakerxPO.getCanvasImageData(canvas, width, height);
beakerxPO.checkImageData(imageData.value, imageDir, 'cell14_case1.png');
});
});
describe('K-means clustering. ', function () {
it('Create table from "whiskey.csv" file. ', function () {
var width = 250, height = 200;
cellIndex += 2;
var codeCell = beakerxPO.runCodeCellByIndex(cellIndex);
var canvas = codeCell.$('canvas');
var imageData = beakerxPO.getCanvasImageData(canvas, width, height);
beakerxPO.checkImageData(imageData.value, imageDir, 'cell15_case1.png');
});
it('Print claster formation. ', function () {
var width = 220, height = 200;
cellIndex += 2;
var codeCell = beakerxPO.runCodeCellByIndex(cellIndex);
var canvas = codeCell.$('canvas');
var imageData = beakerxPO.getCanvasImageData(canvas, width, height);
beakerxPO.checkImageData(imageData.value, imageDir, 'cell16_case1.png');
});
it('Print centroids for each claster. ', function () {
var width = 500, height = 100;
cellIndex += 2;
var codeCell = beakerxPO.runCodeCellByIndex(cellIndex);
var canvas = codeCell.$('canvas');
var imageData = beakerxPO.getCanvasImageData(canvas, width, height);
beakerxPO.checkImageData(imageData.value, imageDir, 'cell17_case1.png');
});
it('Gets the distortion for our model. ', function () {
cellIndex += 2;
beakerxPO.runCodeCellByIndex(cellIndex);
beakerxPO.waitAndCheckOutputTextOfExecuteResult(cellIndex, /385.0489177/);
});
it('Should display line Plot. ', function () {
cellIndex += 1;
var svgElement = beakerxPO.runCellToGetSvgElement(cellIndex);
expect(plotHelper.getLineByGIndex(svgElement, 0).getAttribute('d')).not.toBeNull();
});
});
describe('Play (Money)ball with Linear Regression. ', function () {
it('Should display points Plot. ', function () {
cellIndex += 1;
var svgElement = beakerxPO.runCellToGetSvgElement(cellIndex);
expect(plotHelper.getAllPointsByGIndexAndType(svgElement, 0, 'rect').length).toBeGreaterThan(0);
});
it('Print the “winsModel”. ', function () {
cellIndex += 1;
beakerxPO.runCodeCellByIndex(cellIndex);
beakerxPO.waitAndCheckOutputTextOfExecuteResult(cellIndex,
/Residuals:\s*Min\s*1Q\s*Median\s*3Q\s*Max\s*-14.2662\s*-2.6511\s*0.1282\s*2.9365\s*11.6570/);
});
it('Print the “winsModel” for OBP and SLG. ', function () {
cellIndex += 1;
beakerxPO.runCodeCellByIndex(cellIndex);
beakerxPO.waitAndCheckOutputTextOfExecuteResult(cellIndex,
/Residuals:\s*Min\s*1Q\s*Median\s*3Q\s*Max\s*-70.8379\s*-17.1810\s*-1.0917\s*16.7812\s*90.0358/);
});
it('Should display Histogram. ', function () {
cellIndex += 1;
var svgElement = beakerxPO.runCellToGetSvgElement(cellIndex);
expect(plotHelper.getAllGBarRects(svgElement, 0).length).toBeGreaterThan(10);
});
});
describe('Using Quandl and Tablesaw. ', function () {
it('Output contains names of jars. ', function () {
cellIndex += 1;
beakerxPO.runCodeCellByIndex(cellIndex);
beakerxPO.waitAndCheckOutputTextOfStdout(cellIndex, /quandl-core/);
beakerxPO.waitAndCheckOutputTextOfStdout(cellIndex, /quandl-tablesaw/);
});
it('Should display table. ', function () {
var width = 500, height = 100;
cellIndex += 1;
var codeCell = beakerxPO.runCodeCellByIndex(cellIndex);
var canvas = codeCell.$('canvas');
var imageData = beakerxPO.getCanvasImageData(canvas, width, height);
beakerxPO.checkImageData(imageData.value, imageDir, 'cell34_case1.png');
});
it('Should display Plot with stems and line. ', function () {
cellIndex += 2;
var svgElement = beakerxPO.runCellToGetSvgElement(cellIndex);
expect(plotHelper.getLineByGIndex(svgElement, 1).getAttribute('d')).not.toBeNull();
expect(plotHelper.getAllGStemLines(svgElement, 2).length).toBeGreaterThan(10);
});
});
});