예제 #1
0
        public void TestCondIfSmall3()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("(cond ");
            sb.Append("((= 5 5) (inc 1))");
            sb.Append("(True (inc 5))");
            sb.Append(")");
            string line = sb.ToString();

            string result = HighLevel.Evaluate(line);

            Assert.AreEqual("2", result);
        }
예제 #2
0
        public void TestLambdaApplicationEvaluation()
        {
            string expr      = "(eval (list (lambda (x) (+ 1 x)) 3))";
            Node   parseTree = HighLevel.Parse(expr);

            Node nodeResult = Evaluator.Evaluate(parseTree, env);

            Assert.IsNotNull(nodeResult);
            Assert.AreEqual(StdNodeTypes.Identifier, nodeResult.NodeType);

            string result = NodeOps.Serialize(nodeResult);

            Assert.AreEqual("4", result);
        }
예제 #3
0
파일: TestMacro.cs 프로젝트: orfgen/Trip
        public void TestSimpleParse()
        {
            string line = "(seq (defmacro inc (x) (+ x 1)) (inc 2))";

            Node node = HighLevel.Parse(line);

            Assert.IsNotNull(node);

            Env env = new Env(null);

            node = MacroExpander.ExpandMacros(node, env);
            string serialization = NodeOps.Serialize(node);

            Assert.AreEqual("(seq (+ 2 1))", serialization);
        }
예제 #4
0
        public void TestIfElse()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("(if ");
            sb.Append("(NIL? (quote AnIdentifier)) ");
            sb.Append("(quote ThenResult) ");
            sb.Append("(quote ElseResult)");
            sb.Append(")");
            string line = sb.ToString();

            string result = HighLevel.Evaluate(line);

            Assert.AreEqual("ElseResult", result);
        }
예제 #5
0
        public void SimpleEvalTest()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("(seq ");
            // Could also be: sb.Append("(eval 3 )");
            sb.Append("(eval (+ 1 2) )");
            sb.Append(")");
            string line = sb.ToString();

            string result = HighLevel.Evaluate(line);

            // Atoms are evaluated to atoms.
            Assert.AreEqual("3", result);
        }
예제 #6
0
        public void TestCondIfVerySmall()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("(cond-fun ");
            sb.Append("(quote");
            sb.Append("((True (inc 1)))");
            sb.Append(")");
            sb.Append(")");
            string line = sb.ToString();

            string result = HighLevel.Evaluate(line);

            Assert.AreEqual("2", result);
        }
예제 #7
0
        public void TestCondIfVerySmallBlub()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("(if ");
            sb.Append("True");
            sb.Append("(inc 1)");
            sb.Append("(inc 2)");
            sb.Append(")");
            string line = sb.ToString();

            string result = HighLevel.Evaluate(line);

            Assert.AreEqual("2", result);
        }
예제 #8
0
        public void SaveFileTest()
        {
            string testDir    = TestContext.CurrentContext.TestDirectory;
            string pathToFile = Path.Combine(testDir, "testfiles", "SaveFile.txt");

            string escapedPathToFile = Regex.Escape(pathToFile);

            string fileContent = "This is content for SaveFile.txt";

            string input = "(save-file \"" + escapedPathToFile + "\" \"" + fileContent + "\")";

            string result = HighLevel.Evaluate(input);

            Assert.AreEqual("NIL", result);
        }
예제 #9
0
        public void TestCondMatchSecond()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("(cond ");
            sb.Append("((NIL? (quote AnIdentifier)) (quote WrongResult))");
            sb.Append("((NIL? (NIL)) (quote ThenResult))");
            sb.Append("(True (quote ElseResult))");
            sb.Append(")");
            string line = sb.ToString();

            string result = HighLevel.Evaluate(line);

            Assert.AreEqual("ThenResult", result);
        }
예제 #10
0
        public void TestSimpleHeadStuff()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("(list ");
            sb.Append("(head (quote (1 2 3)))");
            sb.Append("(tail (quote (1 2 3)))");
            sb.Append("(head (tail (quote (1 2 3))))");
            sb.Append(")");
            string line = sb.ToString();

            string result = HighLevel.Evaluate(line);

            Assert.AreEqual("(1 (2 3) 2)", result);
        }
