Skip to content

Commit 15eb759

Browse files
Merge pull request #322 from CodebreakerApp/copilot/fix-289
Enhance log message with expected move number for invalid moves
2 parents 116481b + 3b4d69a commit 15eb759

14 files changed

+48
-36
lines changed

src/services/common/Codebreaker.GameAPIs.Analyzers.Tests/Analyzers/ColorGame6x4AnalyzerTests.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public void SetMove_ShouldReturnThreeWhite()
2424
public void SetMove_UsingVariousData(int expectedBlack, int expectedWhite, params string[] guessValues)
2525
{
2626
string[] code = [Red, Green, Blue, Red];
27-
ColorResult expectedKeyPegs = new (expectedBlack, expectedWhite);
27+
ColorResult expectedKeyPegs = new(expectedBlack, expectedWhite);
2828
ColorResult resultKeyPegs = AnalyzeGame(code, guessValues);
2929
Assert.Equal(expectedKeyPegs, resultKeyPegs);
3030
}
@@ -40,7 +40,7 @@ public void SetMove_UsingVariousDataUsingDataClass(string[] code, string[] guess
4040
[Fact]
4141
public void SetMove_ShouldThrowOnInvalidGuessCount()
4242
{
43-
Assert.Throws<ArgumentException>(() =>
43+
Assert.Throws<ArgumentException>(() =>
4444
AnalyzeGame(
4545
["Black", "Black", "Black", "Black"],
4646
["Black"]
@@ -50,7 +50,7 @@ public void SetMove_ShouldThrowOnInvalidGuessCount()
5050
[Fact]
5151
public void SetMove_ShouldThrowOnInvalidGuessValues()
5252
{
53-
Assert.Throws<ArgumentException>(() =>
53+
Assert.Throws<ArgumentException>(() =>
5454
AnalyzeGame(
5555
["Black", "Black", "Black", "Black"],
5656
["Black", "Der", "Blue", "Yellow"] // "Der" is the wrong value
@@ -60,7 +60,7 @@ public void SetMove_ShouldThrowOnInvalidGuessValues()
6060
[Fact]
6161
public void SetMove_ShouldThrowOnInvalidMoveNumber()
6262
{
63-
Assert.Throws<ArgumentException>(() =>
63+
Assert.Throws<ArgumentException>(() =>
6464
AnalyzeGame(
6565
[Green, Yellow, Green, Black],
6666
[Yellow, Green, Black, Blue], moveNumber: 2));
@@ -76,7 +76,19 @@ public void SetMove_ShouldNotIncrementMoveNumberOnInvalidMove()
7676
Assert.Equal(0, game?.LastMoveNumber);
7777
}
7878

79-
private static MockColorGame CreateGame(string[] codes) =>
79+
[Fact]
80+
public void SetMove_ShouldIncludeExpectedMoveNumberInErrorMessage()
81+
{
82+
var exception = Assert.Throws<ArgumentException>(() =>
83+
AnalyzeGame(
84+
[Green, Yellow, Green, Black],
85+
[Yellow, Green, Black, Blue], moveNumber: 3));
86+
87+
Assert.Contains("received 3", exception.Message);
88+
Assert.Contains("expected 1", exception.Message);
89+
}
90+
91+
private static MockColorGame CreateGame(string[] codes) =>
8092
new()
8193
{
8294
GameType = GameTypes.Game6x4,
@@ -93,7 +105,7 @@ private static MockColorGame CreateGame(string[] codes) =>
93105
private static ColorResult AnalyzeGame(string[] codes, string[] guesses, int moveNumber = 1)
94106
{
95107
MockColorGame game = CreateGame(codes);
96-
ColorGameGuessAnalyzer analyzer = new(game, [.. guesses.ToPegs<ColorField>() ], moveNumber);
108+
ColorGameGuessAnalyzer analyzer = new(game, [.. guesses.ToPegs<ColorField>()], moveNumber);
97109
return analyzer.GetResult();
98110
}
99111

src/services/common/Codebreaker.GameAPIs.Analyzers.Tests/Analyzers/ColorGame8x5AnalyzerTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public void SetMove_ShouldReturnThreeWhite()
2424
public void SetMove_UsingVariousData(int expectedBlack, int expectedWhite, params string[] guessValues)
2525
{
2626
string[] code = [Red, Green, Blue, Red, Brown];
27-
ColorResult expectedKeyPegs = new (expectedBlack, expectedWhite);
27+
ColorResult expectedKeyPegs = new(expectedBlack, expectedWhite);
2828
ColorResult resultKeyPegs = AnalyzeGame(code, guessValues);
2929
Assert.Equal(expectedKeyPegs, resultKeyPegs);
3030
}
@@ -40,7 +40,7 @@ public void SetMove_UsingVariousDataUsingDataClass(string[] code, string[] guess
4040
[Fact]
4141
public void SetMove_ShouldThrowOnInvalidGuessCount()
4242
{
43-
Assert.Throws<ArgumentException>(() =>
43+
Assert.Throws<ArgumentException>(() =>
4444
AnalyzeGame(
4545
["Black", "Black", "Black", "Black", "Black"],
4646
["Black"]
@@ -50,14 +50,14 @@ public void SetMove_ShouldThrowOnInvalidGuessCount()
5050
[Fact]
5151
public void SetMove_ShouldThrowOnInvalidGuessValues()
5252
{
53-
Assert.Throws<ArgumentException>(() =>
53+
Assert.Throws<ArgumentException>(() =>
5454
AnalyzeGame(
5555
["Black", "Black", "Black", "Black", "Black"],
5656
["Black", "Der", "Blue", "Yellow", "Black"] // "Der" is the wrong value
5757
));
5858
}
5959

60-
private static MockColorGame CreateGame(string[] codes) =>
60+
private static MockColorGame CreateGame(string[] codes) =>
6161
new()
6262
{
6363
GameType = GameTypes.Game8x5,

src/services/common/Codebreaker.GameAPIs.Analyzers.Tests/Analyzers/ShapeGame5x5x4AnalyzerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ private static MockShapeGame CreateGame(string[] codes) =>
178178
[FieldCategories.Colors] = TestData5x5x4.Colors5.ToList(),
179179
[FieldCategories.Shapes] = TestData5x5x4.Shapes5.ToList()
180180
},
181-
Codes = codes
181+
Codes = codes
182182
};
183183

184184
private static ShapeAndColorResult AnalyzeGame(string[] codes, string[] guesses)

src/services/common/Codebreaker.GameAPIs.Analyzers.Tests/Analyzers/SimpleGameGuessAnalyzerTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void SetMove_UsingVariousDataUsingDataClass(string[] code, string[] guess
3535
[Fact]
3636
public void SetMove_ShouldThrowOnInvalidGuessCount()
3737
{
38-
Assert.Throws<ArgumentException>(() =>
38+
Assert.Throws<ArgumentException>(() =>
3939
AnalyzeGame(
4040
["Black", "Black", "Black", "Black"],
4141
["Black"]
@@ -45,7 +45,7 @@ public void SetMove_ShouldThrowOnInvalidGuessCount()
4545
[Fact]
4646
public void SetMove_ShouldThrowOnInvalidGuessValues()
4747
{
48-
Assert.Throws<ArgumentException>(() =>
48+
Assert.Throws<ArgumentException>(() =>
4949
AnalyzeGame(
5050
["Black", "Black", "Black", "Black"],
5151
["Black", "Der", "Blue", "Yellow"] // "Der" is the wrong value
@@ -55,7 +55,7 @@ public void SetMove_ShouldThrowOnInvalidGuessValues()
5555
[Fact]
5656
public void SetMove_ShouldThrowOnInvalidMoveNumber()
5757
{
58-
Assert.Throws<ArgumentException>(() =>
58+
Assert.Throws<ArgumentException>(() =>
5959
AnalyzeGame(
6060
[Green, Yellow, Green, Black],
6161
[Yellow, Green, Black, Blue], moveNumber: 2));
@@ -128,7 +128,7 @@ public void GetResult_WithGameNotComplete_ShouldSetCorrectGameEndInformation()
128128
Assert.False(game.IsVictory);
129129
}
130130

131-
private static MockColorGame CreateGame(string[] codes) =>
131+
private static MockColorGame CreateGame(string[] codes) =>
132132
new()
133133
{
134134
GameType = GameTypes.Game6x4Mini,
@@ -180,8 +180,8 @@ public IEnumerator<object[]> GetEnumerator()
180180
new SimpleColorResult(
181181
[
182182
ResultValue.CorrectPositionAndColor,
183-
ResultValue.CorrectColor,
184-
ResultValue.Incorrect,
183+
ResultValue.CorrectColor,
184+
ResultValue.Incorrect,
185185
ResultValue.Incorrect
186186
]) // expected
187187
};

src/services/common/Codebreaker.GameAPIs.Analyzers.Tests/Results/ShapeAndColorResultTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace Codebreaker.GameAPIs.Analyzer.Tests;
22

33
public class ShapeAndColorResultTests
4-
{
4+
{
55
[Fact]
66
public void ToStringShouldReturnFormat()
77
{

src/services/common/Codebreaker.GameAPIs.Analyzers/Analyzers/ColorGameGuessAnalyzer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ protected override void ValidateGuessValues()
1515
protected override ColorResult GetCoreResult()
1616
{
1717
// Check black and white keyPegs
18-
List<ColorField> codesToCheck = [.. _game.Codes.ToPegs<ColorField>() ];
19-
List<ColorField> guessPegsToCheck = [.. Guesses ];
18+
List<ColorField> codesToCheck = [.. _game.Codes.ToPegs<ColorField>()];
19+
List<ColorField> guessPegsToCheck = [.. Guesses];
2020
int black = 0;
2121
List<string> whitePegs = [];
2222

src/services/common/Codebreaker.GameAPIs.Analyzers/Analyzers/GameGuessAnalyzer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ private void ValidateGuess()
4040

4141
if ((_game.LastMoveNumber + 1) != _moveNumber)
4242
{
43-
throw new ArgumentException($"Incorrect move number received {_moveNumber}") { HResult = 4300 };
43+
throw new ArgumentException($"Incorrect move number received {_moveNumber}, expected {_game.LastMoveNumber + 1}") { HResult = 4300 };
4444
}
4545

4646
_game.LastMoveNumber++;

src/services/common/Codebreaker.GameAPIs.Analyzers/Analyzers/ShapeGameGuessAnalyzer.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ protected override void ValidateGuessValues()
2020
protected override ShapeAndColorResult GetCoreResult()
2121
{
2222
// Check black, white and blue keyPegs
23-
List<ShapeAndColorField> codesToCheck = [.._game.Codes.ToPegs<ShapeAndColorField>() ]; // all the codes that need to be verified with the actual check
24-
List<ShapeAndColorField> guessPegsToCheck = [.. Guesses ]; // all the guesses that need to be verified with the actual check
23+
List<ShapeAndColorField> codesToCheck = [.. _game.Codes.ToPegs<ShapeAndColorField>()]; // all the codes that need to be verified with the actual check
24+
List<ShapeAndColorField> guessPegsToCheck = [.. Guesses]; // all the guesses that need to be verified with the actual check
2525
List<ShapeAndColorField> remainingCodesToCheck = []; // the codes that need to be checked with the check following - filled by the actual check
2626
List<ShapeAndColorField> remainingGuessPegsToCheck = []; // the guesses that need to be checked with the check following - filled by the actual check
2727

@@ -74,9 +74,9 @@ protected override ShapeAndColorResult GetCoreResult()
7474

7575
for (int i = 0; i < guessPegsToCheck.Count; i++)
7676
{
77-
if ((guessPegsToCheck[i] != ShapeAndColorField.Empty ||
77+
if ((guessPegsToCheck[i] != ShapeAndColorField.Empty ||
7878
codesToCheck[i] != ShapeAndColorField.Empty) &&
79-
(guessPegsToCheck[i].Shape == codesToCheck[i].Shape ||
79+
(guessPegsToCheck[i].Shape == codesToCheck[i].Shape ||
8080
guessPegsToCheck[i].Color == codesToCheck[i].Color))
8181
{
8282
blue++;

src/services/common/Codebreaker.GameAPIs.Analyzers/Analyzers/SimpleGameGuessAnalyzer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ protected override void ValidateGuessValues()
1111
protected override SimpleColorResult GetCoreResult()
1212
{
1313
// Check black and white keyPegs
14-
List<string> codesToCheck = [.. _game.Codes.ToPegs<ColorField>().Select(cf => cf.ToString()) ];
14+
List<string> codesToCheck = [.. _game.Codes.ToPegs<ColorField>().Select(cf => cf.ToString())];
1515
List<string> guessPegsToCheck = [.. Guesses.Select(g => g.ToString())];
16-
List<int> positionsToIgnore = [];
16+
List<int> positionsToIgnore = [];
1717

1818
ResultValue[] results = [.. Enumerable.Repeat(ResultValue.Incorrect, 4)];
1919

@@ -38,7 +38,7 @@ protected override SimpleColorResult GetCoreResult()
3838
results[i] = ResultValue.CorrectColor;
3939
codesToCheck[ix] = string.Empty;
4040
}
41-
41+
4242
return new SimpleColorResult(results);
4343
}
4444

src/services/common/Codebreaker.GameAPIs.Analyzers/Extensions/FieldExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public static IEnumerable<T> ToFields<T>(this string[] fieldStrings)
1414
public static IEnumerable<string> ToStringFields<T>(this T[] fields)
1515
where T : IFormattable
1616
{
17-
foreach(var field in fields)
17+
foreach (var field in fields)
1818
{
1919
yield return field.ToString(default, default);
2020
}

0 commit comments

Comments
 (0)