예제 #1
0
파일: ParserTest.cs 프로젝트: kranack/CAR
        public void TestEquality()
        {
            Ast.INode n1, n2;

            n1 = new Ast.IntegerNode(42);
            n2 = new Ast.IntegerNode(42);
            Assert.AreEqual(n1, n2);
            n2 = new Ast.IntegerNode(43);
            Assert.AreNotEqual(n1, n2);

            n1 = new Ast.StringNode("foo");
            n2 = new Ast.StringNode("foo");
            Assert.AreEqual(n1, n2);
            n2 = new Ast.StringNode("bar");
            Assert.AreNotEqual(n1, n2);

            n1 = new Ast.ComplexNumberNode()
            {
                Real      = 1.1,
                Imaginary = 2.2
            };
            n2 = new Ast.ComplexNumberNode()
            {
                Real      = 1.1,
                Imaginary = 2.2
            };
            Assert.AreEqual(n1, n2);
            n2 = new Ast.ComplexNumberNode()
            {
                Real      = 1.1,
                Imaginary = 3.3
            };
            Assert.AreNotEqual(n1, n2);

            n1 = new Ast.KeyValueNode()
            {
                Key   = new Ast.IntegerNode(42),
                Value = new Ast.IntegerNode(42)
            };
            n2 = new Ast.KeyValueNode()
            {
                Key   = new Ast.IntegerNode(42),
                Value = new Ast.IntegerNode(42)
            };
            Assert.AreEqual(n1, n2);
            n1 = new Ast.KeyValueNode()
            {
                Key   = new Ast.IntegerNode(43),
                Value = new Ast.IntegerNode(43)
            };
            Assert.AreNotEqual(n1, n2);

            n1 = Ast.NoneNode.Instance;
            n2 = Ast.NoneNode.Instance;
            Assert.AreEqual(n1, n2);
            n2 = new Ast.IntegerNode(42);
            Assert.AreNotEqual(n1, n2);

            n1 = new Ast.DictNode()
            {
                Elements = new List <Ast.INode>()
                {
                    new Ast.KeyValueNode()
                    {
                        Key   = new Ast.IntegerNode(42),
                        Value = new Ast.IntegerNode(42)
                    }
                }
            };
            n2 = new Ast.DictNode()
            {
                Elements = new List <Ast.INode>()
                {
                    new Ast.KeyValueNode()
                    {
                        Key   = new Ast.IntegerNode(42),
                        Value = new Ast.IntegerNode(42)
                    }
                }
            };
            Assert.AreEqual(n1, n2);
            n2 = new Ast.DictNode()
            {
                Elements = new List <Ast.INode>()
                {
                    new Ast.KeyValueNode()
                    {
                        Key   = new Ast.IntegerNode(42),
                        Value = new Ast.IntegerNode(43)
                    }
                }
            };
            Assert.AreNotEqual(n1, n2);

            n1 = new Ast.ListNode()
            {
                Elements = new List <Ast.INode>()
                {
                    new Ast.IntegerNode(42)
                }
            };
            n2 = new Ast.ListNode()
            {
                Elements = new List <Ast.INode>()
                {
                    new Ast.IntegerNode(42)
                }
            };
            Assert.AreEqual(n1, n2);
            n2 = new Ast.ListNode()
            {
                Elements = new List <Ast.INode>()
                {
                    new Ast.IntegerNode(43)
                }
            };
            Assert.AreNotEqual(n1, n2);

            n1 = new Ast.SetNode()
            {
                Elements = new List <Ast.INode>()
                {
                    new Ast.IntegerNode(42)
                }
            };
            n2 = new Ast.SetNode()
            {
                Elements = new List <Ast.INode>()
                {
                    new Ast.IntegerNode(42)
                }
            };
            Assert.AreEqual(n1, n2);
            n2 = new Ast.SetNode()
            {
                Elements = new List <Ast.INode>()
                {
                    new Ast.IntegerNode(43)
                }
            };
            Assert.AreNotEqual(n1, n2);

            n1 = new Ast.TupleNode()
            {
                Elements = new List <Ast.INode>()
                {
                    new Ast.IntegerNode(42)
                }
            };
            n2 = new Ast.TupleNode()
            {
                Elements = new List <Ast.INode>()
                {
                    new Ast.IntegerNode(42)
                }
            };
            Assert.AreEqual(n1, n2);
            n2 = new Ast.TupleNode()
            {
                Elements = new List <Ast.INode>()
                {
                    new Ast.IntegerNode(43)
                }
            };
            Assert.AreNotEqual(n1, n2);
        }
