Ajout d'une correction possible
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
using MiniJeuxFinal.Games.PierrePapierCiseaux.Actions;
|
||||
using NFluent;
|
||||
|
||||
namespace MiniJeuxFinal.Test.Games.PierrePapierCiseaux.Actions
|
||||
{
|
||||
public class PaperActionTest
|
||||
{
|
||||
private PaperAction CreateTarget() => new PaperAction();
|
||||
|
||||
|
||||
|
||||
[Fact]
|
||||
public void Should_init()
|
||||
{
|
||||
var target = CreateTarget();
|
||||
Check.That(target.Name).IsEqualTo("Papier");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_win()
|
||||
{
|
||||
var target = CreateTarget();
|
||||
Check.That(target.ToWin(new StoneAction())).IsTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_loose()
|
||||
{
|
||||
var target = CreateTarget();
|
||||
Check.That(target.ToWin(new ScissorsAction())).IsFalse();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using MiniJeuxFinal.Games.PierrePapierCiseaux.Actions;
|
||||
using NFluent;
|
||||
|
||||
namespace MiniJeuxFinal.Test.Games.PierrePapierCiseaux.Actions
|
||||
{
|
||||
public class ScissorsActionTest
|
||||
{
|
||||
private ScissorsAction CreateTarget() => new ScissorsAction();
|
||||
|
||||
|
||||
|
||||
[Fact]
|
||||
public void Should_init()
|
||||
{
|
||||
var target = CreateTarget();
|
||||
Check.That(target.Name).IsEqualTo("Ciseaux");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_win()
|
||||
{
|
||||
var target = CreateTarget();
|
||||
Check.That(target.ToWin(new PaperAction())).IsTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_loose()
|
||||
{
|
||||
var target = CreateTarget();
|
||||
Check.That(target.ToWin(new StoneAction())).IsFalse();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using MiniJeuxFinal.Games.PierrePapierCiseaux.Actions;
|
||||
using NFluent;
|
||||
|
||||
namespace MiniJeuxFinal.Test.Games.PierrePapierCiseaux.Actions
|
||||
{
|
||||
public class StoneActionTest
|
||||
{
|
||||
private StoneAction CreateTarget() => new StoneAction();
|
||||
|
||||
|
||||
|
||||
[Fact]
|
||||
public void Should_init()
|
||||
{
|
||||
var target = CreateTarget();
|
||||
Check.That(target.Name).IsEqualTo("Pierre");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_win()
|
||||
{
|
||||
var target = CreateTarget();
|
||||
Check.That(target.ToWin(new ScissorsAction())).IsTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_loose()
|
||||
{
|
||||
var target = CreateTarget();
|
||||
Check.That(target.ToWin(new PaperAction())).IsFalse();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
using FakeItEasy;
|
||||
using MiniJeuxFinal.Games.PierrePapierCiseaux.Actions;
|
||||
using MiniJeuxFinal.Games.PierrePapierCiseaux.Factories;
|
||||
using MiniJeuxFinal.Wrappers;
|
||||
using NFluent;
|
||||
|
||||
namespace MiniJeuxFinal.Test.Games.PierrePapierCiseaux.Factories
|
||||
{
|
||||
public class InputActionFactoryTest
|
||||
{
|
||||
private readonly IConsole _console = A.Fake<IConsole>();
|
||||
|
||||
|
||||
|
||||
private InputActionFactory CreateTarget() =>
|
||||
new InputActionFactory(_console);
|
||||
|
||||
|
||||
|
||||
[Theory]
|
||||
[InlineData("0")]
|
||||
[InlineData("1")]
|
||||
[InlineData("2")]
|
||||
public void Should_get_selected_action(string selected)
|
||||
{
|
||||
var target = CreateTarget();
|
||||
A.CallTo(() => _console.ReadLine()).Returns(selected);
|
||||
var actions = new List<IActionPpc>
|
||||
{
|
||||
A.Fake<IActionPpc>(),
|
||||
A.Fake<IActionPpc>(),
|
||||
A.Fake<IActionPpc>()
|
||||
};
|
||||
|
||||
var result = target.GetAction(actions);
|
||||
Check.That(actions.Contains(result)).IsTrue();
|
||||
Check.That(result).IsEqualTo(actions[int.Parse(selected)]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_show_error_when_invalid_input()
|
||||
{
|
||||
var target = CreateTarget();
|
||||
A.CallTo(() => _console.ReadLine()).ReturnsNextFromSequence("3", "0");
|
||||
var actions = new List<IActionPpc>
|
||||
{
|
||||
A.Fake<IActionPpc>(),
|
||||
A.Fake<IActionPpc>(),
|
||||
A.Fake<IActionPpc>()
|
||||
};
|
||||
|
||||
var result = target.GetAction(actions);
|
||||
Check.That(actions.Contains(result)).IsTrue();
|
||||
Check.That(result).IsEqualTo(actions[int.Parse("0")]);
|
||||
A.CallTo(() => _console.WriteLine("❌ Choix invalide !")).MustHaveHappenedOnceExactly();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using FakeItEasy;
|
||||
using MiniJeuxFinal.Games.PierrePapierCiseaux.Actions;
|
||||
using MiniJeuxFinal.Games.PierrePapierCiseaux.Factories;
|
||||
using NFluent;
|
||||
|
||||
namespace MiniJeuxFinal.Test.Games.PierrePapierCiseaux.Factories
|
||||
{
|
||||
public class RandomActionFactoryTest
|
||||
{
|
||||
private RandomActionFactory CreateTarget() => new RandomActionFactory();
|
||||
|
||||
|
||||
|
||||
[Theory]
|
||||
[InlineData(2)]
|
||||
[InlineData(5)]
|
||||
[InlineData(3)]
|
||||
[InlineData(10)]
|
||||
public void Should_get_random_action(int actionNumber)
|
||||
{
|
||||
var target = CreateTarget();
|
||||
var actions = new List<IActionPpc>();
|
||||
for (int i = 0; i < actionNumber; i++)
|
||||
actions.Add(A.Fake<IActionPpc>());
|
||||
|
||||
Check.That(actions.Contains(target.GetAction(actions))).IsTrue();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
using FakeItEasy;
|
||||
using MiniJeuxFinal.Games.PierrePapierCiseaux.Actions;
|
||||
using MiniJeuxFinal.Games.PierrePapierCiseaux.Factories;
|
||||
using MiniJeuxFinal.Games.PierrePapierCiseaux.Players;
|
||||
using NFluent;
|
||||
|
||||
namespace MiniJeuxFinal.Test.Games.PierrePapierCiseaux.Players
|
||||
{
|
||||
public class PlayerPpcTest
|
||||
{
|
||||
private readonly IActionPpcFactory _actionPpcFactory = A.Fake<IActionPpcFactory>();
|
||||
|
||||
|
||||
|
||||
private PlayerPpc CreateTarget() => new PlayerPpc("Paul", _actionPpcFactory);
|
||||
|
||||
|
||||
[Fact]
|
||||
public void Should_initialize_target()
|
||||
{
|
||||
var player = CreateTarget();
|
||||
|
||||
Check.That(player.Name).IsEqualTo("Paul");
|
||||
Check.That(player.ToString()).IsEqualTo("Paul: 0");
|
||||
Check.That(player.Score).IsEqualTo(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_increment_score()
|
||||
{
|
||||
var player = CreateTarget();
|
||||
Check.That(player.Score).IsEqualTo(0);
|
||||
player.IncrementScore();
|
||||
Check.That(player.Score).IsEqualTo(1);
|
||||
player.IncrementScore();
|
||||
player.IncrementScore();
|
||||
Check.That(player.Score).IsEqualTo(3);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_add_a_single_action_and_get()
|
||||
{
|
||||
var player = CreateTarget();
|
||||
var action1 = A.Fake<IActionPpc>();
|
||||
A.CallTo(() => _actionPpcFactory.GetAction(A<IList<IActionPpc>>._)).Returns(action1);
|
||||
player.AddAction(action1);
|
||||
var result = player.Play();
|
||||
|
||||
Check.That(result).IsEqualTo(action1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_add_a_multiple_actions_and_get()
|
||||
{
|
||||
var player = CreateTarget();
|
||||
var action1 = A.Fake<IActionPpc>();
|
||||
var action2 = A.Fake<IActionPpc>();
|
||||
var action3 = A.Fake<IActionPpc>();
|
||||
A.CallTo(() => _actionPpcFactory.GetAction(A<IList<IActionPpc>>._)).Returns(action2);
|
||||
player.AddAction(action1, action2, action3);
|
||||
var result = player.Play();
|
||||
|
||||
Check.That(result).IsEqualTo(action2);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_throw_when_has_no_action()
|
||||
{
|
||||
var player = CreateTarget();
|
||||
Check.ThatCode(() => player.Play()).Throws<InvalidOperationException>();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user