|
@@ -1,6 +1,7 @@
|
|
|
///<reference path="../../../../headers/common.d.ts" />
|
|
///<reference path="../../../../headers/common.d.ts" />
|
|
|
-import _ from 'lodash';
|
|
|
|
|
|
|
+
|
|
|
import { describe, beforeEach, it, expect } from '../../../../../test/lib/common';
|
|
import { describe, beforeEach, it, expect } from '../../../../../test/lib/common';
|
|
|
|
|
+
|
|
|
import { convertValuesToHistogram, getSeriesValues } from '../histogram';
|
|
import { convertValuesToHistogram, getSeriesValues } from '../histogram';
|
|
|
|
|
|
|
|
describe('Graph Histogam Converter', function () {
|
|
describe('Graph Histogam Converter', function () {
|
|
@@ -10,13 +11,13 @@ describe('Graph Histogam Converter', function () {
|
|
|
let bucketSize = 10;
|
|
let bucketSize = 10;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
beforeEach(() => {
|
|
|
- values = [1, 2, 10, 11, 17, 20, 29, 30, 31, 33];
|
|
|
|
|
|
|
+ values = [1, 2, 10, 11, 17, 20, 29];
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('Should convert to series-like array', () => {
|
|
it('Should convert to series-like array', () => {
|
|
|
bucketSize = 10;
|
|
bucketSize = 10;
|
|
|
let expected = [
|
|
let expected = [
|
|
|
- [0, 2], [10, 3], [20, 2], [30, 3]
|
|
|
|
|
|
|
+ [0, 2], [10, 3], [20, 2]
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
let histogram = convertValuesToHistogram(values, bucketSize);
|
|
let histogram = convertValuesToHistogram(values, bucketSize);
|
|
@@ -26,35 +27,12 @@ describe('Graph Histogam Converter', function () {
|
|
|
it('Should not add empty buckets', () => {
|
|
it('Should not add empty buckets', () => {
|
|
|
bucketSize = 5;
|
|
bucketSize = 5;
|
|
|
let expected = [
|
|
let expected = [
|
|
|
- [0, 2], [10, 2], [15, 1], [20, 1], [25, 1], [30, 3]
|
|
|
|
|
|
|
+ [0, 2], [10, 2], [15, 1], [20, 1], [25, 1]
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
let histogram = convertValuesToHistogram(values, bucketSize);
|
|
let histogram = convertValuesToHistogram(values, bucketSize);
|
|
|
expect(histogram).to.eql(expected);
|
|
expect(histogram).to.eql(expected);
|
|
|
});
|
|
});
|
|
|
-
|
|
|
|
|
- it('Should normalize values', () => {
|
|
|
|
|
- bucketSize = 5;
|
|
|
|
|
- let normalize = true;
|
|
|
|
|
- let expected = [
|
|
|
|
|
- [0, 0.2], [10, 0.2], [15, 0.1], [20, 0.1], [25, 0.1], [30, 0.3]
|
|
|
|
|
- ];
|
|
|
|
|
-
|
|
|
|
|
- let histogram = convertValuesToHistogram(values, bucketSize, normalize);
|
|
|
|
|
- expect(histogram).to.eql(expected);
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- it('Sum of normalized values should be 1', () => {
|
|
|
|
|
- bucketSize = 5;
|
|
|
|
|
- let normalize = true;
|
|
|
|
|
- let expected = [
|
|
|
|
|
- [0, 0.2], [10, 0.2], [15, 0.1], [20, 0.1], [25, 0.1], [30, 0.3]
|
|
|
|
|
- ];
|
|
|
|
|
-
|
|
|
|
|
- let histogram = convertValuesToHistogram(values, bucketSize, normalize);
|
|
|
|
|
- let sum = _.reduce(histogram, (sum, point) => sum + point[1], 0);
|
|
|
|
|
- expect(sum).to.eql(1);
|
|
|
|
|
- });
|
|
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
describe('Series to values converter', () => {
|
|
describe('Series to values converter', () => {
|