예제 #11
0
        /// <summary>
        /// 将格式字符串转换为HighLevel
        /// </summary>
        /// <param name="txt">单行高程点</param>
        /// <returns>高程对象</returns>
        private static HighLevel ConvertTxtToHighLevel(string txt)
        {
            HighLevel result = new HighLevel();

            string[] txtContent = txt.Split(',');
            if (txtContent.Length > 0)
            {
                result.Name = txtContent[0];
                result.Lat  = double.Parse(txtContent[1]);
                result.Lon  = double.Parse(txtContent[2]);
                result.HIGH = double.Parse(txtContent[3]);
                //上传的批量点数据没有水准高
                //result.high = double.Parse(txtContent[4]);
            }
            return(result);
        }
예제 #12
0
        public void TestCondFunMatchFirst()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("(cond-fun ");
            sb.Append("(list");
            sb.Append("(quote ((NIL? (NIL)) (inc 1)))");
            sb.Append("(quote (True (inc 5)))");
            sb.Append(")");
            sb.Append(")");
            string line = sb.ToString();

            string result = HighLevel.Evaluate(line);

            Assert.AreEqual("2", result);
        }
예제 #13
0
        public void TestSimpleExpansionGoodOrder()
        {
            Env env = new Env(null);

            AddBuiltin(env, "+", new PlusFun());
            AddBuiltin(env, "seq", new SeqFun());

            StringBuilder sb = new StringBuilder();

            sb.Append("(defmacro inc (x) (+ x 1))");
            sb.Append("(inc 3)");
            string expr   = sb.ToString();
            string result = HighLevel.Evaluate(expr, TraceLevel.Verbose, env);

            Assert.AreEqual("4", result);
        }
예제 #14
0
        public void TestAtoms()
        {
            Assert.AreEqual("(2 \"S-Expr\" (2 \"Atom\" \"id\"))", HighLevel.Evaluate("(parse-s-expr \"id\" 0)", TraceLevel.Error, env));
            Assert.AreEqual("(3 \"S-Expr\" (3 \"Atom\" \"id1\"))", HighLevel.Evaluate("(parse-s-expr \"id1\" 0)", TraceLevel.Error, env));

            //Assert.AreEqual("(15 . NIL)", HighLevel.Evaluate("(parse-s-expr \"(ident1 ident2)\" 0)", TraceLevel.Error, env));
            //Assert.AreEqual("(22 . NIL)", HighLevel.Evaluate("(parse-s-expr \"(ident1 ident2 ident3)\" 0)", TraceLevel.Error, env));

            //Assert.AreEqual("(9 . NIL)", HighLevel.Evaluate("(parse-s-expr \"((ident))\" 0)", TraceLevel.Error, env));
            //Assert.AreEqual("(9 . NIL)", HighLevel.Evaluate("(parse-s-expr \"(a (b c))\" 0)", TraceLevel.Error, env));

            // TODO TripCore: Unescape escape sequences in strings.
            // (parse-s-expr "(print \"Hello\")" 0) =>
            // (parse-s-expr\"(print \\\"Hello\\\")\" 0)
            //Assert.AreEqual("(16 . NIL)", HighLevel.Evaluate("(parse-s-expr \"(print \\\"Hello\\\")\" 0)", TraceLevel.Verbose, env));
        }
예제 #15
0
        /// <summary>
        /// 将格式文件字符转换成HighLevel列表
        /// </summary>
        /// <param name="txt">格式文件字符</param>
        /// <returns>高程对象列表</returns>
        public static List <HighLevel> ConvertTxtToHighLevelList(string txt)
        {
            List <HighLevel> result = new List <HighLevel>();

            string[] contentArray = txt.Split(new string[] { "\r\n" }, StringSplitOptions.None);
            if (contentArray.Length > 0)
            {
                //去除第一行为表头
                for (int i = 1; i < contentArray.Length; i++)
                {
                    HighLevel temp = ConvertTxtToHighLevel(contentArray[i]);
                    result.Add(temp);
                }
            }
            return(result);
        }
