コード例 #1
0
        public void TestFromInstructions()
        {
            var interpreter = IoCInitialization
                              .InitiateIoc()
                              .Resolve <LanguageInterpreter>();

            interpreter.Add("glob is I");
            interpreter.Add("prok is V");
            interpreter.Add("pish is X");
            interpreter.Add("tegj is L");

            interpreter.Add("glob glob Silver is 34 Credits");
            interpreter.Add("glob prok Gold is 57800 Credits");
            interpreter.Add("pish pish Iron is 3910 Credits");

            Assert.AreEqual(
                "pish tegj glob glob is 42",
                interpreter.Add("how much is pish tegj glob glob ?"));
            Assert.AreEqual(
                "glob prok Silver is 68 Credits",
                interpreter.Add("how many Credits is glob prok Silver ?"));
            Assert.AreEqual(
                "glob prok Gold is 57800 Credits",
                interpreter.Add("how many Credits is glob prok Gold ?"));
            Assert.AreEqual(
                "glob prok Iron is 782 Credits",
                interpreter.Add("how many Credits is glob prok Iron ?"));
            Assert.AreEqual(
                "I have no idea what you are talking about",
                interpreter.Add("how much wood could a woodchuck chuck if a woodchuck could chuck wood ?"));
        }
コード例 #2
0
        public void UnitDeclaration_DoesNotProduceOutput()
        {
            var interpreter = IoCInitialization
                              .InitiateIoc()
                              .Resolve <LanguageInterpreter>();

            Assert.IsNull(interpreter.Add("glob is I"));
        }
コード例 #3
0
        public void AddingCommodity_DoesNotProduceOutput()
        {
            var interpreter = IoCInitialization
                              .InitiateIoc()
                              .Resolve <LanguageInterpreter>();

            interpreter.Add("glob is I");
            Assert.IsNull(interpreter.Add("glob glob Silver is 34 Credits"));
        }
コード例 #4
0
        public void UnknownQuery_ReceivesDefaultResponse()
        {
            var interpreter = IoCInitialization
                              .InitiateIoc()
                              .Resolve <LanguageInterpreter>();

            Assert.AreEqual(
                "I have no idea what you are talking about",
                interpreter.Add("how much wood could a woodchuck chuck if a woodchuck could chuck wood ?"));
        }
コード例 #5
0
        public void WhenInputIsNullOrEmpty_Throws()
        {
            var interpreter = IoCInitialization
                              .InitiateIoc()
                              .Resolve <LanguageInterpreter>();

            Assert.Throws <ArgumentNullException>(() => interpreter.Add(null));
            Assert.Throws <ArgumentNullException>(() => interpreter.Add(string.Empty));
            Assert.Throws <ArgumentNullException>(() => interpreter.Add(" "));
        }
コード例 #6
0
        public void QueryingForArabic_ReturnsConversionsBasedOnRegisteredSymbols()
        {
            var interpreter = IoCInitialization
                              .InitiateIoc()
                              .Resolve <LanguageInterpreter>();

            InitializeSymbols(interpreter);

            Assert.AreEqual(
                "pish tegj glob glob is 42",
                interpreter.Add("how much is pish tegj glob glob ?"));
        }
コード例 #7
0
        public void QueryingForCommodity_ReturnsPriceOfChosenAmountOfSelectedProduct()
        {
            var interpreter = IoCInitialization
                              .InitiateIoc()
                              .Resolve <LanguageInterpreter>();

            InitializeSymbols(interpreter);
            InitializeCommodities(interpreter);

            Assert.AreEqual(
                "glob prok Silver is 68 Credits",
                interpreter.Add("how many Credits is glob prok Silver ?"));
        }
コード例 #8
0
        public void QueryForCommodityConversion_ConvertsOneToTheOther()
        {
            var interpreter = IoCInitialization
                              .InitiateIoc()
                              .Resolve <LanguageInterpreter>();

            interpreter.Add("prok is V");
            interpreter.Add("glob is I");
            interpreter.Add("glob glob Silver is 34 Credits");
            interpreter.Add("glob prok Gold is 57800 Credits");

            Assert.AreEqual(
                "glob Gold is 850 Silver",
                interpreter.Add("how many Silver is glob Gold ?"));
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: zkosior/GalaxyMarket
        private static void Main(string[] args)
        {
            try
            {
                if (ValidateParameters(args))
                {
                    using (var input = new StreamReader(InputFile.OpenRead()))
                        using (var output = new StreamWriter(OutputFile.OpenWrite()))
                        {
                            var interpreter = IoCInitialization.InitiateIoc()
                                              .Resolve <LanguageInterpreter>();
                            while (!input.EndOfStream)
                            {
                                var inputLine  = input.ReadLine();
                                var outputLine = interpreter.Add(inputLine);
                                if (outputLine != null)
                                {
                                    output.WriteLine(outputLine);
                                }
                                output.Flush();
                            }
                        }

                    Console.WriteLine("Finished.");
                }
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception exception)
            {
                // not all exception can be caught here and not all should be,
                // but right here I just want to gracefully exit application
                Console.WriteLine(exception.Message);
            }
#pragma warning restore CA1031 // Do not catch general exception types

            Console.ReadKey();
        }