Skip to content

Commit

Permalink
Adds a rule and a game action and some tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lee Richardson committed Jan 3, 2018
1 parent 7ab8e92 commit 7f0f997
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 6 deletions.
26 changes: 26 additions & 0 deletions Sharpasonne.Tests/Rules/SpaceIsEmptyRuleTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Sharpasonne.GameActions;
using Sharpasonne.Rules;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using Xunit;

namespace Sharpasonne.Tests.Rules
{
public class SpaceIsEmptyRuleTests
{
[Fact]
public void When_TileIsEmpty_Then_True()
{
Assert.True(new SpaceIsEmptyRule().Verify(new Engine(), new PlaceTileGameAction()));
}

[Fact]
public void When_TileIsEmpty_Then_False()
{
var engine = new Engine();

Assert.True(new SpaceIsEmptyRule().Verify(engine, new PlaceTileGameAction()));
}
}
}
14 changes: 8 additions & 6 deletions Sharpasonne/Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections;
using System.Collections.Immutable;
using System.Linq;
using System.Runtime.InteropServices;
using JetBrains.Annotations;
using Sharpasonne.Models;

Expand All @@ -12,17 +13,22 @@ public class Engine
{
public Board Board { get; } = new Board();

public Engine()
{
}

public Engine(
[NotNull] IImmutableQueue<IGameAction> gameActions,
[NotNull] IImmutableDictionary<Type, IImmutableList<IRule>> rules)
{
var nonGameActions = rules.Keys
.Where(k => !k.GetInterfaces().Any(i => i == typeof(IGameAction)))
.Where(type => !typeof(IGameAction).IsAssignableFrom(type))
.ToList();

if (nonGameActions.Any())
{
var typeNames = string.Join(", ", nonGameActions.Select(t => t.FullName));
var message = $"'{typeNames}' don't implement {nameof(IGameAction)}";
var message = $"'{typeNames}' does not implement {nameof(IGameAction)}";
throw new ArgumentOutOfRangeException(message);
}
}
Expand All @@ -34,8 +40,4 @@ public Engine(
}*/
}

public interface IGameAction
{
}
}
9 changes: 9 additions & 0 deletions Sharpasonne/GameActions/PlaceTileGameAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Sharpasonne;
using Sharpasonne.Models;

namespace Sharpasonne.GameActions
{
public class PlaceTileGameAction : IGameAction
{
}
}
6 changes: 6 additions & 0 deletions Sharpasonne/IGameAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Sharpasonne
{
public interface IGameAction
{
}
}
14 changes: 14 additions & 0 deletions Sharpasonne/Rules/SpaceIsEmptyRule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Sharpasonne;
using Sharpasonne.Models;

namespace Sharpasonne.Rules
{
public class SpaceIsEmptyRule : IRule
{
public bool Verify<T>(Engine engine, T gameAction)
where T : IGameAction
{
return true;
}
}
}

0 comments on commit 7f0f997

Please sign in to comment.