Commit 7c78e8e3 by Alexander Zobnin

heatmap: add few tests for histogram converter

parent 26ddb997
...@@ -4,7 +4,7 @@ import TimeSeries from 'app/core/time_series2'; ...@@ -4,7 +4,7 @@ import TimeSeries from 'app/core/time_series2';
import { import {
convertToHeatMap, convertToHeatMap,
convertToCards, convertToCards,
elasticHistogramToHeatmap, histogramToHeatmap,
calculateBucketSize, calculateBucketSize,
isHeatmapDataEqual, isHeatmapDataEqual,
} from '../heatmap_data_converter'; } from '../heatmap_data_converter';
...@@ -216,7 +216,7 @@ describe('HeatmapDataConverter', () => { ...@@ -216,7 +216,7 @@ describe('HeatmapDataConverter', () => {
}); });
}); });
describe('ES Histogram converter', () => { describe('Histogram converter', () => {
let ctx: any = {}; let ctx: any = {};
beforeEach(() => { beforeEach(() => {
...@@ -244,7 +244,7 @@ describe('ES Histogram converter', () => { ...@@ -244,7 +244,7 @@ describe('ES Histogram converter', () => {
); );
}); });
describe('when converting ES histogram', () => { describe('when converting histogram', () => {
beforeEach(() => {}); beforeEach(() => {});
it('should build proper heatmap data', () => { it('should build proper heatmap data', () => {
...@@ -252,60 +252,72 @@ describe('ES Histogram converter', () => { ...@@ -252,60 +252,72 @@ describe('ES Histogram converter', () => {
'1422774000000': { '1422774000000': {
x: 1422774000000, x: 1422774000000,
buckets: { buckets: {
'1': { '0': {
y: 1, y: 0,
count: 1, count: 1,
bounds: { bottom: 0, top: null },
values: [], values: [],
points: [], points: [],
bounds: { bottom: 1, top: null },
}, },
'2': { '1': {
y: 2, y: 1,
count: 5, count: 5,
bounds: { bottom: 1, top: null },
values: [], values: [],
points: [], points: [],
bounds: { bottom: 2, top: null },
}, },
'3': { '2': {
y: 3, y: 2,
count: 0, count: 0,
bounds: { bottom: 2, top: null },
values: [], values: [],
points: [], points: [],
bounds: { bottom: 3, top: null },
}, },
}, },
}, },
'1422774060000': { '1422774060000': {
x: 1422774060000, x: 1422774060000,
buckets: { buckets: {
'1': { '0': {
y: 1, y: 0,
count: 0, count: 0,
bounds: { bottom: 0, top: null },
values: [], values: [],
points: [], points: [],
bounds: { bottom: 1, top: null },
}, },
'2': { '1': {
y: 2, y: 1,
count: 3, count: 3,
bounds: { bottom: 1, top: null },
values: [], values: [],
points: [], points: [],
bounds: { bottom: 2, top: null },
}, },
'3': { '2': {
y: 3, y: 2,
count: 1, count: 1,
bounds: { bottom: 2, top: null },
values: [], values: [],
points: [], points: [],
bounds: { bottom: 3, top: null },
}, },
}, },
}, },
}; };
let heatmap = elasticHistogramToHeatmap(ctx.series); const heatmap = histogramToHeatmap(ctx.series);
expect(heatmap).toEqual(expectedHeatmap); expect(heatmap).toEqual(expectedHeatmap);
}); });
it('should use bucket index as a bound', () => {
const heatmap = histogramToHeatmap(ctx.series);
const bucketLabels = _.map(heatmap['1422774000000'].buckets, (b, label) => label);
const bucketYs = _.map(heatmap['1422774000000'].buckets, 'y');
const bucketBottoms = _.map(heatmap['1422774000000'].buckets, b => b.bounds.bottom);
const expectedBounds = [0, 1, 2];
expect(bucketLabels).toEqual(_.map(expectedBounds, b => b.toString()));
expect(bucketYs).toEqual(expectedBounds);
expect(bucketBottoms).toEqual(expectedBounds);
});
}); });
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment