Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 74ba473

Browse filesBrowse files
committed
add geomean test
1 parent 20c2b0f commit 74ba473
Copy full SHA for 74ba473

File tree

2 files changed

+35
-0
lines changed
Filter options

2 files changed

+35
-0
lines changed

‎test/jasmine/tests/calcdata_test.js

Copy file name to clipboardExpand all lines: test/jasmine/tests/calcdata_test.js
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,23 @@ describe('calculated data and points', function() {
11541154
checkAggregatedValue(baseMock, expectedAgg, false, done);
11551155
});
11561156

1157+
it('takes the geomean of all values per category across traces of type ' + trace.type, function(done) {
1158+
var type = trace.type;
1159+
var data = [7, 2, 3];
1160+
var data2 = [5, 4, 2];
1161+
var baseMock = { data: [makeData(type, axName, cat, data), makeData(type, axName, cat, data2)], layout: {}};
1162+
baseMock.layout[axName] = { type: 'category', categoryorder: 'geomean ascending'};
1163+
1164+
var expectedAgg = [['a', Math.sqrt(data[0] * data2[0])], ['b', Math.sqrt(data[1] * data2[1])], ['c', Math.sqrt(data[2] * data2[2])]];
1165+
// TODO: how to actually calc these? what do these even mean?
1166+
if(type === 'histogram') expectedAgg = [['a', 2], ['b', 1], ['c', 1]];
1167+
if(type === 'histogram2d') expectedAgg = [['a', 2 / 3], ['b', 1 / 3], ['c', 1 / 3]];
1168+
if(type === 'contour' || type === 'heatmap') expectedAgg = [['a', expectedAgg[0][1] / 3], ['b', expectedAgg[1][1] / 3], ['c', expectedAgg[2][1] / 3]];
1169+
if(type === 'histogram2dcontour') expectedAgg = [['a', 2 / 4], ['b', 1 / 4], ['c', 1 / 4]];
1170+
1171+
checkAggregatedValue(baseMock, expectedAgg, false, done);
1172+
});
1173+
11571174
it('takes the median of all values per category across traces of type ' + trace.type, function(done) {
11581175
var type = trace.type;
11591176
var data = [7, 2, 3];

‎test/jasmine/tests/lib_test.js

Copy file name to clipboardExpand all lines: test/jasmine/tests/lib_test.js
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,24 @@ describe('Test lib.js:', function() {
126126
});
127127
});
128128

129+
describe('geomean() should', function() {
130+
it('toss out non-numerics (strings)', function() {
131+
var input = [1, 2, 'apple', 'orange'];
132+
var res = Lib.geomean(input);
133+
expect(res).toBeCloseTo(1.414, 3);
134+
});
135+
it('toss out non-numerics (NaN)', function() {
136+
var input = [1, 2, NaN];
137+
var res = Lib.geomean(input);
138+
expect(res).toBeCloseTo(1.414, 3);
139+
});
140+
it('evaluate numbers which are passed around as text strings:', function() {
141+
var input = ['1', '2'];
142+
var res = Lib.geomean(input);
143+
expect(res).toBeCloseTo(1.414, 3);
144+
});
145+
});
146+
129147
describe('midRange() should', function() {
130148
it('should calculate the arithmetic mean of the maximum and minimum value of a given array', function() {
131149
var input = [1, 5.5, 6, 15, 10, 13];

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.