histogram_specs.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. ///<reference path="../../../../headers/common.d.ts" />
  2. import { describe, beforeEach, it, expect } from '../../../../../test/lib/common';
  3. import { convertValuesToHistogram, getSeriesValues } from '../histogram';
  4. describe('Graph Histogam Converter', function () {
  5. describe('Values to histogram converter', () => {
  6. let values;
  7. let bucketSize = 10;
  8. beforeEach(() => {
  9. values = [1, 2, 10, 11, 17, 20, 29];
  10. });
  11. it('Should convert to series-like array', () => {
  12. bucketSize = 10;
  13. let expected = [
  14. [0, 2], [10, 3], [20, 2]
  15. ];
  16. let histogram = convertValuesToHistogram(values, bucketSize);
  17. expect(histogram).to.eql(expected);
  18. });
  19. it('Should not add empty buckets', () => {
  20. bucketSize = 5;
  21. let expected = [
  22. [0, 2], [10, 2], [15, 1], [20, 1], [25, 1]
  23. ];
  24. let histogram = convertValuesToHistogram(values, bucketSize);
  25. expect(histogram).to.eql(expected);
  26. });
  27. });
  28. describe('Series to values converter', () => {
  29. let data;
  30. beforeEach(() => {
  31. data = [
  32. {
  33. data: [[0, 1], [0, 2], [0, 10], [0, 11], [0, 17], [0, 20], [0, 29]]
  34. }
  35. ];
  36. });
  37. it('Should convert to values array', () => {
  38. let expected = [1, 2, 10, 11, 17, 20, 29];
  39. let values = getSeriesValues(data);
  40. expect(values).to.eql(expected);
  41. });
  42. it('Should skip null values', () => {
  43. data[0].data.push([0, null]);
  44. let expected = [1, 2, 10, 11, 17, 20, 29];
  45. let values = getSeriesValues(data);
  46. expect(values).to.eql(expected);
  47. });
  48. });
  49. });