Skip to content

Commit 4a0453e

Browse files
add in code for part 3
function to calc totals for won, lost, NR, points
1 parent 6576bd5 commit 4a0453e

2 files changed

Lines changed: 184 additions & 0 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { calcCompletedMatches } from "../helpers/calcCompletedMatches";
2+
import { cricketTeamTotalCalc } from "../points-table/cricketTeamTotalCalc";
3+
import { matches } from "../data/matches";
4+
import {
5+
WON,
6+
LOST,
7+
NORESULT,
8+
POINTS
9+
} from "../helpers/constants";
10+
11+
const config = { pts4Win: 2, pts4NR: 1 };
12+
13+
it("cricketTeamTotalCalc", () => {
14+
expect(
15+
cricketTeamTotalCalc({
16+
config,
17+
matches,
18+
team: "SA",
19+
stat: WON
20+
})
21+
).toBe(3);
22+
expect(
23+
cricketTeamTotalCalc({
24+
config,
25+
matches,
26+
team: "SA",
27+
stat: LOST
28+
})
29+
).toBe(5);
30+
expect(
31+
cricketTeamTotalCalc({
32+
config,
33+
matches,
34+
team: "SA",
35+
stat: NORESULT
36+
})
37+
).toBe(1);
38+
39+
expect(
40+
cricketTeamTotalCalc({
41+
config,
42+
matches,
43+
team: "SA",
44+
stat: POINTS
45+
})
46+
).toBe(7);
47+
});
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
import {
2+
WON,
3+
LOST,
4+
TEAM1,
5+
TEAM2,
6+
NORESULT,
7+
POINTS
8+
} from "../helpers/constants";
9+
import { teamWon } from "./teamWon";
10+
import { teamWonSuperOver } from "./teamWonSuperOver";
11+
12+
import { teamLost } from "./teamLost";
13+
import { teamLostSuperOver } from "./teamLostSuperOver";
14+
15+
import { teamNoResult } from "./teamNoResult";
16+
17+
export const cricketTeamTotalCalc = ({
18+
config,
19+
matches,
20+
team,
21+
stat
22+
}) => {
23+
const { pts4Win, pts4NR } = config;
24+
// need to look at what is getting passed in here
25+
switch (stat) {
26+
case WON:
27+
return (
28+
teamWon({
29+
matches,
30+
teamNum: TEAM1,
31+
team,
32+
stat: "Ru"
33+
}) +
34+
teamWon({
35+
matches,
36+
teamNum: TEAM2,
37+
team,
38+
stat: "Ru"
39+
}) +
40+
teamWonSuperOver({
41+
matches,
42+
teamNum: TEAM1,
43+
team,
44+
stat: "SupOvrR"
45+
}) +
46+
teamWonSuperOver({
47+
matches,
48+
teamNum: TEAM2,
49+
team,
50+
stat: "SupOvrR"
51+
})
52+
);
53+
case LOST:
54+
return (
55+
teamLost({
56+
matches,
57+
teamNum: TEAM1,
58+
team,
59+
stat: "Ru"
60+
}) +
61+
teamLost({
62+
matches,
63+
teamNum: TEAM2,
64+
team,
65+
stat: "Ru"
66+
}) +
67+
teamLostSuperOver({
68+
matches,
69+
teamNum: TEAM1,
70+
team,
71+
stat: "SupOvrR"
72+
}) +
73+
teamLostSuperOver({
74+
matches,
75+
teamNum: TEAM2,
76+
team,
77+
stat: "SupOvrR"
78+
})
79+
);
80+
case NORESULT:
81+
return (
82+
teamNoResult({
83+
matches,
84+
teamNum: TEAM1,
85+
team
86+
}) +
87+
teamNoResult({
88+
matches,
89+
teamNum: TEAM2,
90+
team
91+
})
92+
);
93+
case POINTS:
94+
return (
95+
(teamWon({
96+
matches,
97+
teamNum: TEAM1,
98+
team,
99+
stat: "Ru"
100+
}) +
101+
teamWon({
102+
matches,
103+
teamNum: TEAM2,
104+
team,
105+
stat: "Ru"
106+
}) +
107+
teamWonSuperOver({
108+
matches,
109+
teamNum: TEAM1,
110+
team,
111+
stat: "SupOvrR"
112+
}) +
113+
teamWonSuperOver({
114+
matches,
115+
teamNum: TEAM2,
116+
team,
117+
stat: "SupOvrR"
118+
})) *
119+
pts4Win +
120+
+(
121+
teamNoResult({
122+
matches,
123+
teamNum: TEAM1,
124+
team
125+
}) +
126+
teamNoResult({
127+
matches,
128+
teamNum: TEAM2,
129+
team
130+
})
131+
) *
132+
pts4NR
133+
);
134+
default:
135+
return;
136+
}
137+
};

0 commit comments

Comments
 (0)