root/lang/csharp/DominionEngine/DominionEngine.CardInfo.Test/Unit/WorthTest.cs @ 37465

Revision 37465, 4.1 kB (checked in by isaisstillalive, 4 years ago)
  • カードの情報を記述するCardInfo系をコミット
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using NUnit.Framework;
6
7namespace 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.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.Potion(1), true},
26            new object[]{Worth.Potion(2), false},
27            new object[]{Worth.Coin(1) + Worth.Potion(1), true},
28            new object[]{Worth.Coin(2) + Worth.Potion(1), true},
29            new object[]{Worth.Coin(3) + Worth.Potion(1), true},
30            new object[]{Worth.Coin(4) + Worth.Potion(1), false},
31            new object[]{Worth.Coin(2) + Worth.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 0P"},
45            new object[]{Worth.Potion(1), "0C 1P"},
46            new object[]{Worth.Coin(1) + Worth.Potion(2), "1C 2P"},
47        };
48
49        #endregion
50
51        #region 比較
52
53        [TestCaseSource("CompareToTestSource")]
54        public void CompareToTest(Worth worth1, Worth worth2)
55        {
56            Assert.That(worth1.CompareTo(worth1), Is.EqualTo(0));
57            Assert.That(worth1.CompareTo(worth2), Is.EqualTo(-1));
58            Assert.That(worth2.CompareTo(worth1), Is.EqualTo(1));
59            Assert.That(worth2.CompareTo(worth2), Is.EqualTo(0));
60        }
61        public static object[][] CompareToTestSource = new object[][]{
62            new object[]{Worth.Coin(1), Worth.Coin(2)},
63            new object[]{Worth.Coin(1), Worth.Coin(3)},
64            new object[]{Worth.Coin(1), Worth.Coin(4)},
65            new object[]{Worth.Coin(2), Worth.Coin(3)},
66            new object[]{Worth.Coin(1), Worth.Coin(1) + Worth.Potion(1)},
67            new object[]{Worth.Potion(1), Worth.Coin(1)},
68            new object[]{Worth.Potion(1), Worth.Coin(1) + Worth.Potion(1)},
69            new object[]{Worth.Potion(1), Worth.Potion(2)},
70            new object[]{Worth.Coin(1) + Worth.Potion(1), Worth.Coin(1) + Worth.Potion(2)},
71            new object[]{Worth.Coin(1) + Worth.Potion(1), Worth.Coin(2) + Worth.Potion(1)},
72            new object[]{Worth.Coin(1) + Worth.Potion(2), Worth.Coin(2) + Worth.Potion(1)},
73        };
74
75        #endregion
76
77        #region 個別の価値
78
79        [Test]
80        public void CoinValue()
81        {
82            Worth cost = Worth.Coin(3) + Worth.Potion(2);
83            Assert.That(cost.CoinValue, Is.EqualTo(3));
84        }
85
86        [Test]
87        public void PotionValue()
88        {
89            Worth cost = Worth.Coin(3) + Worth.Potion(2);
90            Assert.That(cost.PotionValue, Is.EqualTo(2));
91        }
92
93        #endregion
94
95        #region 算術演算子
96
97        [Test]
98        public void Add()
99        {
100            Worth cost = Worth.Coin(1) + Worth.Coin(1) + Worth.Potion(1);
101            Assert.That(cost.CoinValue, Is.EqualTo(2));
102            Assert.That(cost.PotionValue, Is.EqualTo(1));
103        }
104
105        [Test]
106        public void Sub()
107        {
108            Worth cost1 = Worth.Coin(3) + Worth.Potion(5);
109            Worth cost2 = Worth.Coin(1) + Worth.Potion(4);
110
111            Worth cost = cost1 - cost2;
112
113            Assert.That(cost.CoinValue, Is.EqualTo(2));
114            Assert.That(cost.PotionValue, Is.EqualTo(1));
115        }
116
117        #endregion
118    }
119}
Note: See TracBrowser for help on using the browser.