1 | import RecordedValuesIterator from "./RecordedValuesIterator";
|
---|
2 | import Histogram from "./Int32Histogram";
|
---|
3 |
|
---|
4 | describe("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 | });
|
---|