예제 #16
0
        public void LogicXORTest()
        {
            string[][] tests = new string[][]
            {
                new string[] { "(xor (quote (False False)))", "False" },
                new string[] { "(xor (quote (True False)))", "True" },
                new string[] { "(xor (quote (False True)))", "True" },
                new string[] { "(xor (quote (True True)))", "False" }
            };

            foreach (string[] test in tests)
            {
                string result = HighLevel.Evaluate(test[0]);
                Assert.AreEqual(test[1], result);
            }
        }
예제 #17
0
        public void TestParseCharRange()
        {
            string line   = "(parse-char-range \"CharRange\" \"m\" \"z\" \"text\" 0)";
            string result = HighLevel.Evaluate(line, TraceLevel.Error, env);

            Assert.AreEqual("(1 \"CharRange\" \"t\")", result);

            string line2   = "(parse-char-range \"CharRange\" \"m\" \"z\" \"text\" 1)";
            string result2 = HighLevel.Evaluate(line2, TraceLevel.Error, env);

            Assert.AreEqual("NIL", result2);

            string line3   = "(parse-char-range \"CharRange\" \"m\" \"z\" \"text\" 2)";
            string result3 = HighLevel.Evaluate(line3, TraceLevel.Error, env);

            Assert.AreEqual("(3 \"CharRange\" \"x\")", result3);
        }
예제 #18
0
        public void TestParseString()
        {
            string line   = "(parse-string \"String\" \"void\" \"TEXTvoidTEXTvoid\" 4)";
            string result = HighLevel.Evaluate(line, TraceLevel.Error, env);

            Assert.AreEqual("(8 \"String\" \"void\")", result);

            string line2   = "(parse-string \"String\" \"void\" \"TEXTvoidTEXTvoid\" 6)";
            string result2 = HighLevel.Evaluate(line2, TraceLevel.Error, env);

            Assert.AreEqual("NIL", result2);

            string line3   = "(parse-string \"String\" \"void\" \"TEXTvoidTEXTvoid\" 12)";
            string result3 = HighLevel.Evaluate(line3, TraceLevel.Error, env);

            Assert.AreEqual("(16 \"String\" \"void\")", result3);
        }
예제 #19
0
        public void TestNIL()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("(seq ");
            sb.Append("(if");
            sb.Append("(NIL? (tail (quote (1 2 3))))");
            sb.Append("(list (quote Then-Case))");
            sb.Append("(list (quote Else-Case))");
            sb.Append(")");
            sb.Append(")");
            string line = sb.ToString();

            string result = HighLevel.Evaluate(line);

            Assert.AreEqual("(Else-Case . NIL)", result);
        }
예제 #20
0
        public void TestIdentifier()
        {
            string line   = "(parse-string-range \"Atom\" \"*\" \"z\" \"ident\" 0)";
            string result = HighLevel.Evaluate(line, TraceLevel.Error, env);

            Console.WriteLine(result);
            Assert.AreEqual("(5 \"Atom\" \"ident\")", result);

            string line2   = "(parse-string-range \"Atom\" \"*\" \"z\" \"ident1\" 0)";
            string result2 = HighLevel.Evaluate(line2, TraceLevel.Error, env);

            Assert.AreEqual("(6 \"Atom\" \"ident1\")", result2);

            string line3   = "(parse-string-range \"Atom\" \"*\" \"z\" \"IDEnt1\" 0)";
            string result3 = HighLevel.Evaluate(line3, TraceLevel.Error, env);

            Assert.AreEqual("(6 \"Atom\" \"IDEnt1\")", result3);
        }
예제 #21
0
파일: TestParser.cs 프로젝트: orfgen/Trip
        public void TestSimpleParse()
        {
            string line = "(+ 1 2)";

            Node node = HighLevel.Parse(line);

            Assert.IsNull(node.Content);

            Node child0 = node.Head;

            Assert.AreEqual("+", child0.Content);

            Node child1 = node.Tail.Head;

            Assert.AreEqual("1", child1.Content);

            Node child2 = node.Tail.Tail.Head;

            Assert.AreEqual("2", child2.Content);
        }
