source: trip-planner-front/node_modules/hdr-histogram-js/src/RecordedValuesIterator.spec.ts@ 6c1585f

Last change on this file since 6c1585f was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.2 KB
Line 
1import RecordedValuesIterator from "./RecordedValuesIterator";
2import Histogram from "./Int32Histogram";
3
4describe("Recorded Values Iterator", () => {
5 it("should iterate to recorded value", () => {
6 // given
7 const histogram = new Histogram(1, Number.MAX_SAFE_INTEGER, 2);
8 histogram.recordValue(123);
9 const iterator = new RecordedValuesIterator(histogram);
10 // when
11 const iterationValue = iterator.next();
12 // then
13 expect(iterator.hasNext()).toBe(false);
14 expect(iterationValue.totalCountToThisValue).toBe(1);
15 expect(iterationValue.totalValueToThisValue).toBe(123);
16 });
17
18 it("should iterate to all recorded values", () => {
19 // given
20 const histogram = new Histogram(1, Number.MAX_SAFE_INTEGER, 2);
21 histogram.recordValue(1);
22 histogram.recordValue(300);
23 histogram.recordValue(3000);
24 const iterator = new RecordedValuesIterator(histogram);
25 // when
26 const values: number[] = [];
27 while (iterator.hasNext()) {
28 values.push(iterator.next().valueIteratedTo);
29 }
30 // then
31 expect(values).toHaveLength(3);
32 expect(values[0]).toBe(1);
33 expect(values[1]).toBeGreaterThan(300);
34 expect(values[2]).toBeGreaterThan(3000);
35 });
36});
Note: See TracBrowser for help on using the repository browser.