source: trip-planner-front/node_modules/hdr-histogram-js/src/HistogramLogWriter.spec.ts@ 571e0df

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

initial commit

  • Property mode set to 100644
File size: 1.8 KB
Line 
1import HistogramLogWriter from "./HistogramLogWriter";
2import Int32Histogram from "./Int32Histogram";
3
4describe("Histogram Log Writer", () => {
5 let buffer: string;
6 let writer: HistogramLogWriter;
7 let histogram: Int32Histogram;
8 beforeEach(() => {
9 buffer = "";
10 writer = new HistogramLogWriter((content) => {
11 buffer += content;
12 });
13 histogram = new Int32Histogram(1, Number.MAX_SAFE_INTEGER, 3);
14 });
15
16 it("should write a line with start time, duration, max value, and a base64 encoded histogram", () => {
17 // given
18 histogram.recordValue(123000);
19 // when
20 writer.outputIntervalHistogram(histogram, 1000, 1042);
21 // then
22 expect(buffer).toMatch(/^1000.000,42.000,123.000,HISTFAA/);
23 });
24
25 it("should write start time, duration and max value using 3 digits", () => {
26 // given
27 histogram.recordValue(123001);
28 // when
29 writer.outputIntervalHistogram(histogram, 1000.0120001, 1042.013001);
30 // then
31 expect(buffer).toMatch(/^1000.012,42.001,123.001,HISTFAA/);
32 });
33
34 it("should write a line starting with histogram tag", () => {
35 // given
36 histogram.tag = "TAG";
37 histogram.recordValue(123000);
38 // when
39 writer.outputIntervalHistogram(histogram, 1000, 1042);
40 // then
41 expect(buffer).toContain("Tag=TAG,1000.000,42.000,123.000,HISTFAA");
42 });
43
44 it("should write a histogram's start time in sec using basetime", () => {
45 // given
46 histogram.startTimeStampMsec = 1234001;
47 histogram.endTimeStampMsec = 1235001;
48 writer.baseTime = 1000000;
49 histogram.recordValue(1);
50 // when
51 writer.outputIntervalHistogram(histogram);
52 // then
53 expect(buffer).toContain("234.001");
54 });
55
56 it("should write start time in seconds", () => {
57 // given
58 // when
59 writer.outputStartTime(1234560);
60 // then
61 expect(buffer).toContain("1234.560");
62 });
63});
Note: See TracBrowser for help on using the repository browser.