Exemplo n.º 1
0
        public void MultipleVariablesCanBeUnsetAtTheSameTime()
        {
            var count = Variable.Variables.Count;
            var unsetVariable = new UnsetVariable();
            var calculate = new Calculate();

            Assert.AreEqual("x = 2", _inputHandler.HandleInput("set x = 2"));
            Assert.AreEqual("y = 4", _inputHandler.HandleInput("set y = 4"));
            Assert.AreEqual("z = 6", _inputHandler.HandleInput("set z = 6"));
            Assert.AreEqual(count + 3, Variable.Variables.Count);

            Assert.AreEqual("Variable x unset.", _inputHandler.HandleInput("unset x"));
            Assert.Throws<CalculatorException>(() => unsetVariable.HandleInput("unset x"));
            Assert.AreEqual(count + 2, Variable.Variables.Count);

            Assert.AreEqual("Variables z, y unset.", _inputHandler.HandleInput("unset z,    y"));
            Assert.AreEqual(count, Variable.Variables.Count);

            Assert.Throws<CalculatorException>(() => unsetVariable.HandleInput("unset y, z"));
            Assert.Throws<CalculatorException>(() => unsetVariable.HandleInput("unset z"));
            Assert.Throws<CalculatorException>(() => calculate.HandleInput("x"));
            Assert.Throws<CalculatorException>(() => calculate.HandleInput("y"));
            Assert.Throws<CalculatorException>(() => calculate.HandleInput("z"));

            Assert.AreEqual("y = 4", _inputHandler.HandleInput("set y = 4"));
            Assert.AreEqual("z = 6", _inputHandler.HandleInput("set z = 6"));
            Assert.AreEqual("Variables y, z unset.", _inputHandler.HandleInput("unset y;  z"));
        }
Exemplo n.º 2
0
        public void VariablesCanBeUnset()
        {
            var count = Variable.Variables.Count;

            Assert.AreEqual("x = 2", _inputHandler.HandleInput("set x = 2"));
            Assert.AreEqual(count + 1, Variable.Variables.Count);

            Assert.AreEqual("Variable x unset.", _inputHandler.HandleInput("unset x"));
            Assert.AreEqual(count, Variable.Variables.Count);

            var unsetVariable = new UnsetVariable();
            var calculate = new Calculate();

            Assert.Throws<CalculatorException>(() => unsetVariable.HandleInput("unset x"));
            Assert.Throws<CalculatorException>(() => calculate.HandleInput("x"));
        }