Beispiel #1
0
        public void CalculateTaxTest5()
        {
            decimal   shelfPrice = -43.57m; bool isImported = false; bool isExempted = false;
            Evaluater evaluater = new Evaluater();

            Assert.ThrowsException <ShelfPriceNegetiveException>(() => evaluater.CalculateTaxForItem(shelfPrice, isImported, isExempted), "Exception for negetive shelf price was not thrown");
        }
Beispiel #2
0
        public void TestOr()
        {
            Tokens tokens = new Tokens();

            tokens.AddToken(new WordToken("word1"));
            tokens.AddToken(new WordToken("word2"));
            tokens.AddToken(new WordToken("word4"));
            tokens.AddToken(new WordToken("word6"));
            tokens.AddToken(new WordToken("word8"));

            Parser parse = new Parser(tokens);
            Node   root  = parse.BinaryTree.root;

            Evaluater     eval = new Evaluater(root, index);
            List <string> res  = eval.result.ToList <string>();

            Assert.IsNotNull(res);
            Assert.Contains("doc1", res);
            Assert.Contains("doc2", res);
            Assert.Contains("doc3", res);
            Assert.Contains("doc4", res);
            Assert.Contains("doc6", res);
            Assert.AreEqual(5, res.Count);
            Assert.AreNotEqual(2, res.Count);
        }
Beispiel #3
0
        public HomeController()
        {
            Parser parse = new Parser(tokens);
            Node   root  = parse.BinaryTree.root;

            Evaluater     eval = new Evaluater(root, index);
            List <string> res  = eval.result.ToList <string>();
        }
Beispiel #4
0
        public void CalculateTaxTest4()
        {
            decimal   shelfPrice = 43.57m; bool isImported = false; bool isExempted = false;
            decimal   expected  = 4.35m;
            Evaluater evaluater = new Evaluater();
            decimal   actual    = evaluater.CalculateTaxForItem(shelfPrice, isImported, isExempted);

            Assert.AreEqual(expected, actual, "The actual calculated tax and expected tax are not equal");
        }
        public void TotalCostTest3()
        {
            List <decimal> sampleItems = new List <decimal>()
            {
                102134.25m, 82132.75m, 100023.15m
            };
            decimal   expectedSum = 284290.15m;
            Evaluater evaluater   = new Evaluater();
            decimal   actualSum   = evaluater.CalculateSum(sampleItems);

            Assert.AreEqual(expectedSum, actualSum, "The actual sum of costs and expected sum of taxes are not equal");
        }
        public void TotalCostTest2()
        {
            List <decimal> sampleItems = new List <decimal>()
            {
                1.15m, 1.39m, 2.38m, 12.84m
            };
            decimal   expectedSum = 17.76m;
            Evaluater evaluater   = new Evaluater();
            decimal   actualSum   = evaluater.CalculateSum(sampleItems);

            Assert.AreEqual(expectedSum, actualSum, "The actual sum of costs and expected sum of taxes are not equal");
        }
        public void TotalCostTest1()
        {
            List <decimal> sampleItems = new List <decimal>()
            {
                0.15m, 0.25m, 0.12m
            };
            decimal   expectedSum = 0.52m;
            Evaluater evaluater   = new Evaluater();
            decimal   actualSum   = evaluater.CalculateSum(sampleItems);

            Assert.AreEqual(expectedSum, actualSum, "The actual sum of costs and expected sum of taxes are not equal");
        }
Beispiel #8
0
        public void Invalidate(string reason)
        {
            if (!Valid)
            {
                throw new Exception("double invalidation?");
            }
            Evaluater.IncrementInvalidCount(reason);

            _feedback = new Feedback {
                Grade = 0f, InvalidReason = reason
            };
            Valid = false;
            Logger.Log($"{SubmissionID} invalid: {reason}");
        }
Beispiel #9
0
        public void TestAndNot()
        {
            Tokens tokens = new Tokens();

            tokens.AddToken(new ParenthesisBeginToken());
            tokens.AddToken(new WordToken("word6"));
            tokens.AddToken(new AndNotToken());
            tokens.AddToken(new WordToken("word12"));
            tokens.AddToken(new ParenthesisEndToken());

            Parser parse = new Parser(tokens);
            Node   root  = parse.BinaryTree.root;

            Evaluater     eval = new Evaluater(root, index);
            List <string> res  = eval.result.ToList <string>();

            Assert.IsNotNull(res);
            Assert.Contains("doc2", res);
            Assert.AreEqual(1, res.Count);
        }
