| 1 | using System;
|
|---|
| 2 | using System.Collections.Generic;
|
|---|
| 3 | using System.Linq;
|
|---|
| 4 | using System.Text;
|
|---|
| 5 | using NUnit.Framework;
|
|---|
| 6 |
|
|---|
| 7 | namespace DominionEngine.CardInfo.Test
|
|---|
| 8 | {
|
|---|
| 9 | [TestFixture]
|
|---|
| 10 | public class WorthTest
|
|---|
| 11 | {
|
|---|
| 12 | #region Afford
|
|---|
| 13 |
|
|---|
| 14 | [TestCaseSource("IsAffordSource")]
|
|---|
| 15 | public void IsAfford(Worth cost, bool expected)
|
|---|
| 16 | {
|
|---|
| 17 | Worth money = Worth.Coin(3) + Worth.Create<Potion>(1);
|
|---|
| 18 | Assert.That(money.IsAfford(cost), Is.EqualTo(expected));
|
|---|
| 19 | }
|
|---|
| 20 | static object[][] IsAffordSource = new object[][]{
|
|---|
| 21 | new object[]{Worth.Coin(1), true},
|
|---|
| 22 | new object[]{Worth.Coin(2), true},
|
|---|
| 23 | new object[]{Worth.Coin(3), true},
|
|---|
| 24 | new object[]{Worth.Coin(4), false},
|
|---|
| 25 | new object[]{Worth.Create<Potion>(1), true},
|
|---|
| 26 | new object[]{Worth.Create<Potion>(2), false},
|
|---|
| 27 | new object[]{Worth.Coin(1) + Worth.Create<Potion>(1), true},
|
|---|
| 28 | new object[]{Worth.Coin(2) + Worth.Create<Potion>(1), true},
|
|---|
| 29 | new object[]{Worth.Coin(3) + Worth.Create<Potion>(1), true},
|
|---|
| 30 | new object[]{Worth.Coin(4) + Worth.Create<Potion>(1), false},
|
|---|
| 31 | new object[]{Worth.Coin(2) + Worth.Create<Potion>(2), false},
|
|---|
| 32 | };
|
|---|
| 33 |
|
|---|
| 34 | #endregion
|
|---|
| 35 |
|
|---|
| 36 | #region ToString
|
|---|
| 37 |
|
|---|
| 38 | [TestCaseSource("ToStringTestSource")]
|
|---|
| 39 | public void ToStringTest(Worth worth, string expected)
|
|---|
| 40 | {
|
|---|
| 41 | Assert.That(worth.ToString(), Is.EqualTo(expected));
|
|---|
| 42 | }
|
|---|
| 43 | public static object[][] ToStringTestSource = new object[][]{
|
|---|
| 44 | new object[]{Worth.Coin(1), "1C"},
|
|---|
| 45 | new object[]{Worth.Create<Potion>(1), "0C"},
|
|---|
| 46 | new object[]{Worth.Coin(1) + Worth.Create<Potion>(2), "1C"},
|
|---|
| 47 | };
|
|---|
| 48 |
|
|---|
| 49 | #endregion
|
|---|
| 50 |
|
|---|
| 51 | #region MoreThan
|
|---|
| 52 |
|
|---|
| 53 | [Test]
|
|---|
| 54 | public void MoreThan_Worth([Range(0, 10)]int baseCoin, [Range(0, 10)]int moreCoin)
|
|---|
| 55 | {
|
|---|
| 56 | Worth worth = Worth.Coin(baseCoin).MoreThan(Worth.Coin(moreCoin));
|
|---|
| 57 |
|
|---|
| 58 | Assert.That(worth.CoinValue, Is.EqualTo(baseCoin + moreCoin));
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
| 61 | [Test]
|
|---|
| 62 | public void MoreThan_CardInfo([Range(0, 10)]int baseCoin, [Range(0, 10)]int moreCoin)
|
|---|
| 63 | {
|
|---|
| 64 | Worth worth = Worth.Coin(baseCoin).MoreThan(new MockCardInfo(Worth.Coin(moreCoin)));
|
|---|
| 65 |
|
|---|
| 66 | Assert.That(worth.CoinValue, Is.EqualTo(baseCoin + moreCoin));
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | [Test]
|
|---|
| 70 | public void MoreThan_Card([Range(0, 10)]int baseCoin, [Range(0, 10)]int moreCoin)
|
|---|
| 71 | {
|
|---|
| 72 | CardInfo cardInfo = new MockCardInfo(Worth.Coin(moreCoin));
|
|---|
| 73 | Worth worth = Worth.Coin(baseCoin).MoreThan(new Card(cardInfo, CardPosition.Supply));
|
|---|
| 74 |
|
|---|
| 75 | Assert.That(worth.CoinValue, Is.EqualTo(baseCoin + moreCoin));
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | #endregion
|
|---|
| 79 |
|
|---|
| 80 | #region 等価比較
|
|---|
| 81 |
|
|---|
| 82 | [Test]
|
|---|
| 83 | public void EqualsTest([Range(0, 10)]int coin)
|
|---|
| 84 | {
|
|---|
| 85 | Worth worth1 = Worth.Coin(coin);
|
|---|
| 86 | Worth worth2 = Worth.Coin(coin);
|
|---|
| 87 |
|
|---|
| 88 | Assert.That(worth1.Equals(worth2), Is.True);
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | [Test]
|
|---|
| 92 | public void EqualsTest_NotEqual([Range(0, 10)]int coin)
|
|---|
| 93 | {
|
|---|
| 94 | Worth worth1 = Worth.Coin(coin);
|
|---|
| 95 | Worth worth2 = Worth.Coin(coin+1);
|
|---|
| 96 |
|
|---|
| 97 | Assert.That(worth1.Equals(worth2), Is.False);
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | [Test]
|
|---|
| 101 | public void EqualsTest_NotEqual_NoWorth([Range(0, 10)]int coin)
|
|---|
| 102 | {
|
|---|
| 103 | Worth worth1 = Worth.Coin(coin);
|
|---|
| 104 |
|
|---|
| 105 | Assert.That(worth1.Equals(new object()), Is.False);
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | [Test]
|
|---|
| 109 | public void EqualsTest_WithOtherUnit([Range(0, 10)]int coin)
|
|---|
| 110 | {
|
|---|
| 111 | Worth worth1 = Worth.Coin(coin) + Worth.Create<Potion>(1);
|
|---|
| 112 | Worth worth2 = Worth.Create<Potion>(1) + Worth.Coin(coin);
|
|---|
| 113 |
|
|---|
| 114 | Assert.That(worth1, Is.EqualTo(worth2));
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | [Test]
|
|---|
| 118 | public void EqualsTest_WithOtherUnit_NotEqual([Range(0, 10)]int coin)
|
|---|
| 119 | {
|
|---|
| 120 | Worth worth1 = Worth.Coin(coin) + Worth.Create<Potion>(1);
|
|---|
| 121 | Worth worth2 = Worth.Coin(coin);
|
|---|
| 122 |
|
|---|
| 123 | Assert.That(worth1, Is.Not.EqualTo(worth2));
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | [Test]
|
|---|
| 127 | public void GetHashCodeTest([Range(0, 10)]int coin)
|
|---|
| 128 | {
|
|---|
| 129 | Worth worth1 = Worth.Coin(coin);
|
|---|
| 130 | Worth worth2 = Worth.Coin(coin);
|
|---|
| 131 |
|
|---|
| 132 | Assert.That(worth1.GetHashCode(), Is.EqualTo(worth2.GetHashCode()));
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 | [Test]
|
|---|
| 136 | public void GetHashCodeTest_NotEqual([Range(0, 10)]int coin)
|
|---|
| 137 | {
|
|---|
| 138 | Worth worth1 = Worth.Coin(coin);
|
|---|
| 139 | Worth worth2 = Worth.Coin(coin+1);
|
|---|
| 140 |
|
|---|
| 141 | Assert.That(worth1.GetHashCode(), Is.Not.EqualTo(worth2.GetHashCode()));
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|
| 144 | [Test]
|
|---|
| 145 | public void GetHashCodeTest_WithOtherUnit([Range(0, 10)]int coin)
|
|---|
| 146 | {
|
|---|
| 147 | Worth worth1 = Worth.Coin(coin) + Worth.Create<Potion>(1);
|
|---|
| 148 | Worth worth2 = Worth.Create<Potion>(1) + Worth.Coin(coin);
|
|---|
| 149 |
|
|---|
| 150 | Assert.That(worth1.GetHashCode(), Is.EqualTo(worth2.GetHashCode()));
|
|---|
| 151 | }
|
|---|
| 152 |
|
|---|
| 153 | [Test]
|
|---|
| 154 | public void GetHashCodeTest_WithOtherUnit_NotEqual([Range(0, 10)]int coin)
|
|---|
| 155 | {
|
|---|
| 156 | Worth worth1 = Worth.Coin(coin) + Worth.Create<Potion>(1);
|
|---|
| 157 | Worth worth2 = Worth.Coin(coin);
|
|---|
| 158 |
|
|---|
| 159 | Assert.That(worth1.GetHashCode(), Is.Not.EqualTo(worth2.GetHashCode()));
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 | [Test]
|
|---|
| 163 | public void EqualsOperatorTest([Range(0, 10)]int coin)
|
|---|
| 164 | {
|
|---|
| 165 | Worth worth1 = Worth.Coin(coin);
|
|---|
| 166 | Worth worth2 = Worth.Coin(coin);
|
|---|
| 167 |
|
|---|
| 168 | Assert.That((worth1 == worth2), Is.True);
|
|---|
| 169 | }
|
|---|
| 170 |
|
|---|
| 171 | [Test]
|
|---|
| 172 | public void EqualsOperatorTest_Same([Range(0, 10)]int coin)
|
|---|
| 173 | {
|
|---|
| 174 | Worth worth1 = Worth.Coin(coin);
|
|---|
| 175 | Worth worth2 = worth1;
|
|---|
| 176 |
|
|---|
| 177 | Assert.That((worth1 == worth2), Is.True);
|
|---|
| 178 | }
|
|---|
| 179 |
|
|---|
| 180 | [Test]
|
|---|
| 181 | public void EqualsOperatorTest_NotEqual([Range(0, 10)]int coin)
|
|---|
| 182 | {
|
|---|
| 183 | Worth worth1 = Worth.Coin(coin);
|
|---|
| 184 | Worth worth2 = Worth.Coin(coin + 1);
|
|---|
| 185 |
|
|---|
| 186 | Assert.That((worth1 != worth2), Is.True);
|
|---|
| 187 | }
|
|---|
| 188 |
|
|---|
| 189 | #endregion
|
|---|
| 190 |
|
|---|
| 191 | #region 個別の価値
|
|---|
| 192 |
|
|---|
| 193 | [Test]
|
|---|
| 194 | public void CoinValue()
|
|---|
| 195 | {
|
|---|
| 196 | Worth cost = Worth.Coin(3) + Worth.Create<Potion>(2);
|
|---|
| 197 | Assert.That(cost.CoinValue, Is.EqualTo(3));
|
|---|
| 198 | }
|
|---|
| 199 |
|
|---|
| 200 | [Test]
|
|---|
| 201 | public void PotionValue()
|
|---|
| 202 | {
|
|---|
| 203 | Worth cost = Worth.Coin(3) + Worth.Create<Potion>(2);
|
|---|
| 204 | Assert.That(cost.Value<Potion>(), Is.EqualTo(2));
|
|---|
| 205 | }
|
|---|
| 206 |
|
|---|
| 207 | #endregion
|
|---|
| 208 |
|
|---|
| 209 | #region 算術演算子
|
|---|
| 210 |
|
|---|
| 211 | [Test]
|
|---|
| 212 | public void Add()
|
|---|
| 213 | {
|
|---|
| 214 | Worth cost = Worth.Coin(1) + Worth.Coin(1) + Worth.Create<Potion>(1);
|
|---|
| 215 | Assert.That(cost.CoinValue, Is.EqualTo(2));
|
|---|
| 216 | Assert.That(cost.Value<Potion>(), Is.EqualTo(1));
|
|---|
| 217 | }
|
|---|
| 218 |
|
|---|
| 219 | [Test]
|
|---|
| 220 | public void Sub()
|
|---|
| 221 | {
|
|---|
| 222 | Worth cost1 = Worth.Coin(3) + Worth.Create<Potion>(5);
|
|---|
| 223 | Worth cost2 = Worth.Coin(1) + Worth.Create<Potion>(4);
|
|---|
| 224 |
|
|---|
| 225 | Worth cost = cost1 - cost2;
|
|---|
| 226 |
|
|---|
| 227 | Assert.That(cost.CoinValue, Is.EqualTo(2));
|
|---|
| 228 | Assert.That(cost.Value<Potion>(), Is.EqualTo(1));
|
|---|
| 229 | }
|
|---|
| 230 |
|
|---|
| 231 | [Test]
|
|---|
| 232 | public void Sub_NoUnit()
|
|---|
| 233 | {
|
|---|
| 234 | Worth cost1 = Worth.Coin(3);
|
|---|
| 235 | Worth cost2 = Worth.Coin(1) + Worth.Create<Potion>(4);
|
|---|
| 236 |
|
|---|
| 237 | Worth cost = cost1 - cost2;
|
|---|
| 238 |
|
|---|
| 239 | Assert.That(cost.CoinValue, Is.EqualTo(2));
|
|---|
| 240 | Assert.That(cost.Value<Potion>(), Is.EqualTo(-4));
|
|---|
| 241 | }
|
|---|
| 242 |
|
|---|
| 243 | #endregion
|
|---|
| 244 |
|
|---|
| 245 | [Test]
|
|---|
| 246 | public void WorthExtension([Range(0, 10)] int value)
|
|---|
| 247 | {
|
|---|
| 248 | Worth worth = value.Coin();
|
|---|
| 249 | Assert.That(worth.CoinValue, Is.EqualTo(value));
|
|---|
| 250 | }
|
|---|
| 251 |
|
|---|
| 252 | public class Potion : Worth.Unit { }
|
|---|
| 253 | }
|
|---|
| 254 | }
|
|---|