コード例 #1
0
        public void TestCalculate()
        {
            ICalculator calculator = new RomanCalculator();

            Assert.AreEqual(calculator.Calculate(commands[0], romanSymbolDefinition), 5331);

            Assert.AreEqual(
                Assert.ThrowsException <Exception>(
                    () => calculator.Calculate(commands[1], romanSymbolDefinition)).Message,
                "V can not be subtracted");

            Assert.AreEqual(
                Assert.ThrowsException <Exception>(
                    () => calculator.Calculate(commands[2], romanSymbolDefinition)).Message,
                "I can not be subtracted from L");

            Assert.AreEqual(
                Assert.ThrowsException <Exception>(
                    () => calculator.Calculate(commands[3], romanSymbolDefinition)).Message,
                "D can not be repeated");

            Assert.AreEqual(
                Assert.ThrowsException <Exception>(
                    () => calculator.Calculate(commands[4], romanSymbolDefinition)).Message,
                "Symbols must be placed in order of value, starting with the largest values");

            Assert.AreEqual(
                Assert.ThrowsException <Exception>(
                    () => calculator.Calculate(commands[5], romanSymbolDefinition)).Message,
                "The symbols can be repeated three times in succession, but no more");

            Assert.AreEqual(
                Assert.ThrowsException <Exception>(
                    () => calculator.Calculate(commands[6], romanSymbolDefinition)).Message,
                "Invalid Symbol");
        }