예제 #22
0
        public void UnescapeTest()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("(quote ");
            sb.Append('\"');
            sb.Append("Hello");

            // Double backslash to prevent C# from unescaping "\t" to tab.
            sb.Append('\\');
            sb.Append('t');

            sb.Append("World");
            sb.Append('\"');
            sb.Append(")");

            string line = sb.ToString();

            string result = HighLevel.Evaluate(line);

            Assert.AreEqual("\"Hello\tWorld\"", result);
        }
예제 #23
0
        public void TestParseRepetition()
        {
            string first = "(parse-repetition \"Repetition\" (quote (parse-string \"String\" \"pizza\")) \"";
            string third = "\" 0)";

            string line   = first + "pizza" + third;
            string result = HighLevel.Evaluate(line, TraceLevel.Error, env);

            Assert.AreEqual("(5 \"Repetition\" (5 \"String\" \"pizza\"))", result);

            line   = first + "pizzapizza" + third;
            result = HighLevel.Evaluate(line, TraceLevel.Error, env);
            Assert.AreEqual("(10 \"Repetition\" (5 \"String\" \"pizza\") (10 \"String\" \"pizza\"))", result);

            line   = first + "pizzapizzapasta" + third;
            result = HighLevel.Evaluate(line, TraceLevel.Error, env);
            Assert.AreEqual("(10 \"Repetition\" (5 \"String\" \"pizza\") (10 \"String\" \"pizza\"))", result);

            line   = first + "pizzapizzapizza" + third;
            result = HighLevel.Evaluate(line, TraceLevel.Error, env);
            Console.WriteLine(result);
            Assert.AreEqual("(15 \"Repetition\" (5 \"String\" \"pizza\") (10 \"String\" \"pizza\") (15 \"String\" \"pizza\"))", result);
        }
예제 #24
0
        public void TestParse()
        {
            Node result = HighLevel.Parse(null);

            Assert.IsNull(result);
        }
예제 #25
0
        private Critter create()
        {
            Critter critter = null;
            switch (crittersLevel)
            {
                case CritterType.LowLevel: critter = new LowLevel(); break;
                case CritterType.MediumLevel: critter = new MediumLevel(); break;
                case CritterType.HighLevel: critter = new HighLevel(); break;
            }

            critter.Move(critterStartX, critterStartY);

            critter.Texture = Presentation.PresentationController.CritterTexture2D;
            critter.Width = critter.Texture.Width;
            critter.Height = critter.Texture.Height;

            critter.HP += (int)(waveLevel * Constants.CritterLevelHpModifier);
            critter.Speed += waveLevel * Constants.CritterLevelSpeedModifier;
            critter.Points += (int)(waveLevel * Constants.CritterLevelPointsModifier);
            critter.Dexterity += waveLevel * Constants.CritterLevelDexterityModifier;

            critter.Dead = false;
            critter.Active = false;
            critter.Slowed = 0;

            if ((float)RandomHandler.GetRandom() < Constants.CritterUpgradeChance)
            {
                critter.upgradeCritter();
            }

            CrittersList.Add(critter);
            return critter;
        }
