From 06d439a4e18e1647c3e4667ea2d9df8a9a1cf8da Mon Sep 17 00:00:00 2001 From: guillaume Date: Mon, 20 Nov 2023 00:28:10 +0100 Subject: [PATCH 1/7] on commence ici --- src/12_RefactoringGolf/hole1/kata.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/12_RefactoringGolf/hole1/kata.ts b/src/12_RefactoringGolf/hole1/kata.ts index c750e5e..cde22cc 100644 --- a/src/12_RefactoringGolf/hole1/kata.ts +++ b/src/12_RefactoringGolf/hole1/kata.ts @@ -1,5 +1,6 @@ /* eslint-disable */ +// améliore ce code export class Game { private _lastSymbol = ' '; private _toto: Board = new Board(); From c7a6028001da31de041249b39426d374f0490a24 Mon Sep 17 00:00:00 2001 From: guillaume Date: Mon, 20 Nov 2023 00:44:53 +0100 Subject: [PATCH 2/7] =?UTF-8?q?instruction=20pour=20passer=20=C3=A0=20hole?= =?UTF-8?q?=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/{ => 12_RefactoringGolf/hole1}/README.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/{ => 12_RefactoringGolf/hole1}/README.md (100%) diff --git a/src/README.md b/src/12_RefactoringGolf/hole1/README.md similarity index 100% rename from src/README.md rename to src/12_RefactoringGolf/hole1/README.md From 64fd9d16c35306d62b9c8f23f08814a19ce4fd5e Mon Sep 17 00:00:00 2001 From: guillaume Date: Mon, 20 Nov 2023 14:46:48 +0100 Subject: [PATCH 3/7] modif le nom toto --- src/12_RefactoringGolf/hole1/kata.ts | 42 ++++++++++++++-------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/12_RefactoringGolf/hole1/kata.ts b/src/12_RefactoringGolf/hole1/kata.ts index cde22cc..966c385 100644 --- a/src/12_RefactoringGolf/hole1/kata.ts +++ b/src/12_RefactoringGolf/hole1/kata.ts @@ -3,7 +3,7 @@ // améliore ce code export class Game { private _lastSymbol = ' '; - private _toto: Board = new Board(); + private _board: Board = new Board(); public Play(symbol: string, x: number, y: number): void { //if first move @@ -18,58 +18,58 @@ export class Game { throw new Error('Invalid next player'); } //if not first move but play on an already played tile - else if (this._toto.TileAt(x, y).Symbol != ' ') { + else if (this._board.TileAt(x, y).Symbol != ' ') { throw new Error('Invalid position'); } // update game state this._lastSymbol = symbol; - this._toto.AddTileAt(symbol, x, y); + this._board.AddTileAt(symbol, x, y); } public Winner(): string { //if the positions in first row are taken if ( - this._toto.TileAt(0, 0)!.Symbol != ' ' && - this._toto.TileAt(0, 1)!.Symbol != ' ' && - this._toto.TileAt(0, 2)!.Symbol != ' ' + this._board.TileAt(0, 0)!.Symbol != ' ' && + this._board.TileAt(0, 1)!.Symbol != ' ' && + this._board.TileAt(0, 2)!.Symbol != ' ' ) { //if first row is full with same symbol if ( - this._toto.TileAt(0, 0)!.Symbol == this._toto.TileAt(0, 1)!.Symbol && - this._toto.TileAt(0, 2)!.Symbol == this._toto.TileAt(0, 1)!.Symbol + this._board.TileAt(0, 0)!.Symbol == this._board.TileAt(0, 1)!.Symbol && + this._board.TileAt(0, 2)!.Symbol == this._board.TileAt(0, 1)!.Symbol ) { - return this._toto.TileAt(0, 0)!.Symbol; + return this._board.TileAt(0, 0)!.Symbol; } } //if the positions in first row are taken if ( - this._toto.TileAt(1, 0)!.Symbol != ' ' && - this._toto.TileAt(1, 1)!.Symbol != ' ' && - this._toto.TileAt(1, 2)!.Symbol != ' ' + this._board.TileAt(1, 0)!.Symbol != ' ' && + this._board.TileAt(1, 1)!.Symbol != ' ' && + this._board.TileAt(1, 2)!.Symbol != ' ' ) { //if middle row is full with same symbol if ( - this._toto.TileAt(1, 0)!.Symbol == this._toto.TileAt(1, 1)!.Symbol && - this._toto.TileAt(1, 2)!.Symbol == this._toto.TileAt(1, 1)!.Symbol + this._board.TileAt(1, 0)!.Symbol == this._board.TileAt(1, 1)!.Symbol && + this._board.TileAt(1, 2)!.Symbol == this._board.TileAt(1, 1)!.Symbol ) { - return this._toto.TileAt(1, 0)!.Symbol; + return this._board.TileAt(1, 0)!.Symbol; } } //if the positions in first row are taken if ( - this._toto.TileAt(2, 0)!.Symbol != ' ' && - this._toto.TileAt(2, 1)!.Symbol != ' ' && - this._toto.TileAt(2, 2)!.Symbol != ' ' + this._board.TileAt(2, 0)!.Symbol != ' ' && + this._board.TileAt(2, 1)!.Symbol != ' ' && + this._board.TileAt(2, 2)!.Symbol != ' ' ) { //if middle row is full with same symbol if ( - this._toto.TileAt(2, 0)!.Symbol == this._toto.TileAt(2, 1)!.Symbol && - this._toto.TileAt(2, 2)!.Symbol == this._toto.TileAt(2, 1)!.Symbol + this._board.TileAt(2, 0)!.Symbol == this._board.TileAt(2, 1)!.Symbol && + this._board.TileAt(2, 2)!.Symbol == this._board.TileAt(2, 1)!.Symbol ) { - return this._toto.TileAt(2, 0)!.Symbol; + return this._board.TileAt(2, 0)!.Symbol; } } From 36de56ead638854370709936ed61cafdfc034ff9 Mon Sep 17 00:00:00 2001 From: guillaume Date: Mon, 20 Nov 2023 15:05:04 +0100 Subject: [PATCH 4/7] commentaire de Nicolas --- src/12_RefactoringGolf/hole1/kata.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/12_RefactoringGolf/hole1/kata.ts b/src/12_RefactoringGolf/hole1/kata.ts index 966c385..6ee50ca 100644 --- a/src/12_RefactoringGolf/hole1/kata.ts +++ b/src/12_RefactoringGolf/hole1/kata.ts @@ -5,13 +5,10 @@ export class Game { private _lastSymbol = ' '; private _board: Board = new Board(); - public Play(symbol: string, x: number, y: number): void { - //if first move - if (this._lastSymbol == ' ') { - //if player is X - if (symbol == 'O') { - throw new Error('Invalid first player'); - } + public Play(symbol: string, x: number, y: number): void { + //if first move //if player is X + if (this._lastSymbol == ' ' && symbol == 'O') { + throw new Error('Invalid first player'); } //if not first move but player repeated else if (symbol == this._lastSymbol) { From 1e64a6470fa4a02738597f5bb8c8813d87932567 Mon Sep 17 00:00:00 2001 From: guillaume Date: Mon, 20 Nov 2023 15:06:40 +0100 Subject: [PATCH 5/7] =?UTF-8?q?enlev=C3=A9=20les=20else?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/12_RefactoringGolf/hole1/kata.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/12_RefactoringGolf/hole1/kata.ts b/src/12_RefactoringGolf/hole1/kata.ts index 6ee50ca..33b937a 100644 --- a/src/12_RefactoringGolf/hole1/kata.ts +++ b/src/12_RefactoringGolf/hole1/kata.ts @@ -11,11 +11,11 @@ export class Game { throw new Error('Invalid first player'); } //if not first move but player repeated - else if (symbol == this._lastSymbol) { + if (symbol == this._lastSymbol) { throw new Error('Invalid next player'); } //if not first move but play on an already played tile - else if (this._board.TileAt(x, y).Symbol != ' ') { + if (this._board.TileAt(x, y).Symbol != ' ') { throw new Error('Invalid position'); } From 2119ddf662c70c4b2cb430a4583d6fc90bac7aec Mon Sep 17 00:00:00 2001 From: guillaume Date: Mon, 20 Nov 2023 15:09:40 +0100 Subject: [PATCH 6/7] remplacer commentaire par une fonction --- src/12_RefactoringGolf/hole1/kata.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/12_RefactoringGolf/hole1/kata.ts b/src/12_RefactoringGolf/hole1/kata.ts index 33b937a..fde5008 100644 --- a/src/12_RefactoringGolf/hole1/kata.ts +++ b/src/12_RefactoringGolf/hole1/kata.ts @@ -18,8 +18,11 @@ export class Game { if (this._board.TileAt(x, y).Symbol != ' ') { throw new Error('Invalid position'); } + + this.updateGameState(symbol, x, y); + } - // update game state + private updateGameState(symbol: string, x: number, y: number) { this._lastSymbol = symbol; this._board.AddTileAt(symbol, x, y); } From 161370eeedb38fc9288354d431d420e32900086c Mon Sep 17 00:00:00 2001 From: guillaume prof Date: Sun, 15 Sep 2024 19:52:03 +0200 Subject: [PATCH 7/7] create PR --- src/12_RefactoringGolf/hole1/README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/12_RefactoringGolf/hole1/README.md b/src/12_RefactoringGolf/hole1/README.md index 4cfc9a0..87ea8b9 100644 --- a/src/12_RefactoringGolf/hole1/README.md +++ b/src/12_RefactoringGolf/hole1/README.md @@ -1,14 +1,15 @@ # Hole 1 to Hole 2 -Change the code in hole 1 to be identical to the code in hole 2; implementation and tests can change. +# create a pull request ## Refactorings -- Tackle code comments, long method and large class - - Extract method +- Tackle all code comments, long method and large class + - Extract methods where there is a comment ## Tips +- Change the code in hole 1 to be identical to the code in hole 2; implementation and tests can change. - Use a diff tool to identify the code changes you need to perform - Check the code coverage is enough to detect any unintended behaviour changes