コード例 #1
0
        public void InputCommand_Interpreter_ResultMustBeMessageAboutTheAbsenceOfSuchBuilder()
        {
            var command = "add linear linear(3  2)";
            var builder =
                new Dictionary <string, Func <ICommandBuilder> >()
            {
                [@"^add linear \w+\((-?\d+(,\d+)?) (-?\d+(,\d+)?)\)$"] = () => new AddLinearFunctionBuilderStab()
            };
            var storage     = new FunctionsStorageStab();
            var interpreter = new Interpreter(storage, builder);

            var result = interpreter.SearchMatches(command);

            Assert.Multiple(() =>
            {
                Assert.AreEqual(result.Message, "the command is entered incorrectly");
                Assert.IsFalse(result.Identifier);
            });
        }
コード例 #2
0
        public void InputCommand_Interpreter_ResultMustBeIsTrue()
        {
            var command = "add linear linearA(2 3,1)";
            var builder =
                new Dictionary <string, Func <ICommandBuilder> >()
            {
                [@"^add linear \w+\((-?\d+(,\d+)?) (-?\d+(,\d+)?)\)$"]
                    = () => new AddLinearFunctionBuilderStab()
            };
            var storage     = new FunctionsStorageStab();
            var interpreter = new Interpreter(storage, builder);

            var result = interpreter.SearchMatches(command);

            Assert.Multiple(() =>
            {
                Assert.IsNull(result.Message);
                Assert.IsTrue(result.Identifier);
            });
        }
コード例 #3
0
        public void CalculateFunction_Interpreter_ResultMustBeSumOfNumber()
        {
            var command = "calc Linear(2)";
            var builder =
                new Dictionary <string, Func <ICommandBuilder> >()
            {
                [@"^calc \w+\((-?\d+(,\d+)?)\)$"]
                    = () => new CalculateFunctionBuilderStab()
            };
            var storage     = new FunctionsStorageStab();
            var interpreter = new Interpreter(storage, builder);

            storage.AddFunction("Linear", new LinearFunctionStab(2.3, 3));
            var result = interpreter.SearchMatches(command);

            Assert.Multiple(
                () =>
            {
                Assert.AreEqual(result.Message, "9,9");
                Assert.IsTrue(result.Identifier);
            });
        }
コード例 #4
0
        public void NotImplementedStorageMethod_Interpreter_ResultMustBeExeption()
        {
            var command = "del Linear";
            var message = "Метод или операция не реализована.Void DeleteFunction(System.String)";
            var builder =
                new Dictionary <string, Func <ICommandBuilder> >()
            {
                [@"^del \w+$"]
                    = () => new DeleteFunctionBuilderStab()
            };
            var storage     = new FunctionsStorageStab();
            var interpreter = new Interpreter(storage, builder);

            storage.AddFunction("Linear", new LinearFunctionStab(3, 2));
            var result = interpreter.SearchMatches(command);

            Assert.Multiple(
                () =>
            {
                Assert.AreEqual(result.Message, message);
                Assert.IsFalse(result.Identifier);
            }
                );
        }