Skip to content

Commit

Permalink
Merge pull request #9 from shammy642/backend_player_class
Browse files Browse the repository at this point in the history
added player class
  • Loading branch information
Alexia-May authored Oct 16, 2024
2 parents ee8d88b + 3c5ce84 commit 747f2be
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 30 deletions.
21 changes: 21 additions & 0 deletions api/numberGame/Player.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Player {
constructor(id, name) {
this.id = id;
this.name = name;
this.currentGuess = null,
this.totalScore = 0
}

guess(num) {
this.currentGuess = num
}

getTotalScore() {
return this.totalScore
}
wonRound() {
this.totalScore++
}
}

module.exports = Player
27 changes: 27 additions & 0 deletions api/tests/numberGame/Player.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const Player = require("../../numberGame/Player")

describe('player', () => {
test('initiates with id, name, currentGuess (null) and totalScore (0)', () => {
const player = new Player('17326746', 'Bob')
expect(player.id).toBe('17326746')
expect(player.name).toBe('Bob')
expect(player.currentGuess).toEqual(null)
expect(player.totalScore).toEqual(0)
})

test('guess() replaces the players guess', () => {
const player = new Player('17326746', 'Bob')
player.guess(5)
expect(player.currentGuess).toBe(5)
})

test('getTotalScore returns total score', () => {
const player = new Player('17326746', 'Bob')
expect(player.getTotalScore()).toBe(0)
})
test('wonRound adds 1 to total score', () => {
const player = new Player('17326746', 'Bob')
player.wonRound()
expect(player.totalScore).toEqual(1)
})
})
9 changes: 0 additions & 9 deletions frontend/tests/pages/HomePage.test.jsx

This file was deleted.

7 changes: 0 additions & 7 deletions frontend/tests/pages/InGame.test.jsx

This file was deleted.

7 changes: 0 additions & 7 deletions frontend/tests/pages/Lobby.test.jsx

This file was deleted.

7 changes: 0 additions & 7 deletions frontend/tests/pages/RoundEnd.test.jsx

This file was deleted.

0 comments on commit 747f2be

Please sign in to comment.