source: trip-planner-front/node_modules/hdr-histogram-js/assembly/__tests__/formatters.spec.ts@ 8d391a1

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

initial commit

  • Property mode set to 100644
File size: 2.3 KB
Line 
1/*
2 * This is a AssemblyScript port of the original Java version, which was written by
3 * Gil Tene as described in
4 * https://github.com/HdrHistogram/HdrHistogram
5 * and released to the public domain, as explained at
6 * http://creativecommons.org/publicdomain/zero/1.0/
7 */
8
9import { FloatFormatter, IntegerFormatter } from "../formatters";
10
11describe("Integer formatter", () => {
12 it("should format integer as a string", () => {
13 // given
14 const formatter = new IntegerFormatter(3);
15 // when
16 const result = formatter.format(123);
17 // then
18 expect(result).toBe("123");
19 });
20
21 it("should add padding on the left when input has a few digits", () => {
22 // given
23 const formatter = new IntegerFormatter(5);
24 // when
25 const result = formatter.format(123);
26 // then
27 expect(result).toBe(" 123");
28 });
29});
30
31describe("Float formatter", () => {
32 it("should format float as a string", () => {
33 // given
34 const formatter = new FloatFormatter(5, 2);
35 // when
36 const result = formatter.format(12.34);
37 // then
38 expect(result).toBe("12.34");
39 });
40
41 it("should format float as a string with given number of fraction digits", () => {
42 // given
43 const formatter = new FloatFormatter(5, 2);
44 // when
45 const result = formatter.format(12.347);
46 // then
47 expect(result).toBe("12.35");
48 });
49
50 it("should format float as a string with given number of fraction digits (bis)", () => {
51 // given
52 const formatter = new FloatFormatter(12, 3);
53 // when
54 const result = formatter.format(50);
55 // then
56 expect(result).toBe(" 50.000");
57 });
58
59 it("should format float as a string adding fraction digits", () => {
60 // given
61 const formatter = new FloatFormatter(5, 2);
62 // when
63 const result = formatter.format(12.3);
64 // then
65 expect(result).toBe("12.30");
66 });
67
68 it("should format the whole float input even with lots of digits", () => {
69 // given
70 const formatter = new FloatFormatter(5, 2);
71 // when
72 const result = formatter.format(12456789.34);
73 // then
74 expect(result).toBe("12456789.34");
75 });
76
77 it("should add padding on the left when not enough digits", () => {
78 // given
79 const formatter = new FloatFormatter(5, 2);
80 // when
81 const result = formatter.format(9.34);
82 // then
83 expect(result).toBe(" 9.34");
84 });
85});
Note: See TracBrowser for help on using the repository browser.