histogram.jest.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. data: [[0, 1], [0, 2], [0, 10], [0, 11], [0, 17], [0, 20], [0, 29]]
  32. }
  33. ];
  34. });
  35. it('Should convert to values array', () => {
  36. let expected = [1, 2, 10, 11, 17, 20, 29];
  37. let values = getSeriesValues(data);
  38. expect(values).toMatchObject(expected);
  39. });
  40. it('Should skip null values', () => {
  41. data[0].data.push([0, null]);
  42. let expected = [1, 2, 10, 11, 17, 20, 29];
  43. let values = getSeriesValues(data);
  44. expect(values).toMatchObject(expected);
  45. });
  46. });
  47. });