Skip to content
Permalink
Browse files

add in code for part 3

function to calc totals for won, lost, NR, points
  • Loading branch information
afewminutesofcode committed Aug 26, 2019
1 parent 6576bd5 commit 4a0453e7368ad22b7ddacc463f5a3628ed0506e4
Showing with 184 additions and 0 deletions.
  1. +47 −0 src/__tests__/cricketTeamTotalCalc.js
  2. +137 −0 src/points-table/cricketTeamTotalCalc.js
@@ -0,0 +1,47 @@
import { calcCompletedMatches } from "../helpers/calcCompletedMatches";
import { cricketTeamTotalCalc } from "../points-table/cricketTeamTotalCalc";
import { matches } from "../data/matches";
import {
WON,
LOST,
NORESULT,
POINTS
} from "../helpers/constants";

const config = { pts4Win: 2, pts4NR: 1 };

it("cricketTeamTotalCalc", () => {
expect(
cricketTeamTotalCalc({
config,
matches,
team: "SA",
stat: WON
})
).toBe(3);
expect(
cricketTeamTotalCalc({
config,
matches,
team: "SA",
stat: LOST
})
).toBe(5);
expect(
cricketTeamTotalCalc({
config,
matches,
team: "SA",
stat: NORESULT
})
).toBe(1);

expect(
cricketTeamTotalCalc({
config,
matches,
team: "SA",
stat: POINTS
})
).toBe(7);
});
@@ -0,0 +1,137 @@
import {
WON,
LOST,
TEAM1,
TEAM2,
NORESULT,
POINTS
} from "../helpers/constants";
import { teamWon } from "./teamWon";
import { teamWonSuperOver } from "./teamWonSuperOver";

import { teamLost } from "./teamLost";
import { teamLostSuperOver } from "./teamLostSuperOver";

import { teamNoResult } from "./teamNoResult";

export const cricketTeamTotalCalc = ({
config,
matches,
team,
stat
}) => {
const { pts4Win, pts4NR } = config;
// need to look at what is getting passed in here
switch (stat) {
case WON:
return (
teamWon({
matches,
teamNum: TEAM1,
team,
stat: "Ru"
}) +
teamWon({
matches,
teamNum: TEAM2,
team,
stat: "Ru"
}) +
teamWonSuperOver({
matches,
teamNum: TEAM1,
team,
stat: "SupOvrR"
}) +
teamWonSuperOver({
matches,
teamNum: TEAM2,
team,
stat: "SupOvrR"
})
);
case LOST:
return (
teamLost({
matches,
teamNum: TEAM1,
team,
stat: "Ru"
}) +
teamLost({
matches,
teamNum: TEAM2,
team,
stat: "Ru"
}) +
teamLostSuperOver({
matches,
teamNum: TEAM1,
team,
stat: "SupOvrR"
}) +
teamLostSuperOver({
matches,
teamNum: TEAM2,
team,
stat: "SupOvrR"
})
);
case NORESULT:
return (
teamNoResult({
matches,
teamNum: TEAM1,
team
}) +
teamNoResult({
matches,
teamNum: TEAM2,
team
})
);
case POINTS:
return (
(teamWon({
matches,
teamNum: TEAM1,
team,
stat: "Ru"
}) +
teamWon({
matches,
teamNum: TEAM2,
team,
stat: "Ru"
}) +
teamWonSuperOver({
matches,
teamNum: TEAM1,
team,
stat: "SupOvrR"
}) +
teamWonSuperOver({
matches,
teamNum: TEAM2,
team,
stat: "SupOvrR"
})) *
pts4Win +
+(
teamNoResult({
matches,
teamNum: TEAM1,
team
}) +
teamNoResult({
matches,
teamNum: TEAM2,
team
})
) *
pts4NR
);
default:
return;
}
};

0 comments on commit 4a0453e

Please sign in to comment.
You can’t perform that action at this time.