Beispiel #10
0
        static void Main(string[] args)
        {
            Type type = typeof(string);

            Parser    ep                = new Parser();
            Evaluater evaluater         = new Evaluater();
            ParameterVariableHolder pvh = new ParameterVariableHolder();

            pvh.Parameters["char"]     = new Parameter(typeof(char));
            pvh.Parameters["sbyte"]    = new Parameter(typeof(sbyte));
            pvh.Parameters["byte"]     = new Parameter(typeof(byte));
            pvh.Parameters["short"]    = new Parameter(typeof(short));
            pvh.Parameters["ushort"]   = new Parameter(typeof(ushort));
            pvh.Parameters["int"]      = new Parameter(typeof(int));
            pvh.Parameters["uint"]     = new Parameter(typeof(uint));
            pvh.Parameters["long"]     = new Parameter(typeof(string));
            pvh.Parameters["ulong"]    = new Parameter(typeof(ulong));
            pvh.Parameters["float"]    = new Parameter(typeof(float));
            pvh.Parameters["double"]   = new Parameter(typeof(double));
            pvh.Parameters["decimal"]  = new Parameter(typeof(decimal));
            pvh.Parameters["DateTime"] = new Parameter(typeof(DateTime));
            pvh.Parameters["string"]   = new Parameter(typeof(string));

            pvh.Parameters["Guid"] = new Parameter(typeof(Guid));

            pvh.Parameters["Convert"]    = new Parameter(typeof(Convert));
            pvh.Parameters["Math"]       = new Parameter(typeof(Math));
            pvh.Parameters["Array "]     = new Parameter(typeof(Array));
            pvh.Parameters["Random"]     = new Parameter(typeof(Random));
            pvh.Parameters["TimeZone"]   = new Parameter(typeof(TimeZone));
            pvh.Parameters["AppDomain "] = new Parameter(typeof(AppDomain));

            pvh.Parameters["Console"] = new Parameter(typeof(Console));

            pvh.Parameters["evaluater"] = new Parameter(evaluater);

            evaluater.VariableHolder = pvh;

            while (true)
            {
                System.Console.WriteLine("Input line,press Return to Eval:");
                string line = System.Console.ReadLine().Trim();
                if (string.IsNullOrEmpty(line))
                {
                    break;
                }
                try
                {
                    Tree tree = ep.Parse(line);

                    tree.Print(System.Console.Out);

                    object result = evaluater.Eval(tree);

                    if (result != null)
                    {
                        System.Console.WriteLine("Resut:{0}", result);
                    }
                    else
                    {
                        System.Console.WriteLine("Resut is null");
                    }
                }
                catch (Exception e)
                {
                    System.Console.WriteLine("Exception:" + e.GetType().Name + "->" + e.Message);
                }
            }
        }
    protected void WebChartControl1_CustomCallback(object sender, DevExpress.XtraCharts.Web.CustomCallbackEventArgs e)
    {
        string[] cmdAndParams = e.Parameter.Split(new string[] { "_" }, StringSplitOptions.RemoveEmptyEntries);
        string   command      = cmdAndParams[0];

        string[] parameters = cmdAndParams[1].Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries);

        if (command == "ChangeViewTypeCommand")
        {
            WebChartControl1.Series[0].ChangeView((ViewType)Enum.Parse(typeof(ViewType), parameters[0]));
        }
        else if (command == "EvaluateCommand")
        {
            string expr   = parameters[0].Replace("x", "Convert.ToDouble(param1)").Replace("y", "Convert.ToDouble(param2)");
            double start  = double.Parse(parameters[1], System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            double end    = double.Parse(parameters[2], System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            int    points = int.Parse(parameters[3], System.Globalization.CultureInfo.InvariantCulture.NumberFormat);

            Evaluater.Code = expr;

            WebChartControl1.Series[0].Points.Clear();
            for (double x = start; x <= end; x += (end - start) / (points - 1))
            {
                WebChartControl1.Series[0].Points.Add(new SeriesPoint(x, Convert.ToDouble(Evaluater.Evaluate(x, 0))));
            }
        }
    }