예제 #26
0
        //Выполнение команды
        private void Button1_Click_1(object sender, EventArgs e)
        {
            if (portStatus.Text == "Порт закрыт")
            {
                MessageBox.Show("Откройте порт");
            }
            else if (command.Text == "")
            {
                MessageBox.Show("Выберите команду");
            }
            else
            {
                HighLevel high = new HighLevel();

                byte[]   workBytes = new byte[] { };
                ushort   ush1, ush2, ush3, ush4;
                byte     by1, by2, by3, by4, by5, by6, by7, by8;
                string[] decodeText;

                try
                {
                    switch (CommandIndex)
                    {
                    case 2:

                        ush1 = ushort.Parse(ushort1.Text);
                        ush2 = ushort.Parse(ushort2.Text);

                        workBytes = high.Second(ush1, ush2);
                        ShowAnswerBytes(workBytes);

                        break;

                    case 3:

                        ush1 = ushort.Parse(ushort1.Text);
                        ush2 = ushort.Parse(ushort2.Text);

                        workBytes = high.Third(ush1, ush2);
                        ShowAnswerBytes(workBytes);

                        workBytes  = Decode.GetAnswerBytes(workBytes, numberParity: true);
                        decodeText = Decode.DecodeThird(workBytes);

                        ShowAnswerText(decodeText);


                        break;

                    case 4:

                        ush1 = ushort.Parse(ushort1.Text);
                        ush2 = ushort.Parse(ushort2.Text);

                        workBytes = high.Fourth(ush1, ush2);
                        ShowAnswerBytes(workBytes);

                        workBytes  = Decode.GetAnswerBytes(workBytes, numberParity: true);
                        decodeText = Decode.DecodeFourth(workBytes);

                        ShowAnswerText(decodeText);

                        break;

                    case 5:

                        ush1 = ushort.Parse(ushort1.Text);
                        ush2 = ushort.Parse(ushort2.Text);

                        workBytes = high.Fifth(ush1, ush2);
                        ShowAnswerBytes(workBytes);

                        workBytes  = Decode.GetAnswerBytes(workBytes);
                        decodeText = Decode.DecodeFifth(workBytes);

                        ShowAnswerText(decodeText);

                        break;

                    case 6:

                        ush1 = ushort.Parse(ushort1.Text);
                        ush2 = ushort.Parse(ushort2.Text);

                        workBytes = high.Sixth(ush1, ush2);
                        ShowAnswerBytes(workBytes);

                        break;

                    case 7:

                        workBytes = high.Seventh();
                        ShowAnswerBytes(workBytes);

                        workBytes = Decode.GetAnswerBytes(workBytes);

                        decodeText = Decode.DecodeSeventh(workBytes[0]);

                        ShowAnswerText(decodeText);

                        break;

                    case 8:

                        ush1 = ushort.Parse(ushort1.Text);
                        by1  = byte.Parse(byte1.Text);
                        by2  = byte.Parse(byte2.Text);

                        workBytes = high.Eighth(ush1, by1, by2);
                        ShowAnswerBytes(workBytes);

                        break;

                    case 9:

                        by1  = byte.Parse(byte1.Text);
                        ush1 = ushort.Parse(ushort1.Text);
                        ush2 = ushort.Parse(ushort2.Text);
                        ush3 = ushort.Parse(ushort3.Text);

                        workBytes = high.Nineth(by1, ush1, ush2, ush3);
                        ShowAnswerBytes(workBytes);

                        break;

                    case 10:

                        by1  = byte.Parse(byte1.Text);
                        ush1 = ushort.Parse(ushort1.Text);
                        ush2 = ushort.Parse(ushort2.Text);
                        ush3 = ushort.Parse(ushort3.Text);
                        by3  = byte.Parse(byte3.Text);
                        by4  = byte.Parse(byte4.Text);
                        by5  = byte.Parse(byte5.Text);
                        by6  = byte.Parse(byte6.Text);
                        by7  = byte.Parse(byte7.Text);
                        by8  = byte.Parse(byte8.Text);

                        workBytes = high.Tenth(by1, ush1, ush2, ush3, by3, by4, by5, by6, by7, by8);
                        ShowAnswerBytes(workBytes);

                        break;

                    case 11:

                        by1  = byte.Parse(byte1.Text);
                        ush1 = ushort.Parse(ushort1.Text);
                        ush2 = ushort.Parse(ushort2.Text);

                        workBytes = high.Eleventh(by1, ush1, ush2);
                        ShowAnswerBytes(workBytes);

                        break;

                    case 16:

                        by1  = byte.Parse(byte1.Text);
                        ush1 = ushort.Parse(ushort1.Text);
                        ush2 = ushort.Parse(ushort2.Text);
                        ush3 = ushort.Parse(ushort3.Text);
                        ush4 = ushort.Parse(ushort4.Text);

                        workBytes = high.Sixteenth(by1, ush1, ush2, ush3, ush4);
                        ShowAnswerBytes(workBytes);

                        break;

                    case 17:

                        workBytes = high.Seventeenth();
                        ShowAnswerBytes(workBytes);

                        break;

                    case 18:

                        by1  = byte.Parse(byte1.Text);
                        ush1 = ushort.Parse(ushort1.Text);
                        ush2 = ushort.Parse(ushort2.Text);

                        workBytes = high.Eightteenth(by1, ush1, ush2);
                        ShowAnswerBytes(workBytes);

                        break;

                    case 19:

                        by1  = byte.Parse(byte1.Text);
                        ush1 = ushort.Parse(ushort1.Text);
                        ush2 = ushort.Parse(ushort2.Text);
                        by3  = byte.Parse(byte3.Text);
                        by4  = byte.Parse(byte3.Text);
                        by5  = byte.Parse(byte3.Text);
                        by6  = byte.Parse(byte3.Text);

                        workBytes = high.Nineteenth(by1, ush1, ush2, by3, by4, by5, by6);
                        ShowAnswerBytes(workBytes);

                        break;
                    }
                }
                catch (OverflowException)
                {
                    MessageBox.Show("Слишком большое или слишком маленькое значение одного из аргументов,OfverflowException");
                }
                catch (ArgumentException)
                {
                    MessageBox.Show("Один из аргументов имеет недопустимый формат,ArgumentException");
                }
                catch (FormatException)
                {
                    MessageBox.Show("Введите корректные значения,FormatException");
                }
            }
        }
