using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using RuleOfReady.Core.DomainModels;
namespace RuleOfReady.Core.Test.DomainModelTest
{
[TestClass]
public class MahjongTileTests
{
[TestMethod]
public void SuitTileEquality()
{
MahjongSuitTile bam4 = new MahjongSuitTile(MahjongSuitType.Bamboo, MahjongSuitNumber.Four);
MahjongSuitTile dot5 = new MahjongSuitTile(MahjongSuitType.Dot, MahjongSuitNumber.Five);
MahjongSuitTile anotherBam4 = new MahjongSuitTile(MahjongSuitType.Bamboo, MahjongSuitNumber.Four);
MahjongSuitTile redDot5 = new MahjongSuitTile(MahjongSuitType.Dot, MahjongSuitNumber.Five, isRedBonus: true);
MahjongSuitTile dot5int = new MahjongSuitTile(MahjongSuitType.Dot, 5);
Assert.AreNotEqual(bam4, dot5);
Assert.AreEqual(bam4, anotherBam4);
Assert.AreEqual(bam4, bam4);
Assert.AreEqual(dot5, redDot5);
Assert.AreNotEqual(bam4, redDot5);
Assert.AreEqual(dot5, dot5int);
MahjongSuitTile bam5 = new MahjongSuitTile(MahjongSuitType.Bamboo, MahjongSuitNumber.Five);
Assert.AreNotEqual(bam4, bam5);
Assert.IsTrue(bam4 == anotherBam4);
Assert.IsFalse(bam4 == redDot5);
Assert.IsFalse(dot5 != redDot5);
}
[TestMethod]
public void HonorTileEquality()
{
MahjongHonorTile rd = new MahjongHonorTile(MahjongHonorType.RedDragon);
MahjongHonorTile redDragon = new MahjongHonorTile(MahjongHonorType.RedDragon);
MahjongHonorTile eastWind = new MahjongHonorTile(MahjongHonorType.EastWind);
Assert.AreEqual(rd, redDragon);
Assert.AreNotEqual(redDragon, eastWind);
Assert.IsTrue(rd == redDragon);
Assert.IsFalse(rd == eastWind);
}
[TestMethod]
public void TileEquality()
{
MahjongTile dot5 = new MahjongSuitTile(MahjongSuitType.Dot, MahjongSuitNumber.Five);
MahjongTile redDot5 = new MahjongSuitTile(MahjongSuitType.Dot, MahjongSuitNumber.Five, isRedBonus: true);
Assert.AreEqual(dot5, redDot5);
Assert.IsTrue(dot5 == redDot5);
}
[TestMethod]
public void HonorTileCompare()
{
MahjongHonorTile whiteDragon = new MahjongHonorTile(MahjongHonorType.WhiteDragon);
MahjongHonorTile westWind = new MahjongHonorTile(MahjongHonorType.WestWind);
MahjongHonorTile anotherWhiteDragon = new MahjongHonorTile(MahjongHonorType.WhiteDragon);
Assert.IsTrue(whiteDragon.CompareTo(westWind) > 0);
Assert.IsTrue(whiteDragon.CompareTo(anotherWhiteDragon) == 0);
Assert.IsTrue(whiteDragon > westWind);
Assert.IsTrue(whiteDragon <= anotherWhiteDragon && whiteDragon >= anotherWhiteDragon);
}
[TestMethod]
public void SuitTileCompare()
{
MahjongSuitTile char3 = new MahjongSuitTile(MahjongSuitType.Character, MahjongSuitNumber.Three);
MahjongSuitTile char5 = new MahjongSuitTile(MahjongSuitType.Character, MahjongSuitNumber.Five);
MahjongSuitTile bam1 = new MahjongSuitTile(MahjongSuitType.Bamboo, MahjongSuitNumber.One);
MahjongSuitTile dot1 = new MahjongSuitTile(MahjongSuitType.Dot, MahjongSuitNumber.One);
MahjongSuitTile anotherDot1 = new MahjongSuitTile(MahjongSuitType.Dot, MahjongSuitNumber.One);
Assert.IsTrue(char3.CompareTo(char5) < 0);
Assert.IsTrue(bam1.CompareTo(dot1) < 0);
Assert.IsTrue(dot1.CompareTo(char3) > 0);
Assert.IsTrue(dot1.CompareTo(anotherDot1) == 0);
Assert.IsTrue(char3 < char5);
Assert.IsTrue(bam1 < dot1);
Assert.IsTrue(dot1 > char3);
Assert.IsTrue(dot1 <= anotherDot1 && dot1 >= anotherDot1);
}
[TestMethod]
public void TileCompare()
{
MahjongTile eastWind = new MahjongHonorTile(MahjongHonorType.EastWind);
MahjongTile dot9 = new MahjongSuitTile(MahjongSuitType.Dot, MahjongSuitNumber.Nine);
MahjongTile anotherEastWind = new MahjongHonorTile(MahjongHonorType.EastWind);
MahjongTile anotherDot9 = new MahjongSuitTile(MahjongSuitType.Dot, MahjongSuitNumber.Nine);
Assert.IsTrue(eastWind.CompareTo(dot9) > 0);
Assert.IsTrue(eastWind.CompareTo(anotherEastWind) == 0);
Assert.IsTrue(dot9.CompareTo(anotherDot9) == 0);
Assert.IsTrue(eastWind > dot9);
Assert.IsTrue(eastWind <= anotherEastWind && eastWind >= anotherEastWind);
Assert.IsTrue(dot9 <= anotherDot9 && dot9 >= anotherDot9);
}
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void ExceptionForBadSuitValue()
{
try
{
MahjongTile badTile = new MahjongSuitTile(MahjongSuitType.Bamboo, 20);
}
catch(ArgumentException ex)
{
Assert.IsTrue(ex.ParamName == "suitNumber");
throw;
}
}
[TestMethod]
public void TileHashCodesUnique()
{
HashSet<MahjongTile> tileTypes = new HashSet<MahjongTile>();
this.AddEveryTile(tileTypes);
Assert.IsTrue(tileTypes.Count == 34);
this.AddEveryTile(tileTypes);
Assert.IsTrue(tileTypes.Count == 34);
this.CheckForEveryTile(tileTypes);
}
private void AddEveryTile(ICollection<MahjongTile> tileTypes)
{
tileTypes.Add(new MahjongSuitTile(MahjongSuitType.Bamboo, 1));
tileTypes.Add(new MahjongSuitTile(MahjongSuitType.Bamboo, 2));
tileTypes.Add(new MahjongSuitTile(MahjongSuitType.Bamboo, 3));
tileTypes.Add(new MahjongSuitTile(MahjongSuitType.Bamboo, 4));
tileTypes.Add(new MahjongSuitTile(MahjongSuitType.Bamboo, 5));
tileTypes.Add(new MahjongSuitTile(MahjongSuitType.Bamboo, 6));
tileTypes.Add(new MahjongSuitTile(MahjongSuitType.Bamboo, 7));
tileTypes.Add(new MahjongSuitTile(MahjongSuitType.Bamboo, 8));
tileTypes.Add(new MahjongSuitTile(MahjongSuitType.Bamboo, 9));
tileTypes.Add(new MahjongSuitTile(MahjongSuitType.Character, 1));
tileTypes.Add(new MahjongSuitTile(MahjongSuitType.Character, 2));
tileTypes.Add(new MahjongSuitTile(MahjongSuitType.Character, 3));
tileTypes.Add(new MahjongSuitTile(MahjongSuitType.Character, 4));
tileTypes.Add(new MahjongSuitTile(MahjongSuitType.Character, 5));
tileTypes.Add(new MahjongSuitTile(MahjongSuitType.Character, 6));
tileTypes.Add(new MahjongSuitTile(MahjongSuitType.Character, 7));
tileTypes.Add(new MahjongSuitTile(MahjongSuitType.Character, 8));
tileTypes.Add(new MahjongSuitTile(MahjongSuitType.Character, 9));
tileTypes.Add(new MahjongSuitTile(MahjongSuitType.Dot, 1));
tileTypes.Add(new MahjongSuitTile(MahjongSuitType.Dot, 2));
tileTypes.Add(new MahjongSuitTile(MahjongSuitType.Dot, 3));
tileTypes.Add(new MahjongSuitTile(MahjongSuitType.Dot, 4));
tileTypes.Add(new MahjongSuitTile(MahjongSuitType.Dot, 5));
tileTypes.Add(new MahjongSuitTile(MahjongSuitType.Dot, 6));
tileTypes.Add(new MahjongSuitTile(MahjongSuitType.Dot, 7));
tileTypes.Add(new MahjongSuitTile(MahjongSuitType.Dot, 8));
tileTypes.Add(new MahjongSuitTile(MahjongSuitType.Dot, 9));
tileTypes.Add(new MahjongHonorTile(MahjongHonorType.EastWind));
tileTypes.Add(new MahjongHonorTile(MahjongHonorType.SouthWind));
tileTypes.Add(new MahjongHonorTile(MahjongHonorType.WestWind));
tileTypes.Add(new MahjongHonorTile(MahjongHonorType.NorthWind));
tileTypes.Add(new MahjongHonorTile(MahjongHonorType.RedDragon));
tileTypes.Add(new MahjongHonorTile(MahjongHonorType.WhiteDragon));
tileTypes.Add(new MahjongHonorTile(MahjongHonorType.GreenDragon));
}
private void CheckForEveryTile(ICollection<MahjongTile> tileTypes)
{
Assert.IsTrue(tileTypes.Contains(new MahjongSuitTile(MahjongSuitType.Bamboo, 1)));
Assert.IsTrue(tileTypes.Contains(new MahjongSuitTile(MahjongSuitType.Bamboo, 2)));
Assert.IsTrue(tileTypes.Contains(new MahjongSuitTile(MahjongSuitType.Bamboo, 3)));
Assert.IsTrue(tileTypes.Contains(new MahjongSuitTile(MahjongSuitType.Bamboo, 4)));
Assert.IsTrue(tileTypes.Contains(new MahjongSuitTile(MahjongSuitType.Bamboo, 5)));
Assert.IsTrue(tileTypes.Contains(new MahjongSuitTile(MahjongSuitType.Bamboo, 6)));
Assert.IsTrue(tileTypes.Contains(new MahjongSuitTile(MahjongSuitType.Bamboo, 7)));
Assert.IsTrue(tileTypes.Contains(new MahjongSuitTile(MahjongSuitType.Bamboo, 8)));
Assert.IsTrue(tileTypes.Contains(new MahjongSuitTile(MahjongSuitType.Bamboo, 9)));
Assert.IsTrue(tileTypes.Contains(new MahjongSuitTile(MahjongSuitType.Character, 1)));
Assert.IsTrue(tileTypes.Contains(new MahjongSuitTile(MahjongSuitType.Character, 2)));
Assert.IsTrue(tileTypes.Contains(new MahjongSuitTile(MahjongSuitType.Character, 3)));
Assert.IsTrue(tileTypes.Contains(new MahjongSuitTile(MahjongSuitType.Character, 4)));
Assert.IsTrue(tileTypes.Contains(new MahjongSuitTile(MahjongSuitType.Character, 5)));
Assert.IsTrue(tileTypes.Contains(new MahjongSuitTile(MahjongSuitType.Character, 6)));
Assert.IsTrue(tileTypes.Contains(new MahjongSuitTile(MahjongSuitType.Character, 7)));
Assert.IsTrue(tileTypes.Contains(new MahjongSuitTile(MahjongSuitType.Character, 8)));
Assert.IsTrue(tileTypes.Contains(new MahjongSuitTile(MahjongSuitType.Character, 9)));
Assert.IsTrue(tileTypes.Contains(new MahjongSuitTile(MahjongSuitType.Dot, 1)));
Assert.IsTrue(tileTypes.Contains(new MahjongSuitTile(MahjongSuitType.Dot, 2)));
Assert.IsTrue(tileTypes.Contains(new MahjongSuitTile(MahjongSuitType.Dot, 3)));
Assert.IsTrue(tileTypes.Contains(new MahjongSuitTile(MahjongSuitType.Dot, 4)));
Assert.IsTrue(tileTypes.Contains(new MahjongSuitTile(MahjongSuitType.Dot, 5)));
Assert.IsTrue(tileTypes.Contains(new MahjongSuitTile(MahjongSuitType.Dot, 6)));
Assert.IsTrue(tileTypes.Contains(new MahjongSuitTile(MahjongSuitType.Dot, 7)));
Assert.IsTrue(tileTypes.Contains(new MahjongSuitTile(MahjongSuitType.Dot, 8)));
Assert.IsTrue(tileTypes.Contains(new MahjongSuitTile(MahjongSuitType.Dot, 9)));
Assert.IsTrue(tileTypes.Contains(new MahjongHonorTile(MahjongHonorType.EastWind)));
Assert.IsTrue(tileTypes.Contains(new MahjongHonorTile(MahjongHonorType.SouthWind)));
Assert.IsTrue(tileTypes.Contains(new MahjongHonorTile(MahjongHonorType.WestWind)));
Assert.IsTrue(tileTypes.Contains(new MahjongHonorTile(MahjongHonorType.NorthWind)));
Assert.IsTrue(tileTypes.Contains(new MahjongHonorTile(MahjongHonorType.RedDragon)));
Assert.IsTrue(tileTypes.Contains(new MahjongHonorTile(MahjongHonorType.WhiteDragon)));
Assert.IsTrue(tileTypes.Contains(new MahjongHonorTile(MahjongHonorType.GreenDragon)));
}
}
}