Skip to content

Commit 65e743e

Browse files
Merge pull request #107 from CodebreakerApp/106-update-analyzer-library
106 update analyzer library
2 parents 32eb380 + c7836ec commit 65e743e

File tree

12 files changed

+58
-24
lines changed

12 files changed

+58
-24
lines changed

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

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
using System.Collections;
2+
using System.Reflection.Emit;
23

34
using static Codebreaker.GameAPIs.Models.Colors;
45

5-
namespace Codebreaker.GameAPIs.Algorithms.Tests;
6+
namespace Codebreaker.GameAPIs.Analyzer.Tests;
67

78
public class ColorGame6x4AnalyzerTests
89
{
@@ -66,6 +67,16 @@ public void ShouldThrowOnInvalidMoveNumber()
6667
[Yellow, Green, Black, Blue], moveNumber: 2));
6768
}
6869

70+
[Fact]
71+
public void ShouldNotIncrementMoveNumberOnInvalidMove()
72+
{
73+
IGame game = TestSkeletonWithGame(
74+
[Green, Yellow, Green, Black],
75+
[Yellow, Green, Black, Blue], moveNumber: 2);
76+
77+
Assert.Equal(0, game?.LastMoveNumber);
78+
}
79+
6980
private static ColorResult TestSkeleton(string[] codes, string[] guesses, int moveNumber = 1)
7081
{
7182
MockColorGame game = new()
@@ -84,6 +95,33 @@ private static ColorResult TestSkeleton(string[] codes, string[] guesses, int mo
8495
ColorGameGuessAnalyzer analyzer = new(game,guesses.ToPegs<ColorField>().ToArray(), moveNumber);
8596
return analyzer.GetResult();
8697
}
98+
99+
private static IGame TestSkeletonWithGame(string[] codes, string[] guesses, int moveNumber = 1)
100+
{
101+
MockColorGame game = new()
102+
{
103+
GameType = GameTypes.Game6x4,
104+
NumberCodes = 4,
105+
MaxMoves = 12,
106+
IsVictory = false,
107+
FieldValues = new Dictionary<string, IEnumerable<string>>()
108+
{
109+
[FieldCategories.Colors] = TestData6x4.Colors6.ToList()
110+
},
111+
Codes = codes
112+
};
113+
114+
ColorGameGuessAnalyzer analyzer = new(game, guesses.ToPegs<ColorField>().ToArray(), moveNumber);
115+
try
116+
{
117+
analyzer.GetResult();
118+
}
119+
catch (ArgumentException)
120+
{
121+
122+
}
123+
return game;
124+
}
87125
}
88126

89127
public class TestData6x4 : IEnumerable<object[]>

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
using System.Collections;
22

3-
using Codebreaker.GameAPIs.Analyzers;
4-
53
using static Codebreaker.GameAPIs.Models.Colors;
64

7-
namespace Codebreaker.GameAPIs.Algorithms.Tests;
5+
namespace Codebreaker.GameAPIs.Analyzer.Tests;
86

97
public class ColorGame8x5AnalyzerTests
108
{

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
using System.Collections;
22

3-
using Codebreaker.GameAPIs.Analyzers;
4-
53
using static Codebreaker.GameAPIs.Models.Colors;
64
using static Codebreaker.GameAPIs.Models.Shapes;
75

8-
namespace Codebreaker.GameAPIs.Algorithms.Tests;
6+
namespace Codebreaker.GameAPIs.Analyzer.Tests;
97

108
// TODO: add more unit tests
119
public class ShapeGame5x5x4AnalyzerTests

src/services/gameapi/Codebreaker.GameAPIs.Analyzers.Tests/Codebreaker.GameAPIs.Analyzers.Tests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
<ItemGroup>
1313
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
1414
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
15-
<PackageReference Include="Moq" Version="4.18.4" />
15+
<PackageReference Include="Moq" Version="4.20.70" />
1616
<PackageReference Include="xunit" Version="2.6.3" />
17-
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.1">
17+
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.5">
1818
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1919
<PrivateAssets>all</PrivateAssets>
2020
</PackageReference>

src/services/gameapi/Codebreaker.GameAPIs.Analyzers.Tests/MockColorGame.cs

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

33
public class MockColorGame : IGame
44
{

src/services/gameapi/Codebreaker.GameAPIs.Analyzers.Tests/MockShapeGame.cs

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

33
public class MockShapeGame : IGame
44
{

src/services/gameapi/Codebreaker.GameAPIs.Analyzers.Tests/Results/ColorResultTests.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using Codebreaker.GameAPIs.Models;
2-
3-
namespace Codebreaker.GameAPIs.Algorithms.Tests;
1+
namespace Codebreaker.GameAPIs.Analyzer.Tests;
42

53
public class ColorResultTests
64
{

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using Codebreaker.GameAPIs.Models;
2-
3-
namespace Codebreaker.GameAPIs.Algorithms.Tests;
1+
namespace Codebreaker.GameAPIs.Analyzer.Tests;
42

53
public class ShapeAndColorResultTests
64
{

src/services/gameapi/Codebreaker.GameAPIs.Analyzers.Tests/Results/SimpleColorResultTests.cs

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

33
public class SimpleColorResultTests
44
{

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ private void ValidateGuess()
4343

4444
ValidateGuessValues();
4545

46-
_game.LastMoveNumber++;
47-
48-
if (_game.LastMoveNumber != _moveNumber)
46+
if ((_game.LastMoveNumber + 1) != _moveNumber)
4947
{
5048
throw new ArgumentException($"Incorrect move number received {_moveNumber}") { HResult = 4300 };
5149
}
50+
51+
_game.LastMoveNumber++;
5252
}
5353

5454
/// <summary>

0 commit comments

Comments
 (0)