From 4817ec28ab9e150f0812e1b922695e8e35b0d1bc Mon Sep 17 00:00:00 2001 From: Richard Halsall <–richard-glyn.halsall@informatik.hs-fulda.e> Date: Thu, 9 Feb 2023 14:35:02 +0100 Subject: [PATCH] =?UTF-8?q?Test;=20testen,=20ob=20die=20Spielerobjekte=20f?= =?UTF-8?q?=C3=BCr=20jede=20Spieleranzahl=20korrekt=20erzeugt=20werden?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- schlangen_und_leitern/js/playerHandling.js | 11 ++++-- .../tests/playerHandling.test.js | 36 +++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 schlangen_und_leitern/tests/playerHandling.test.js diff --git a/schlangen_und_leitern/js/playerHandling.js b/schlangen_und_leitern/js/playerHandling.js index 6cbef27..9340360 100644 --- a/schlangen_und_leitern/js/playerHandling.js +++ b/schlangen_und_leitern/js/playerHandling.js @@ -4,7 +4,7 @@ function PlayerBuilder(){ this.position = 1; - this.newPosition; + this.newPosition = 1; this.won = false } @@ -19,7 +19,7 @@ function buildPlayerArray(playerCount, boardArr){ for(let i = 1; i <= playerCount; i++){ let player = new PlayerBuilder(i); playerArray.push(player) - console.log("player added to array!") + } return playerArray; @@ -210,4 +210,11 @@ function landedOn (player, objectArr){ player.newPosition = objectArr[i].end; } } +} + + + +module.exports = { + PlayerBuilder, + buildPlayerArray, } \ No newline at end of file diff --git a/schlangen_und_leitern/tests/playerHandling.test.js b/schlangen_und_leitern/tests/playerHandling.test.js new file mode 100644 index 0000000..62792ba --- /dev/null +++ b/schlangen_und_leitern/tests/playerHandling.test.js @@ -0,0 +1,36 @@ +//Importieren der FUnktionen +const { PlayerBuilder, buildPlayerArray, movePlayer } = require('../js/playerHandling'); + +//example player array +let playerArr2 = [ + {"position": 1, "newPosition": 1, "won": false}, + {"position": 1, "newPosition": 1, "won": false} + +] +let playerArr3 = [ + {"position": 1, "newPosition": 1, "won": false}, + {"position": 1, "newPosition": 1, "won": false}, + {"position": 1, "newPosition": 1, "won": false}, + +] +let playerArr4 = [ + {"position": 1, "newPosition": 1, "won": false}, + {"position": 1, "newPosition": 1, "won": false}, + {"position": 1, "newPosition": 1, "won": false}, + {"position": 1, "newPosition": 1, "won": false} + +] + +//Eine Test Gruppe, mit mehreren Tests +describe('Testen, ob für jede mögliche Spieleranzahl die richtige Anzahl von Spielerobjekten erzeugt wird', () => { + + it('testen ob 2 Spieler Objekte generiert wird ', ()=>{ + expect(buildPlayerArray(2)).toEqual(playerArr2); + }); + it('testen ob 3 Spieler Objekte generiert wird ', ()=>{ + expect(buildPlayerArray(3)).toEqual(playerArr3); + }); + it('testen ob 4 Spieler Objekte generiert wird ', ()=>{ + expect(buildPlayerArray(4)).toEqual(playerArr4); + }); +}) \ No newline at end of file