Skip to content

Commit

Permalink
Create bowling_game.test.js
Browse files Browse the repository at this point in the history
  • Loading branch information
steelpipe75 committed Apr 27, 2024
1 parent c00ecf3 commit 9828289
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions javascript_bun/bowling_game/bowling_game.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { describe, beforeEach, expect, test } from "bun:test";
import { BowlingGame } from "./bowling_game";

describe("Bowling Game", () => {
let bg;

beforeEach(() => {
bg = new BowlingGame();
});

function rollMany(game, times, pins) {
for (let i = 0; i < times; i++) {
game.roll(pins);
}
}

test("All zeros game", () => {
rollMany(bg, 20, 0)
expect(bg.score()).toBe(0);
});

test("All one game", () => {
rollMany(bg, 20, 1)
expect(bg.score()).toBe(20);
});

test("One spare game", () => {
bg.roll(5)
bg.roll(5)
bg.roll(3)
rollMany(bg, 17, 0)
expect(bg.score()).toBe(16);
});

test("One strike game", () => {
bg.roll(10)
bg.roll(3)
bg.roll(4)
rollMany(bg, 16, 0)
expect(bg.score()).toBe(24);
});

test("Perfect game", () => {
rollMany(bg, 12, 10)
expect(bg.score()).toBe(300);
});
});

0 comments on commit 9828289

Please sign in to comment.