Merge pull request 'fix_die_and_faces_structure' (#106) from fix_die_and_faces_structure into main
continuous-integration/drone/push Build is passing Details

Reviewed-on: #106
pull/107/head
Alexis Drai 2 years ago
commit c28a36292a

@ -4,6 +4,7 @@ using Model.Games;
using Model.Players; using Model.Players;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing;
using System.Linq; using System.Linq;
using Data; using Data;
@ -61,7 +62,7 @@ namespace App
Console.WriteLine("make at least one dice group first, then try again"); Console.WriteLine("make at least one dice group first, then try again");
break; break;
} }
IEnumerable<AbstractDie<AbstractDieFace>> newGameDice = PrepareDice(gameRunner); IEnumerable<Die> newGameDice = PrepareDice(gameRunner);
string newGameName; string newGameName;
Console.WriteLine("give this new game a name\n>"); Console.WriteLine("give this new game a name\n>");
@ -83,11 +84,11 @@ namespace App
Console.WriteLine("give this new dice group a name"); Console.WriteLine("give this new dice group a name");
newGroupName = Console.ReadLine(); newGroupName = Console.ReadLine();
List<AbstractDie<AbstractDieFace>> newGroupDice = new(); List<Die> newGroupDice = new();
string menuChoiceNewDice = ""; string menuChoiceNewDice = "";
while (!(menuChoiceNewDice.Equals("ok") && newGroupDice.Any())) while (!(menuChoiceNewDice.Equals("ok") && newGroupDice.Any()))
{ {
AbstractDie<AbstractDieFace> die = null; Die die = null;
Console.WriteLine("create a die you want to add (at least one), or enter 'ok' if you're finished"); Console.WriteLine("create a die you want to add (at least one), or enter 'ok' if you're finished");
Console.WriteLine("what type of die ?\n" + Console.WriteLine("what type of die ?\n" +
"n... number\n" + "n... number\n" +
@ -114,7 +115,7 @@ namespace App
newGroupDice.Add(die); newGroupDice.Add(die);
} }
} }
gameRunner.GlobalDieManager.Add(new KeyValuePair<string, IEnumerable<AbstractDie<AbstractDieFace>>>(newGroupName, newGroupDice)); gameRunner.GlobalDieManager.Add(new KeyValuePair<string, IEnumerable<Die>>(newGroupName, newGroupDice));
break; break;
default: default:
@ -173,7 +174,7 @@ namespace App
private static NumberDie MakeNumberDie() private static NumberDie MakeNumberDie()
{ {
NumberDie die; NumberDie die;
List<NumberDieFace> faces = new(); List<NumberFace> faces = new();
string menuChoiceNewFaces = ""; string menuChoiceNewFaces = "";
while (menuChoiceNewFaces != "ok") while (menuChoiceNewFaces != "ok")
@ -194,14 +195,14 @@ namespace App
private static ColorDie MakeColorDie() private static ColorDie MakeColorDie()
{ {
ColorDie die; ColorDie die;
List<ColorDieFace> faces = new(); List<ColorFace> faces = new();
string menuChoiceNewFaces = ""; string menuChoiceNewFaces = "";
while (!menuChoiceNewFaces.Equals("ok")) while (!menuChoiceNewFaces.Equals("ok"))
{ {
Console.WriteLine("create a face with an color hex code, or enter 'ok' if you're finished"); Console.WriteLine("create a face with an color name, or enter 'ok' if you're finished");
menuChoiceNewFaces = Console.ReadLine(); menuChoiceNewFaces = Console.ReadLine();
if (menuChoiceNewFaces != "ok") faces.Add(new(menuChoiceNewFaces)); if (menuChoiceNewFaces != "ok") faces.Add(new(Color.FromName(menuChoiceNewFaces)));
} }
die = new ColorDie(faces.ToArray()); die = new ColorDie(faces.ToArray());
@ -211,27 +212,41 @@ namespace App
private static ImageDie MakeImageDie() private static ImageDie MakeImageDie()
{ {
ImageDie die; ImageDie die;
List<ImageDieFace> faces = new(); List<ImageFace> faces = new();
string menuChoiceNewFaces = ""; string menuChoiceNewFaces = "";
while (!menuChoiceNewFaces.Equals("ok")) while (!menuChoiceNewFaces.Equals("ok"))
{ {
Console.WriteLine("create a face with an image url, or enter 'ok' if you're finished"); Console.WriteLine("create a face with an image uri, or enter 'ok' if you're finished");
menuChoiceNewFaces = Console.ReadLine(); menuChoiceNewFaces = Console.ReadLine();
if (menuChoiceNewFaces != "ok") faces.Add(new(menuChoiceNewFaces)); if (menuChoiceNewFaces != "ok")
{
try
{
faces.Add(new(new Uri(menuChoiceNewFaces)));
}
catch (ArgumentNullException ex)
{
Console.WriteLine(ex.Message);
}
catch (UriFormatException ex)
{
Console.WriteLine("that URI was not valid");
Console.WriteLine(ex.Message);
}
}
} }
die = new ImageDie(faces.ToArray()); die = new ImageDie(faces.ToArray());
return die; return die;
} }
private static IEnumerable<AbstractDie<AbstractDieFace>> PrepareDice(GameRunner gameRunner) private static IEnumerable<Die> PrepareDice(GameRunner gameRunner)
{ {
List<AbstractDie<AbstractDieFace>> result = new(); List<Die> result = new();
Console.WriteLine("add dice to the game"); Console.WriteLine("add dice to the game");
Console.WriteLine("all known dice or groups of dice:"); Console.WriteLine("all known dice or groups of dice:");
foreach ((string name, IEnumerable<AbstractDie<AbstractDieFace>> dice) in gameRunner.GlobalDieManager.GetAll()) foreach ((string name, IEnumerable<Die> dice) in gameRunner.GlobalDieManager.GetAll())
{ {
Console.WriteLine($"{name} -- {dice}"); Console.WriteLine($"{name} -- {dice}");
} }
@ -243,8 +258,8 @@ namespace App
// no checks, this is temporary // no checks, this is temporary
if (!menuChoiceDice.Equals("ok")) if (!menuChoiceDice.Equals("ok"))
{ {
IEnumerable<AbstractDie<AbstractDieFace>> chosenDice = gameRunner.GlobalDieManager.GetOneByName(menuChoiceDice).Value; IEnumerable<Die> chosenDice = gameRunner.GlobalDieManager.GetOneByName(menuChoiceDice).Value;
foreach (AbstractDie<AbstractDieFace> die in chosenDice) foreach (Die die in chosenDice)
{ {
result.Add(die); result.Add(die);
} }

@ -4,6 +4,7 @@ using Model.Dice.Faces;
using Model.Games; using Model.Games;
using Model.Players; using Model.Players;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing;
namespace Data namespace Data
{ {
@ -20,18 +21,42 @@ namespace Data
gr.GlobalPlayerManager.Add(player3); gr.GlobalPlayerManager.Add(player3);
List<AbstractDie<AbstractDieFace>> monopolyDice = new(); List<Die> monopolyDice = new();
List<AbstractDie<AbstractDieFace>> dndDice = new(); List<Die> dndDice = new();
string monopolyName = "Monopoly", dndName = "DnD"; string monopolyName = "Monopoly", dndName = "DnD";
NumberDieFace[] d6Faces = new NumberDieFace[] { new(1), new(2), new(3), new(4), new(5), new(6) }; NumberFace[] d6Faces = new NumberFace[] { new(1), new(2), new(3), new(4), new(5), new(6) };
monopolyDice.Add(new NumberDie(new NumberFace(1), new NumberFace(1), new NumberFace(1), new NumberFace(1)));
monopolyDice.Add(new NumberDie(d6Faces)); monopolyDice.Add(new NumberDie(d6Faces));
monopolyDice.Add(new NumberDie(d6Faces)); monopolyDice.Add(new NumberDie(d6Faces));
monopolyDice.Add(new ColorDie(new("#ff0000"), new("#00ff00"), new("#0000ff"), new("#ffff00"), new("#000000"), new("#ffffff")));
NumberDieFace[] d20Faces = new NumberDieFace[] { ColorFace[] colorFaces = new ColorFace[]
{
new(Color.FromName("blue")),
new(Color.FromName("red")),
new(Color.FromName("yellow")),
new(Color.FromName("green")),
new(Color.FromName("black")),
new(Color.FromName("white"))
};
monopolyDice.Add(new ColorDie(colorFaces));
string rootPath = "https://unsplash.com/photos/";
ImageFace[] imageFaces = new ImageFace[]
{
new(new Uri(rootPath + "TLD6iCOlyb0")),
new(new Uri(rootPath + "rTZW4f02zY8")),
new(new Uri(rootPath + "Hyu76loQLdk")),
new(new Uri(rootPath + "A_Ncbi-RH6s")),
};
monopolyDice.Add(new ImageDie(imageFaces));
NumberFace[] d20Faces = new NumberFace[] {
new(1), new(2), new(3), new(4), new(5), new(1), new(2), new(3), new(4), new(5),
new(6), new(7), new(8), new(9), new(10), new(6), new(7), new(8), new(9), new(10),
new(11), new(12), new(13), new(14), new(15), new(11), new(12), new(13), new(14), new(15),
@ -40,8 +65,8 @@ namespace Data
dndDice.Add(new NumberDie(d20Faces)); dndDice.Add(new NumberDie(d20Faces));
gr.GlobalDieManager.Add(new KeyValuePair<string, IEnumerable<AbstractDie<AbstractDieFace>>>(dndName, dndDice.AsEnumerable())); gr.GlobalDieManager.Add(new KeyValuePair<string, IEnumerable<Die>>(dndName, dndDice.AsEnumerable()));
gr.GlobalDieManager.Add(new KeyValuePair<string, IEnumerable<AbstractDie<AbstractDieFace>>>(monopolyName, monopolyDice.AsEnumerable())); gr.GlobalDieManager.Add(new KeyValuePair<string, IEnumerable<Die>>(monopolyName, monopolyDice.AsEnumerable()));
string game1 = "Forgotten Realms", game2 = "4e", game3 = "The Coopers"; string game1 = "Forgotten Realms", game2 = "4e", game3 = "The Coopers";

@ -1,25 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Model.Dice.Faces;
namespace Model.Dice
{
public abstract class AbstractDie<T> : RandomnessHaver where T : AbstractDieFace
{
public IEnumerable<T> ListFaces => listFaces;
private readonly List<T> listFaces = new();
protected AbstractDie(params T[] faces)
{
listFaces.AddRange(faces);
}
public T GetRandomFace()
{
int faceIndex = rnd.Next(0, ListFaces.Count());
return ListFaces.ElementAt(faceIndex);
}
}
}

@ -1,18 +1,13 @@
using Model.Dice.Faces; using Model.Dice.Faces;
using System; using System.Drawing;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model.Dice namespace Model.Dice
{ {
public class ColorDie : AbstractDie<AbstractDieFace> public class ColorDie : HomogeneousDie<Color>
{ {
public ColorDie(params ColorDieFace[] faces) : base(faces) public ColorDie(params ColorFace[] faces) : base(faces)
{ {
} }
} }
} }

@ -0,0 +1,27 @@
using Model.Dice.Faces;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Model.Dice
{
public abstract class Die
{
public IEnumerable<Face> Faces => faces;
protected static readonly Random rnd = new();
private readonly List<Face> faces = new();
protected Die(params Face[] faces)
{
this.faces.AddRange(faces);
}
public virtual Face GetRandomFace()
{
int faceIndex = rnd.Next(0, Faces.Count());
return Faces.ElementAt(faceIndex);
}
}
}

@ -1,83 +1,85 @@
using Model.Dice.Faces; using Model.Dice.Faces;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
namespace Model.Dice namespace Model.Dice
{ {
public class DieManager : IManager<KeyValuePair<string, IEnumerable<AbstractDie<AbstractDieFace>>>> public class DieManager : IManager<KeyValuePair<string, IEnumerable<Die>>>
{ {
private readonly Dictionary<string, IEnumerable<AbstractDie<AbstractDieFace>>> diceGroups = new(); private readonly Dictionary<string, IEnumerable<Die>> diceGroups = new();
public KeyValuePair<string, IEnumerable<AbstractDie<AbstractDieFace>>> Add(KeyValuePair<string, IEnumerable<AbstractDie<AbstractDieFace>>> toAdd) public KeyValuePair<string, IEnumerable<Die>> Add(KeyValuePair<string, IEnumerable<Die>> toAdd)
{ {
// on trim la clé d'abord // on trim la clé d'abord
if (string.IsNullOrWhiteSpace(toAdd.Key)) if (string.IsNullOrWhiteSpace(toAdd.Key))
{ {
throw new ArgumentNullException(nameof(toAdd), "param should not be null or empty"); throw new ArgumentNullException(nameof(toAdd), "param should not be null or empty");
} }
if (diceGroups.Contains(toAdd)) if (diceGroups.Contains(toAdd))
{ {
throw new ArgumentException("this username is already taken", nameof(toAdd)); throw new ArgumentException("this username is already taken", nameof(toAdd));
} }
diceGroups.Add(toAdd.Key.Trim(), toAdd.Value); diceGroups.Add(toAdd.Key.Trim(), toAdd.Value);
return toAdd; return toAdd;
} }
public IEnumerable<KeyValuePair<string, IEnumerable<AbstractDie<AbstractDieFace>>>> GetAll() public IEnumerable<KeyValuePair<string, IEnumerable<Die>>> GetAll()
{ {
return diceGroups.AsEnumerable(); return diceGroups.AsEnumerable();
} }
public KeyValuePair<string, IEnumerable<AbstractDie<AbstractDieFace>>> GetOneByID(Guid ID) public KeyValuePair<string, IEnumerable<Die>> GetOneByID(Guid ID)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public KeyValuePair<string, IEnumerable<AbstractDie<AbstractDieFace>>> GetOneByName(string name) public KeyValuePair<string, IEnumerable<Die>> GetOneByName(string name)
{ {
// les groupes de dés nommés : // les groupes de dés nommés :
// ils sont case-sensistive, mais "mon jeu" == "mon jeu " == " mon jeu" // ils sont case-sensistive, mais "mon jeu" == "mon jeu " == " mon jeu"
if (string.IsNullOrWhiteSpace(name)) if (string.IsNullOrWhiteSpace(name))
{ {
throw new ArgumentNullException(nameof(name), "param should not be null or empty"); throw new ArgumentNullException(nameof(name), "param should not be null or empty");
} }
else else
{ {
return new KeyValuePair<string, IEnumerable<AbstractDie<AbstractDieFace>>>(name, diceGroups[name]); return new KeyValuePair<string, IEnumerable<Die>>(name, diceGroups[name]);
} }
} }
public void Remove(KeyValuePair<string, IEnumerable<AbstractDie<AbstractDieFace>>> toRemove) public void Remove(KeyValuePair<string, IEnumerable<Die>> toRemove)
{ {
if (toRemove.Key is null) if (toRemove.Key is null)
{ {
throw new ArgumentNullException(nameof(toRemove), "param should not be null"); throw new ArgumentNullException(nameof(toRemove), "param should not be null");
} }
else else
{ {
diceGroups.Remove(toRemove.Key); diceGroups.Remove(toRemove.Key);
} }
} }
public KeyValuePair<string, IEnumerable<AbstractDie<AbstractDieFace>>> Update(KeyValuePair<string, IEnumerable<AbstractDie<AbstractDieFace>>> before, KeyValuePair<string, IEnumerable<AbstractDie<AbstractDieFace>>> after) public KeyValuePair<string, IEnumerable<Die>> Update(KeyValuePair<string, IEnumerable<Die>> before, KeyValuePair<string, IEnumerable<Die>> after)
{ {
// pas autorisé de changer les dés, juste le nom // pas autorisé de changer les dés, juste le nom
if (!before.Value.Equals(after.Value)) if (!before.Value.Equals(after.Value))
{ {
if (string.IsNullOrWhiteSpace(before.Key) || string.IsNullOrWhiteSpace(after.Key)) if (string.IsNullOrWhiteSpace(before.Key) || string.IsNullOrWhiteSpace(after.Key))
{ {
throw new ArgumentNullException(nameof(before), "dice group name should not be null or empty"); throw new ArgumentNullException(nameof(before), "dice group name should not be null or empty");
} }
diceGroups.Remove(before.Key); diceGroups.Remove(before.Key);
diceGroups.Add(after.Key, after.Value); diceGroups.Add(after.Key, after.Value);
return after; return after;
} }
return before; return before;
} }
}
}
}
}

@ -1,26 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model.Dice.Faces
{
public abstract class AbstractDieFace
{
/// <summary>
/// every die face has a value, and they can all be represented by an int,
/// even if they're not litterally a decimal number
/// <br/>
/// USE GetPracticalValue for a Value specific to face type
/// </summary>
public int Value { get; protected set; }
public abstract object GetPracticalValue();
public override string ToString()
{
return GetPracticalValue().ToString();
}
}
}

@ -1,45 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model.Dice.Faces
{
public class ColorDieFace : AbstractDieFace
{
private static readonly int MAX_HEX = 16777215;
/// <summary>
/// accepts hex strings like "ffbb84" and "#af567d" ([RRGGBB])
/// </summary>
/// <param name="hexValueString">hex string</param>
public ColorDieFace(string hexValueString)
{
// https://stackoverflow.com/questions/1139957/convert-integer-to-hexadecimal-and-back-again
// we remove any initial '#' before parsing
if (hexValueString.StartsWith('#'))
{
hexValueString = hexValueString[1..];
}
int result = int.Parse(hexValueString, System.Globalization.NumberStyles.HexNumber);
if (result < 0) Value = 0;
else if (result > MAX_HEX) Value = MAX_HEX;
else Value = result;
}
/// <summary>
/// accepts a decimal value that represents a color hex (0 is black, 65280 is green...)
/// </summary>
/// <param name="decimalValue"></param>
public ColorDieFace(int decimalValue)
: this(decimalValue.ToString())
{ }
public override object GetPracticalValue()
{
// https://stackoverflow.com/questions/1139957/convert-integer-to-hexadecimal-and-back-again
return Value.ToString("X6").Insert(0, "#");
}
}
}

@ -0,0 +1,11 @@
using System.Drawing;
namespace Model.Dice.Faces
{
public class ColorFace : Face<Color>
{
public ColorFace(Color value) : base(value)
{
}
}
}

@ -0,0 +1,28 @@
namespace Model.Dice.Faces
{
public abstract class Face
{
public string StringValue { get; protected set; }
public override string ToString()
{
return StringValue;
}
}
public abstract class Face<T> : Face
{
public T Value { get; protected set; }
protected Face(T value)
{
Value = value;
StringValue = value.ToString();
}
protected Face(T value, string stringValue)
{
Value = value;
StringValue = stringValue;
}
}
}

@ -1,27 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model.Dice.Faces
{
public class ImageDieFace : AbstractDieFace
{
public ImageDieFace(string uri)
{
Value = int.Parse(Path.GetFileNameWithoutExtension(uri));
}
public ImageDieFace(int code)
{
Value = code;
}
public override object GetPracticalValue()
{
return string.Format($"Assets/images/{Value}.png");
}
}
}

@ -0,0 +1,11 @@
using System;
namespace Model.Dice.Faces
{
public class ImageFace : Face<Uri>
{
public ImageFace(Uri value) : base(value)
{
}
}
}

@ -1,21 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model.Dice.Faces
{
public class NumberDieFace : AbstractDieFace
{
public NumberDieFace(int value)
{
Value = value;
}
public override object GetPracticalValue()
{
return Value;
}
}
}

@ -0,0 +1,9 @@
namespace Model.Dice.Faces
{
public class NumberFace : Face<int>
{
public NumberFace(int value) : base(value)
{
}
}
}

@ -0,0 +1,16 @@
using Model.Dice.Faces;
namespace Model.Dice
{
public abstract class HomogeneousDie<T> : Die
{
protected HomogeneousDie(params Face<T>[] faces) : base(faces)
{
}
public override Face<T> GetRandomFace()
{
return (Face<T>)base.GetRandomFace();
}
}
}

@ -1,15 +1,11 @@
using Model.Dice.Faces; using Model.Dice.Faces;
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model.Dice namespace Model.Dice
{ {
public class ImageDie : AbstractDie<AbstractDieFace> public class ImageDie : HomogeneousDie<Uri>
{ {
public ImageDie(params ImageDieFace[] faces) : base(faces) public ImageDie(params ImageFace[] faces) : base(faces)
{ {
} }
} }

@ -7,9 +7,9 @@ using System.Threading.Tasks;
namespace Model.Dice namespace Model.Dice
{ {
public class NumberDie : AbstractDie<AbstractDieFace> public class NumberDie : HomogeneousDie<int>
{ {
public NumberDie(params NumberDieFace[] faces) : base(faces) public NumberDie(params NumberFace[] faces) : base(faces)
{ {
} }
} }

@ -1,16 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model.Dice
{
public class RandomnessHaver
{
protected RandomnessHaver()
{
}
protected static readonly Random rnd = new();
}
}

@ -57,8 +57,8 @@ namespace Model.Games
/// <summary> /// <summary>
/// the group of dice used for this game /// the group of dice used for this game
/// </summary> /// </summary>
public IEnumerable<AbstractDie<AbstractDieFace>> Dice => dice; public IEnumerable<Die> Dice => dice;
private readonly IEnumerable<AbstractDie<AbstractDieFace>> dice; private readonly IEnumerable<Die> dice;
/// <summary> /// <summary>
/// constructs a Game with its own history of Turns. /// constructs a Game with its own history of Turns.
@ -68,7 +68,7 @@ namespace Model.Games
/// <param name="turns">the turns that have been done so far</param> /// <param name="turns">the turns that have been done so far</param>
/// <param name="playerManager">the game's player manager, doing CRUD on players and switching whose turn it is</param> /// <param name="playerManager">the game's player manager, doing CRUD on players and switching whose turn it is</param>
/// <param name="favGroup">the group of dice used for this game</param> /// <param name="favGroup">the group of dice used for this game</param>
public Game(string name, IManager<Player> playerManager, IEnumerable<AbstractDie<AbstractDieFace>> dice, IEnumerable<Turn> turns) public Game(string name, IManager<Player> playerManager, IEnumerable<Die> dice, IEnumerable<Turn> turns)
{ {
Name = name; Name = name;
PlayerManager = playerManager; PlayerManager = playerManager;
@ -83,7 +83,7 @@ namespace Model.Games
/// <param name="name">the name of the game 😎</param> /// <param name="name">the name of the game 😎</param>
/// <param name="playerManager">the game's player manager, doing CRUD on players and switching whose turn it is</param> /// <param name="playerManager">the game's player manager, doing CRUD on players and switching whose turn it is</param>
/// <param name="favGroup">the group of dice used for this game</param> /// <param name="favGroup">the group of dice used for this game</param>
public Game(string name, IManager<Player> playerManager, IEnumerable<AbstractDie<AbstractDieFace>> dice) public Game(string name, IManager<Player> playerManager, IEnumerable<Die> dice)
: this(name, playerManager, dice, null) : this(name, playerManager, dice, null)
{ } { }
@ -161,10 +161,10 @@ namespace Model.Games
/// throws all the Dice in FavGroup and returns a list of their Faces /// throws all the Dice in FavGroup and returns a list of their Faces
/// </summary> /// </summary>
/// <returns>list of AbstractDieFaces after a throw</returns> /// <returns>list of AbstractDieFaces after a throw</returns>
private Dictionary<AbstractDie<AbstractDieFace>, AbstractDieFace> ThrowAll() private Dictionary<Die, Face> ThrowAll()
{ {
Dictionary<AbstractDie<AbstractDieFace>, AbstractDieFace> faces = new(); Dictionary<Die, Face> faces = new();
foreach (AbstractDie<AbstractDieFace> die in dice) foreach (Die die in dice)
{ {
faces.Add(die, die.GetRandomFace()); faces.Add(die, die.GetRandomFace());
} }

@ -12,17 +12,17 @@ namespace Model.Games
public class GameRunner : IManager<Game> public class GameRunner : IManager<Game>
{ {
public IManager<Player> GlobalPlayerManager { get; private set; } public IManager<Player> GlobalPlayerManager { get; private set; }
public IManager<KeyValuePair<string, IEnumerable<AbstractDie<AbstractDieFace>>>> GlobalDieManager { get; private set; } public IManager<KeyValuePair<string, IEnumerable<Die>>> GlobalDieManager { get; private set; }
private readonly List<Game> games; private readonly List<Game> games;
public GameRunner(IManager<Player> globalPlayerManager, IManager<KeyValuePair<string, IEnumerable<AbstractDie<AbstractDieFace>>>> globalDieManager, List<Game> games) public GameRunner(IManager<Player> globalPlayerManager, IManager<KeyValuePair<string, IEnumerable<Die>>> globalDieManager, List<Game> games)
{ {
GlobalPlayerManager = globalPlayerManager; GlobalPlayerManager = globalPlayerManager;
GlobalDieManager = globalDieManager; GlobalDieManager = globalDieManager;
this.games = games ?? new(); this.games = games ?? new();
} }
public GameRunner(IManager<Player> globalPlayerManager, IManager<KeyValuePair<string, IEnumerable<AbstractDie<AbstractDieFace>>>> globalDieManager) public GameRunner(IManager<Player> globalPlayerManager, IManager<KeyValuePair<string, IEnumerable<Die>>> globalDieManager)
: this(globalPlayerManager, globalDieManager, null){ } : this(globalPlayerManager, globalDieManager, null){ }
@ -65,7 +65,7 @@ namespace Model.Games
/// <summary> /// <summary>
/// creates a new game /// creates a new game
/// </summary> /// </summary>
public Game StartNewGame(string name, IManager<Player> playerManager, IEnumerable<AbstractDie<AbstractDieFace>> dice) public Game StartNewGame(string name, IManager<Player> playerManager, IEnumerable<Die> dice)
{ {
Game game = new(name, playerManager, dice); Game game = new(name, playerManager, dice);
return Add(game); return Add(game);

@ -1,7 +1,5 @@
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Model.Dice; using Model.Dice;
@ -33,8 +31,8 @@ namespace Model.Games
/// <summary> /// <summary>
/// the collection of Face that were rolled /// the collection of Face that were rolled
/// </summary> /// </summary>
public IEnumerable<KeyValuePair<AbstractDie<AbstractDieFace>, AbstractDieFace>> DiceNFaces => diceNFaces.AsEnumerable(); public IEnumerable<KeyValuePair<Die, Face>> DiceNFaces => diceNFaces.AsEnumerable();
private readonly Dictionary<AbstractDie<AbstractDieFace>, AbstractDieFace> diceNFaces; private readonly Dictionary<Die, Face> diceNFaces;
/// <summary> /// <summary>
/// this private constructor is to be used only by factories /// this private constructor is to be used only by factories
@ -42,7 +40,7 @@ namespace Model.Games
/// <param name="when">date and time of the turn</param> /// <param name="when">date and time of the turn</param>
/// <param name="player">player who played the turn</param> /// <param name="player">player who played the turn</param>
/// <param name="faces">faces that were rolled</param> /// <param name="faces">faces that were rolled</param>
private Turn(DateTime when, Player player, Dictionary<AbstractDie<AbstractDieFace>, AbstractDieFace> diceNFaces) private Turn(DateTime when, Player player, Dictionary<Die, Face> diceNFaces)
{ {
When = when; When = when;
Player = player; Player = player;
@ -59,7 +57,7 @@ namespace Model.Games
/// <param name="player">player who played the turn</param> /// <param name="player">player who played the turn</param>
/// <param name="faces">faces that were rolled</param> /// <param name="faces">faces that were rolled</param>
/// <returns>a new Turn object</returns> /// <returns>a new Turn object</returns>
public static Turn CreateWithSpecifiedTime(DateTime when, Player player, Dictionary<AbstractDie<AbstractDieFace>, AbstractDieFace> diceNFaces) public static Turn CreateWithSpecifiedTime(DateTime when, Player player, Dictionary<Die, Face> diceNFaces)
{ {
if (player is null) if (player is null)
{ {
@ -87,7 +85,7 @@ namespace Model.Games
/// <param name="player">player who played the turn</param> /// <param name="player">player who played the turn</param>
/// <param name="faces">faces that were rolled</param> /// <param name="faces">faces that were rolled</param>
/// <returns>a new Turn object</returns> /// <returns>a new Turn object</returns>
public static Turn CreateWithDefaultTime(Player player, Dictionary<AbstractDie<AbstractDieFace>, AbstractDieFace> diceNFaces) public static Turn CreateWithDefaultTime(Player player, Dictionary<Die, Face> diceNFaces)
{ {
return CreateWithSpecifiedTime(DateTime.UtcNow, player, diceNFaces); return CreateWithSpecifiedTime(DateTime.UtcNow, player, diceNFaces);
} }
@ -108,7 +106,7 @@ namespace Model.Games
date, date,
time, time,
Player.ToString()); Player.ToString());
foreach (AbstractDieFace face in this.diceNFaces.Values) foreach (Face face in this.diceNFaces.Values)
{ {
sb.Append(" " + face.ToString()); sb.Append(" " + face.ToString());
} }

@ -1,4 +1,5 @@
using Model.Dice; using Data;
using Model.Dice;
using Model.Dice.Faces; using Model.Dice.Faces;
using Model.Games; using Model.Games;
using Model.Players; using Model.Players;
@ -12,50 +13,26 @@ namespace Tests.Model_UTs.Games
{ {
public class GameTest public class GameTest
{ {
private readonly GameRunner stubGameRunner = new Stub().LoadApp();
private static readonly string GAME_NAME = "my game"; private static readonly string GAME_NAME = "my game";
private static readonly Player PLAYER_1 = new("Alice"), PLAYER_2 = new("Bob"), PLAYER_3 = new("Clyde"); private static readonly Player PLAYER_1 = new("Alice"), PLAYER_2 = new("Bob"), PLAYER_3 = new("Clyde");
private readonly IEnumerable<Die> DICE_1, DICE_2;
private readonly static NumberDieFace FACE_NUM = new(1); public GameTest()
private readonly static ImageDieFace FACE_IMG = new(10);
private readonly static ColorDieFace FACE_CLR = new(1000);
private readonly static NumberDieFace[] FACES_1 = new NumberDieFace[]
{
FACE_NUM,
new(2),
new(3),
new(4)
};
private readonly static ImageDieFace[] FACES_2 = new ImageDieFace[]
{ {
FACE_IMG, DICE_1 = stubGameRunner.GlobalDieManager.GetAll().First().Value;
new(20), DICE_2 = stubGameRunner.GlobalDieManager.GetAll().Last().Value;
new(30), }
new(40)
};
private readonly static ColorDieFace[] FACES_3 = new ColorDieFace[]
{
FACE_CLR,
new(2000),
new(3000),
new(4000)
};
private static readonly AbstractDie<AbstractDieFace> NUM = new NumberDie(FACES_1), IMG = new ImageDie(FACES_2), CLR = new ColorDie(FACES_3);
private static readonly IEnumerable<AbstractDie<AbstractDieFace>> DICE =
new List<AbstractDie<AbstractDieFace>>() { NUM, IMG, CLR }
.AsEnumerable();
[Fact] [Fact]
public void TestNamePropertyGet() public void TestNamePropertyGet()
{ {
// Arrange // Arrange
Game game = new(name: GAME_NAME, playerManager: new PlayerManager(), dice: DICE); Game game = new(name: GAME_NAME,
playerManager: new PlayerManager(),
dice: DICE_1);
// Act // Act
string actual = game.Name; string actual = game.Name;
@ -68,9 +45,11 @@ namespace Tests.Model_UTs.Games
public void TestNamePropertySetWhenValidThenCorrect() public void TestNamePropertySetWhenValidThenCorrect()
{ {
// Arrange // Arrange
Game game = new(name: GAME_NAME, playerManager: new PlayerManager(), dice: DICE); Game game = new(name: GAME_NAME,
string expected = "shitty marmot"; playerManager: new PlayerManager(),
dice: DICE_1);
string expected = "shitty marmot";
// Act // Act
game.Name = expected; game.Name = expected;
@ -90,7 +69,9 @@ namespace Tests.Model_UTs.Games
Game game; Game game;
// Act // Act
void action() => game = new(name: name, playerManager: new PlayerManager(), dice: DICE); void action() => game = new(name: name,
playerManager: new PlayerManager(),
dice: DICE_1);
// Assert // Assert
Assert.Throws<ArgumentException>(action); Assert.Throws<ArgumentException>(action);
@ -100,12 +81,7 @@ namespace Tests.Model_UTs.Games
public void TestGetHistory() public void TestGetHistory()
{ {
// Arrange // Arrange
Dictionary<AbstractDie<AbstractDieFace>, AbstractDieFace> diceNFaces = new() Dictionary<Die, Face> diceNFaces = (Dictionary<Die, Face>)stubGameRunner.GetAll().First().GetHistory().First().DiceNFaces;
{
{ CLR, FACE_CLR },
{ IMG, FACE_IMG },
{ NUM, FACE_NUM }
};
Turn turn1 = Turn.CreateWithDefaultTime(PLAYER_1, diceNFaces); Turn turn1 = Turn.CreateWithDefaultTime(PLAYER_1, diceNFaces);
Turn turn2 = Turn.CreateWithDefaultTime(PLAYER_2, diceNFaces); // yeah they rolled the same Turn turn2 = Turn.CreateWithDefaultTime(PLAYER_2, diceNFaces); // yeah they rolled the same
@ -113,7 +89,11 @@ namespace Tests.Model_UTs.Games
IEnumerable<Turn> expected = new List<Turn>() { turn1, turn2 }; IEnumerable<Turn> expected = new List<Turn>() { turn1, turn2 };
// Act // Act
Game game = new(name: GAME_NAME, playerManager: new PlayerManager(), dice: DICE, expected); Game game = new(name: GAME_NAME,
playerManager: new PlayerManager(),
dice: DICE_1,
expected);
IEnumerable<Turn> actual = game.GetHistory(); IEnumerable<Turn> actual = game.GetHistory();
// Assert // Assert
@ -124,12 +104,14 @@ namespace Tests.Model_UTs.Games
public void TestDicePropertyGet() public void TestDicePropertyGet()
{ {
// Arrange // Arrange
Game game = new(name: GAME_NAME, playerManager: new PlayerManager(), dice: DICE); Game game = new(name: GAME_NAME,
playerManager: new PlayerManager(),
dice: DICE_2);
// Act // Act
IEnumerable<AbstractDie<AbstractDieFace>> actual = game.Dice; IEnumerable<Die> actual = game.Dice;
IEnumerable<AbstractDie<AbstractDieFace>> expected = DICE; IEnumerable<Die> expected = DICE_2;
// Assert // Assert
Assert.Equal(expected, actual); Assert.Equal(expected, actual);
@ -139,7 +121,10 @@ namespace Tests.Model_UTs.Games
public void TestPerformTurnDoesAddOneTurn() public void TestPerformTurnDoesAddOneTurn()
{ {
// Arrange // Arrange
Game game = new(name: GAME_NAME, playerManager: new PlayerManager(), dice: DICE); Game game = new(name: GAME_NAME,
playerManager: new PlayerManager(),
dice: DICE_1);
game.PlayerManager.Add(PLAYER_1); game.PlayerManager.Add(PLAYER_1);
game.PlayerManager.Add(PLAYER_2); game.PlayerManager.Add(PLAYER_2);
@ -167,7 +152,10 @@ namespace Tests.Model_UTs.Games
public void TestGetWhoPlaysNowWhenValidThenCorrect() public void TestGetWhoPlaysNowWhenValidThenCorrect()
{ {
// Arrange // Arrange
Game game = new(name: GAME_NAME, playerManager: new PlayerManager(), dice: DICE); Game game = new(name: GAME_NAME,
playerManager: new PlayerManager(),
dice: DICE_1);
game.PlayerManager.Add(PLAYER_1); game.PlayerManager.Add(PLAYER_1);
game.PlayerManager.Add(PLAYER_2); game.PlayerManager.Add(PLAYER_2);
@ -190,7 +178,9 @@ namespace Tests.Model_UTs.Games
public void TestGetWhoPlaysNowWhenInvalidThenException() public void TestGetWhoPlaysNowWhenInvalidThenException()
{ {
// Arrange // Arrange
Game game = new(name: GAME_NAME, playerManager: new PlayerManager(), dice: DICE); Game game = new(name: GAME_NAME,
playerManager: new PlayerManager(),
dice: DICE_1);
// Act // Act
void action() => game.GetWhoPlaysNow(); // on an empty collection of players void action() => game.GetWhoPlaysNow(); // on an empty collection of players
@ -203,8 +193,9 @@ namespace Tests.Model_UTs.Games
public void TestPrepareNextPlayerWhenEmptyThenException() public void TestPrepareNextPlayerWhenEmptyThenException()
{ {
// Arrange // Arrange
Game game = new(name: GAME_NAME, playerManager: new PlayerManager(), dice: DICE); Game game = new(name: GAME_NAME,
playerManager: new PlayerManager(),
dice: DICE_1);
// Act // Act
void action() => game.PrepareNextPlayer(PLAYER_1); // on an empty collection of players void action() => game.PrepareNextPlayer(PLAYER_1); // on an empty collection of players
@ -216,7 +207,10 @@ namespace Tests.Model_UTs.Games
public void TestPrepareNextPlayerWhenNullThenException() public void TestPrepareNextPlayerWhenNullThenException()
{ {
// Arrange // Arrange
Game game = new(name: GAME_NAME, playerManager: new PlayerManager(), dice: DICE); Game game = new(name: GAME_NAME,
playerManager: new PlayerManager(),
dice: DICE_2);
game.PlayerManager.Add(PLAYER_1); game.PlayerManager.Add(PLAYER_1);
// Act // Act
@ -230,7 +224,10 @@ namespace Tests.Model_UTs.Games
public void TestPrepareNextPlayerWhenNonExistentThenException() public void TestPrepareNextPlayerWhenNonExistentThenException()
{ {
// Arrange // Arrange
Game game = new(name: GAME_NAME, playerManager: new PlayerManager(), dice: DICE); Game game = new(name: GAME_NAME,
playerManager: new PlayerManager(),
dice: DICE_1);
game.PlayerManager.Add(PLAYER_2); game.PlayerManager.Add(PLAYER_2);
// Act // Act
@ -244,7 +241,10 @@ namespace Tests.Model_UTs.Games
public void TestPrepareNextPlayerWhenValidThenCorrectWithSeveralPlayers() public void TestPrepareNextPlayerWhenValidThenCorrectWithSeveralPlayers()
{ {
// Arrange // Arrange
Game game = new(name: GAME_NAME, playerManager: new PlayerManager(), dice: DICE); Game game = new(name: GAME_NAME,
playerManager: new PlayerManager(),
dice: DICE_2);
game.PlayerManager.Add(PLAYER_1); game.PlayerManager.Add(PLAYER_1);
game.PlayerManager.Add(PLAYER_2); game.PlayerManager.Add(PLAYER_2);
@ -264,7 +264,10 @@ namespace Tests.Model_UTs.Games
public void TestPrepareNextPlayerWhenValidThenCorrectWithOnePlayer() public void TestPrepareNextPlayerWhenValidThenCorrectWithOnePlayer()
{ {
// Arrange // Arrange
Game game = new(name: GAME_NAME, playerManager: new PlayerManager(), dice: DICE); Game game = new(name: GAME_NAME,
playerManager: new PlayerManager(),
dice: DICE_1);
game.PlayerManager.Add(PLAYER_1); game.PlayerManager.Add(PLAYER_1);
// Act // Act
@ -283,7 +286,9 @@ namespace Tests.Model_UTs.Games
public void TestAddPlayerToGame() public void TestAddPlayerToGame()
{ {
// Arrange // Arrange
Game game = new(name: GAME_NAME, playerManager: new PlayerManager(), dice: DICE); Game game = new(name: GAME_NAME,
playerManager: new PlayerManager(),
dice: DICE_2);
// Act // Act
Player expected = PLAYER_1; Player expected = PLAYER_1;
@ -297,7 +302,9 @@ namespace Tests.Model_UTs.Games
public void TestGetPlayersFromGame() public void TestGetPlayersFromGame()
{ {
// Arrange // Arrange
Game game = new(name: GAME_NAME, playerManager: new PlayerManager(), dice: DICE); Game game = new(name: GAME_NAME,
playerManager: new PlayerManager(),
dice: DICE_1);
// Act // Act
Assert.Empty(game.PlayerManager.GetAll()); Assert.Empty(game.PlayerManager.GetAll());
@ -311,7 +318,10 @@ namespace Tests.Model_UTs.Games
public void TestUpdatePlayerInGame() public void TestUpdatePlayerInGame()
{ {
// Arrange // Arrange
Game game = new(name: GAME_NAME, playerManager: new PlayerManager(), dice: DICE); Game game = new(name: GAME_NAME,
playerManager: new PlayerManager(),
dice: DICE_2);
game.PlayerManager.Add(PLAYER_1); game.PlayerManager.Add(PLAYER_1);
// Act // Act
@ -326,7 +336,10 @@ namespace Tests.Model_UTs.Games
public void TestRemovePlayerFromGame() public void TestRemovePlayerFromGame()
{ {
// Arrange // Arrange
Game game = new(name: GAME_NAME, playerManager: new PlayerManager(), dice: DICE); Game game = new(name: GAME_NAME,
playerManager: new PlayerManager(),
dice: DICE_1);
game.PlayerManager.Add(PLAYER_1); game.PlayerManager.Add(PLAYER_1);
game.PlayerManager.Add(PLAYER_2); game.PlayerManager.Add(PLAYER_2);
game.PlayerManager.Remove(PLAYER_1); game.PlayerManager.Remove(PLAYER_1);
@ -338,54 +351,5 @@ namespace Tests.Model_UTs.Games
// Assert // Assert
Assert.Equal(expected, actual); Assert.Equal(expected, actual);
} }
[Fact]
public void TestToString()
{
// Arrange
DateTime dateTime = DateTime.UtcNow;
List<Turn> turns = new()
{
Turn.CreateWithSpecifiedTime(dateTime, PLAYER_1, new()
{
{NUM, new NumberDieFace(4)},
{IMG, new ImageDieFace(40)},
{CLR, new ColorDieFace("A00FA0")},
}),
Turn.CreateWithSpecifiedTime(dateTime, PLAYER_2, new()
{
{NUM, new NumberDieFace(3)},
{IMG, new ImageDieFace(20)},
{CLR, new ColorDieFace("A00BB8")},
}),
};
Game game = new(name: GAME_NAME, playerManager: new PlayerManager(), dice: DICE, turns: turns);
game.PlayerManager.Add(PLAYER_1);
game.PlayerManager.Add(PLAYER_2);
// Act
string[] dateTimeString = dateTime.ToString("s", System.Globalization.CultureInfo.InvariantCulture).Split("T");
string date = dateTimeString[0];
string time = dateTimeString[1];
string expected =
"Game: my game" +
"\nPlayers: Alice Bob" +
"\nNext: Alice" +
"\nLog:" +
"\n\t" + date + " " + time + " -- Alice rolled: 4 Assets/images/40.png #A00FA0" +
"\n\t" + date + " " + time + " -- Bob rolled: 3 Assets/images/20.png #A00BB8" +
"\n";
string actual = game.ToString();
Debug.WriteLine("expected:\n" + expected);
Debug.WriteLine("actual:\n" + actual);
// Assert
Assert.Equal(expected, actual);
}
} }
} }

@ -1,4 +1,5 @@
using Model.Dice; using Data;
using Model.Dice;
using Model.Dice.Faces; using Model.Dice.Faces;
using Model.Games; using Model.Games;
using Model.Players; using Model.Players;
@ -8,74 +9,21 @@ using System.Diagnostics;
using System.Linq; using System.Linq;
using Xunit; using Xunit;
namespace Tests.Model_UTs.Games namespace Tests.Model_UTs.Games
{ {
public class TurnTest public class TurnTest
{ {
private readonly Dictionary<AbstractDie<AbstractDieFace>, AbstractDieFace> DICE_N_FACES_1; private readonly GameRunner stubGameRunner = new Stub().LoadApp();
private readonly Dictionary<AbstractDie<AbstractDieFace>, AbstractDieFace> DICE_N_FACES_2;
private static readonly AbstractDieFace FACE_ONE = new NumberDieFace(1); Dictionary<Die, Face> DICE_N_FACES_1, DICE_N_FACES_2;
private static readonly AbstractDieFace FACE_TWO = new NumberDieFace(12);
private static readonly AbstractDieFace FACE_THREE = new ImageDieFace(54);
private static readonly AbstractDieFace FACE_FOUR = new ColorDieFace(16548);
private readonly static NumberDieFace[] FACES1 = new NumberDieFace[]
{
FACE_ONE as NumberDieFace,
new NumberDieFace(2),
new NumberDieFace(3),
new NumberDieFace(4)
};
private readonly static NumberDieFace[] FACES2 = new NumberDieFace[] {
new NumberDieFace(9),
new NumberDieFace(10),
new NumberDieFace(11),
FACE_TWO as NumberDieFace,
new NumberDieFace(13),
new NumberDieFace(14)
};
private readonly static ImageDieFace[] FACES3 = new ImageDieFace[] {
new ImageDieFace(13),
new ImageDieFace(27),
new ImageDieFace(38),
FACE_THREE as ImageDieFace
};
private readonly static ColorDieFace[] FACES4 = new ColorDieFace[] {
new(11651),
new(24651),
FACE_FOUR as ColorDieFace,
new(412)
};
private readonly AbstractDie<AbstractDieFace> NUM1 = new NumberDie(FACES1);
private readonly AbstractDie<AbstractDieFace> NUM2 = new NumberDie(FACES2);
private readonly AbstractDie<AbstractDieFace> IMG1 = new ImageDie(FACES3);
private readonly AbstractDie<AbstractDieFace> CLR1 = new ColorDie(FACES4);
public TurnTest() public TurnTest()
{ {
DICE_N_FACES_1 = new() DICE_N_FACES_1 = (Dictionary<Die, Face>)stubGameRunner.GetAll().First().GetHistory().First().DiceNFaces;
{ DICE_N_FACES_2 = (Dictionary<Die, Face>)stubGameRunner.GetAll().Last().GetHistory().Last().DiceNFaces;
{ NUM1, FACE_ONE },
{ NUM2, FACE_TWO },
{ IMG1, FACE_THREE },
{ CLR1, FACE_FOUR }
};
DICE_N_FACES_2 = new()
{
{ NUM1, FACE_TWO },
{ IMG1, FACE_THREE },
{ CLR1, FACE_FOUR }
};
} }
[Fact] [Fact]
public void TestCreateWithSpecifiedTimeNotUTCThenValid() public void TestCreateWithSpecifiedTimeNotUTCThenValid()
{ {
@ -171,31 +119,6 @@ namespace Tests.Model_UTs.Games
// N.B.: might fail between 11:59:59PM and 00:00:00AM // N.B.: might fail between 11:59:59PM and 00:00:00AM
} }
[Fact]
public void TestToStringValidIfAllNormal()
{
// Arrange
DateTime dateTime = new(year: 2018, month: 06, day: 15, hour: 16, minute: 30, second: 0, kind: DateTimeKind.Utc);
string name = "Bobby";
Player player = new(name);
string expected = $"2018-06-15 16:30:00 -- {name} rolled: "
+ FACE_ONE.ToString() + " "
+ FACE_TWO.ToString() + " "
+ FACE_THREE.ToString() + " "
+ FACE_FOUR.ToString();
Turn turn = Turn.CreateWithSpecifiedTime(dateTime, player, DICE_N_FACES_1);
// Act
string actual = turn.ToString();
Debug.WriteLine(actual);
// Assert
Assert.Equal(expected, actual);
}
[Fact] [Fact]
public void TestDiceNFacesProperty() public void TestDiceNFacesProperty()
{ {
@ -204,12 +127,12 @@ namespace Tests.Model_UTs.Games
// Act // Act
Turn turn = Turn.CreateWithDefaultTime(player, DICE_N_FACES_1); Turn turn = Turn.CreateWithDefaultTime(player, DICE_N_FACES_1);
IEnumerable<KeyValuePair<AbstractDie<AbstractDieFace>, AbstractDieFace>> expected = DICE_N_FACES_1.AsEnumerable(); IEnumerable<KeyValuePair<Die, Face>> expected = DICE_N_FACES_1.AsEnumerable();
// Assert // Assert
Assert.Equal(expected, turn.DiceNFaces); Assert.Equal(expected, turn.DiceNFaces);
} }
[Fact] [Fact]
public void TestEqualsFalseIfNotTurn() public void TestEqualsFalseIfNotTurn()
{ {
@ -233,7 +156,7 @@ namespace Tests.Model_UTs.Games
public void TestGoesThruToSecondMethodIfObjIsTypeTurn() public void TestGoesThruToSecondMethodIfObjIsTypeTurn()
{ {
// Arrange // Arrange
object t1; object t1;
Turn t2; Turn t2;
Player player1 = new Player("Marvin"); Player player1 = new Player("Marvin");
Player player2 = new Player("Noah"); Player player2 = new Player("Noah");
@ -254,8 +177,8 @@ namespace Tests.Model_UTs.Games
public void TestEqualsFalseIfNotSamePlayer() public void TestEqualsFalseIfNotSamePlayer()
{ {
// Arrange // Arrange
Player player1 = new("Panama"); Player player1 = new("Panama");
Player player2 = new("Clyde"); Player player2 = new("Clyde");
// Act // Act
Turn t1 = Turn.CreateWithDefaultTime(player1, DICE_N_FACES_2); Turn t1 = Turn.CreateWithDefaultTime(player1, DICE_N_FACES_2);
@ -266,8 +189,8 @@ namespace Tests.Model_UTs.Games
Assert.False(t1.GetHashCode().Equals(t2.GetHashCode())); Assert.False(t1.GetHashCode().Equals(t2.GetHashCode()));
Assert.False(t2.Equals(t1)); Assert.False(t2.Equals(t1));
Assert.False(t2.GetHashCode().Equals(t1.GetHashCode())); Assert.False(t2.GetHashCode().Equals(t1.GetHashCode()));
} }
[Fact] [Fact]
public void TestEqualsFalseIfNotSameTime() public void TestEqualsFalseIfNotSameTime()
{ {
@ -283,8 +206,8 @@ namespace Tests.Model_UTs.Games
Assert.False(t1.GetHashCode().Equals(t2.GetHashCode())); Assert.False(t1.GetHashCode().Equals(t2.GetHashCode()));
Assert.False(t2.Equals(t1)); Assert.False(t2.Equals(t1));
Assert.False(t2.GetHashCode().Equals(t1.GetHashCode())); Assert.False(t2.GetHashCode().Equals(t1.GetHashCode()));
} }
[Fact] [Fact]
public void TestEqualsFalseIfNotSameDiceNFaces() public void TestEqualsFalseIfNotSameDiceNFaces()
{ {

Loading…
Cancel
Save