-
Notifications
You must be signed in to change notification settings - Fork 0
/
splitter.test.js
92 lines (78 loc) · 1.85 KB
/
splitter.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
const splitter = require("./splitter")
test("split 1", () => {
const commands = [
{ names: ["boat"], prices: ["1000"] },
{ names: ["bird"], prices: ["3000"] }
]
expect(splitter.process(commands)).toEqual({
boat: 1000,
bird: 3000
})
})
test("split 2", () => {
const commands = [
{ names: ["boat"], prices: ["1000", "2000"] },
{ names: ["bird"], prices: ["3000", "4000"] },
{ names: ["boat"], prices: ["1000"] }
]
expect(splitter.process(commands)).toEqual({
boat: 4000,
bird: 7000
})
})
test("split 3", () => {
const commands = [
{ names: ["a", "b"], prices: ["1000"] },
{ names: ["c", "d", "e"], prices: ["2000", "3000", "4000"] }
]
expect(splitter.process(commands)).toEqual({
a: 500,
b: 500,
c: 3000,
d: 3000,
e: 3000
})
})
test("split 4", () => {
const commands = [
{ names: ["a", "b"], prices: ["100+200"] },
{ names: ["c"], prices: ["10+2", "20-10", "100/2", "500*3"] }
]
expect(splitter.process(commands)).toEqual({
a: 150,
b: 150,
c: 1572
})
})
test("split 5", () => {
const commands = [
{ names: [], prices: ["1000", "2000"] },
{ names: ["a", "b", "c"], prices: [] }
]
expect(splitter.process(commands)).toEqual({
a: 1000,
b: 1000,
c: 1000
})
})
test("split 6", () => {
const commands = [{ names: ["a"], prices: ["1000/0", "100"] }]
expect(splitter.process(commands)).toEqual({
a: 100
})
})
test("scenario 1", () => {
const commands = [
{ names: ["boat"], prices: ["100", "1000/4"] },
{ names: ["louis"], prices: ["300", "1000/4"] },
{ names: ["prun"], prices: ["200", "1000/4"] },
{ names: ["tung"], prices: ["500", "1000/4"] },
{ names: [], prices: ["+10%", "+7%"] }
]
expect(splitter.process(commands)).toEqual({
boat: 411.95,
louis: 647.35,
prun: 529.65,
tung: 882.75
})
})