From 618debcb06e1610b6e43cd7007ec8ad8507ff50d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphael=20Elstr=C3=B6m?= Date: Wed, 8 Feb 2023 16:45:15 +0100 Subject: [PATCH] =?UTF-8?q?Test:=20Vier=20Diagonal=20nach=20links=20erkann?= =?UTF-8?q?t=20f=C3=BCr=20Spieler=202=20(rot)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vier_gewinnt/JS/vierDiagonalLinks.js | 4 +++- vier_gewinnt/tests/test_vierDiagonalLinks.test.js | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/vier_gewinnt/JS/vierDiagonalLinks.js b/vier_gewinnt/JS/vierDiagonalLinks.js index e0d8369..18e8c79 100644 --- a/vier_gewinnt/JS/vierDiagonalLinks.js +++ b/vier_gewinnt/JS/vierDiagonalLinks.js @@ -4,7 +4,9 @@ function vierDiagonalLinks(allSpaltenArray) { for (let j = 0; j <= allSpaltenArray[0].length -3; j++) { if (allSpaltenArray[j][i]===1 && allSpaltenArray[j+1][i-1]===1 && allSpaltenArray[j+2][i-2]===1 && allSpaltenArray[j+3][i-3]===1) { Gewinner = 1; - } + }if (allSpaltenArray[j][i]===2 && allSpaltenArray[j+1][i-1]===2 && allSpaltenArray[j+2][i-2]===2 && allSpaltenArray[j+3][i-3]===2) { + Gewinner = 2; + } } } return Gewinner; diff --git a/vier_gewinnt/tests/test_vierDiagonalLinks.test.js b/vier_gewinnt/tests/test_vierDiagonalLinks.test.js index 9d65ddf..1970e3a 100644 --- a/vier_gewinnt/tests/test_vierDiagonalLinks.test.js +++ b/vier_gewinnt/tests/test_vierDiagonalLinks.test.js @@ -8,5 +8,17 @@ describe("Test Vier Gewinnt", () => { expect(vierDiagonalLinks([[2, 2, 1, 2, 1, 1], [2, 1, 2, 1, 1, 0], [2, 1, 2, 1, 0, 0], [1, 2, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]])).toBe(1); expect(vierDiagonalLinks([[0, 0, 0, 0, 0, 0], [1, 2, 1, 2, 1, 0], [2, 1, 2, 1, 0, 0], [2, 1, 1, 0, 0, 0], [2, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 2, 2, 0, 0, 0]])).toBe(1); + }) +}) + + +describe("Test Vier Gewinnt", () => { + it("Test vierDiagonalLinks: Vier Diagonal nach links erkennen und Gewinner 2(Rot) zuruek geben", () =>{ + expect(vierDiagonalLinks([[0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 1, 2, 2, 0, 0], [1, 2, 2, 0, 0, 0], [1, 2, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0]])).toBe(2); + expect(vierDiagonalLinks([[1, 2, 1, 2, 0, 0], [1, 2, 2, 0, 0, 0], [1, 2, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]])).toBe(2); + expect(vierDiagonalLinks([[0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 1, 2, 1, 2, 2], [1, 2, 1, 2, 2, 0], [1, 2, 1, 2, 0, 0], [2, 1, 2, 0, 0, 0]])).toBe(2); + expect(vierDiagonalLinks([[1, 1, 2, 1, 2, 2], [1, 2, 1, 2, 2, 0], [1, 2, 1, 2, 0, 0], [2, 1, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]])).toBe(2); + expect(vierDiagonalLinks([[0, 0, 0, 0, 0, 0], [2, 1, 2, 1, 2, 0], [1, 2, 1, 2, 0, 0], [1, 2, 2, 0, 0, 0], [1, 2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 1, 0, 0, 0]])).toBe(2); + }) }) \ No newline at end of file