예제 #2
0
        public void TestEquality()
        {
            Ast.INode n1, n2;

            n1 = new Ast.IntegerNode(42);
            n2 = new Ast.IntegerNode(42);
            Assert.AreEqual(n1, n2);
            n2 = new Ast.IntegerNode(43);
            Assert.AreNotEqual(n1, n2);

            n1 = new Ast.StringNode("foo");
            n2 = new Ast.StringNode("foo");
            Assert.AreEqual(n1, n2);
            n2 = new Ast.StringNode("bar");
            Assert.AreNotEqual(n1, n2);

            n1 = new Ast.ComplexNumberNode() {
                Real=1.1,
                Imaginary=2.2
            };
            n2 = new Ast.ComplexNumberNode() {
                Real=1.1,
                Imaginary=2.2
            };
            Assert.AreEqual(n1, n2);
            n2 = new Ast.ComplexNumberNode() {
                Real=1.1,
                Imaginary=3.3
            };
            Assert.AreNotEqual(n1, n2);

            n1=new Ast.KeyValueNode() {
                Key=new Ast.IntegerNode(42),
                Value=new Ast.IntegerNode(42)
            };
            n2=new Ast.KeyValueNode() {
                Key=new Ast.IntegerNode(42),
                Value=new Ast.IntegerNode(42)
            };
            Assert.AreEqual(n1, n2);
            n1=new Ast.KeyValueNode() {
                Key=new Ast.IntegerNode(43),
                Value=new Ast.IntegerNode(43)
            };
            Assert.AreNotEqual(n1,n2);

            n1=Ast.NoneNode.Instance;
            n2=Ast.NoneNode.Instance;
            Assert.AreEqual(n1, n2);
            n2=new Ast.IntegerNode(42);
            Assert.AreNotEqual(n1, n2);

            n1=new Ast.DictNode() {
                Elements=new List<Ast.INode>() {
                    new Ast.KeyValueNode() {
                        Key=new Ast.IntegerNode(42),
                        Value=new Ast.IntegerNode(42)
                    }
                }
            };
            n2=new Ast.DictNode() {
                Elements=new List<Ast.INode>() {
                    new Ast.KeyValueNode() {
                        Key=new Ast.IntegerNode(42),
                        Value=new Ast.IntegerNode(42)
                    }
                }
            };
            Assert.AreEqual(n1, n2);
            n2=new Ast.DictNode() {
                Elements=new List<Ast.INode>() {
                    new Ast.KeyValueNode() {
                        Key=new Ast.IntegerNode(42),
                        Value=new Ast.IntegerNode(43)
                    }
                }
            };
            Assert.AreNotEqual(n1, n2);

            n1=new Ast.ListNode() {
                Elements=new List<Ast.INode>() {
                    new Ast.IntegerNode(42)
                }
            };
            n2=new Ast.ListNode() {
                Elements=new List<Ast.INode>() {
                    new Ast.IntegerNode(42)
                }
            };
            Assert.AreEqual(n1,n2);
            n2=new Ast.ListNode() {
                Elements=new List<Ast.INode>() {
                    new Ast.IntegerNode(43)
                }
            };
            Assert.AreNotEqual(n1,n2);

            n1=new Ast.SetNode() {
                Elements=new List<Ast.INode>() {
                    new Ast.IntegerNode(42)
                }
            };
            n2=new Ast.SetNode() {
                Elements=new List<Ast.INode>() {
                    new Ast.IntegerNode(42)
                }
            };
            Assert.AreEqual(n1,n2);
            n2=new Ast.SetNode() {
                Elements=new List<Ast.INode>() {
                    new Ast.IntegerNode(43)
                }
            };
            Assert.AreNotEqual(n1,n2);

            n1=new Ast.TupleNode() {
                Elements=new List<Ast.INode>() {
                    new Ast.IntegerNode(42)
                }
            };
            n2=new Ast.TupleNode() {
                Elements=new List<Ast.INode>() {
                    new Ast.IntegerNode(42)
                }
            };
            Assert.AreEqual(n1,n2);
            n2=new Ast.TupleNode() {
                Elements=new List<Ast.INode>() {
                    new Ast.IntegerNode(43)
                }
            };
            Assert.AreNotEqual(n1,n2);
        }