예제 #27
0
 private void toolBar1_ButtonClick(object sender, ToolBarButtonClickEventArgs e)
 {
     try
     {
         if ((string)e.Button.Tag == "clear")
         {
             zedGraphControl1.GraphPane.CurveList.Clear();
         }
         else if ((string)e.Button.Tag == "+")
         {
             zedGraphControl1.GraphPane.YAxis.MaxAuto = false;
             YAxis  yaxis = zedGraphControl1.GraphPane.YAxis;
             double num   = yaxis.Max * 2.0;
             yaxis.Max = num;
         }
         else if ((string)e.Button.Tag == "-")
         {
             zedGraphControl1.GraphPane.YAxis.MaxAuto = false;
             if (zedGraphControl1.GraphPane.YAxis.Max != 0.0 && zedGraphControl1.GraphPane.YAxis.Max > 1E-15)
             {
                 YAxis  yaxis = zedGraphControl1.GraphPane.YAxis;
                 double num   = yaxis.Max / 2.0;
                 yaxis.Max = num;
             }
         }
         else if ((string)e.Button.Tag == "SBW")
         {
             oSBWMenu.Show(e.Button.Parent, e.Button.Rectangle.Location);
         }
         else if ((string)e.Button.Tag == "on/off")
         {
             if (!e.Button.Pushed)
             {
                 zedGraphControl1.GraphPane.PaneFill = new Fill(Color.WhiteSmoke);
                 zedGraphControl1.GraphPane.AxisFill = new Fill(Color.White);
             }
             else
             {
                 zedGraphControl1.GraphPane.PaneFill = new Fill(Color.WhiteSmoke, Color.Lavender, 0.0f);
                 zedGraphControl1.GraphPane.AxisFill = new Fill(Color.White,
                                                                Color.FromArgb(byte.MaxValue, byte.MaxValue, 166), 90f);
             }
         }
         else if ((string)e.Button.Tag == "[]")
         {
             zedGraphControl1.GraphPane.YAxis.MaxAuto = true;
         }
         else if ((string)e.Button.Tag == "About")
         {
             if (m_oAbout == null)
             {
                 m_oAbout = new AboutBifurcation(HighLevel.getSBWVersion());
             }
             var num = (int)m_oAbout.ShowDialog();
         }
         zedGraphControl1.AxisChange();
         zedGraphControl1.Refresh();
     }
     catch (Exception ex)
     {
         var num =
             (int)
             MessageBox.Show(
                 "Error displaying the graph in this resolution. Please increase the scale, or let the scale be determined automatically.",
                 "Error displaying graph");
     }
 }
예제 #28
0
        public void TestEvaluate()
        {
            string result = HighLevel.Evaluate(null);

            Assert.IsNull(result);
        }