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"));
        }
示例#2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="InputHandler"/> class.
 /// </summary>
 public InputHandler()
 {
     _fraction = new Fraction();
     _setVariable = new SetVariable();
     _unsetVariable = new UnsetVariable();
     _variables = new Variables();
     _calculate = new Calculate();
     _help = new Help();
 }
        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"));
        }