histogram.jest.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { convertValuesToHistogram, getSeriesValues } from '../histogram';
  2. describe('Graph Histogam Converter', function () {
  3. describe('Values to histogram converter', () => {
  4. let values;
  5. let bucketSize = 10;
  6. beforeEach(() => {
  7. values = [1, 2, 10, 11, 17, 20, 29];
  8. });
  9. it('Should convert to series-like array', () => {
  10. bucketSize = 10;
  11. let expected = [
  12. [0, 2], [10, 3], [20, 2]
  13. ];
  14. let histogram = convertValuesToHistogram(values, bucketSize);
  15. expect(histogram).toMatchObject(expected);
  16. });
  17. it('Should not add empty buckets', () => {
  18. bucketSize = 5;
  19. let expected = [
  20. [0, 2], [10, 2], [15, 1], [20, 1], [25, 1]
  21. ];
  22. let histogram = convertValuesToHistogram(values, bucketSize);
  23. expect(histogram).toMatchObject(expected);
  24. });
  25. });
  26. describe('Series to values converter', () => {
  27. let data;
  28. beforeEach(() => {
  29. data = [
  30. {
  31. datapoints: [
  32. [1, 0], [2, 0], [10, 0], [11, 0], [17, 0], [20, 0], [29, 0]
  33. ]
  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).toMatchObject(expected);
  41. });
  42. it('Should skip null values', () => {
  43. data[0].datapoints.push([null, 0]);
  44. let expected = [1, 2, 10, 11, 17, 20, 29];
  45. let values = getSeriesValues(data);
  46. expect(values).toMatchObject(expected);
  47. });
  48. });
  49. });