public void TestComplex() { Parser p = new Parser(); var cplx = new Ast.ComplexNumberNode() { Real = 4.2, Imaginary = 3.2 }; var cplx2 = new Ast.ComplexNumberNode() { Real = 4.2, Imaginary = 99 }; Assert.AreNotEqual(cplx, cplx2); cplx2.Imaginary = 3.2; Assert.AreEqual(cplx, cplx2); Assert.AreEqual(cplx, p.Parse("(4.2+3.2j)").Root); cplx.Real = 0; Assert.AreEqual(cplx, p.Parse("(0+3.2j)").Root); Assert.AreEqual(cplx, p.Parse("3.2j").Root); Assert.AreEqual(cplx, p.Parse("+3.2j").Root); cplx.Imaginary = -3.2; Assert.AreEqual(cplx, p.Parse("-3.2j").Root); cplx.Real = -9.9; Assert.AreEqual(cplx, p.Parse("(-9.9-3.2j)").Root); }
public void TestComplex() { Parser p = new Parser(); var cplx = new Ast.ComplexNumberNode() { Real = 4.2, Imaginary = 3.2 }; var cplx2 = new Ast.ComplexNumberNode() { Real = 4.2, Imaginary = 99 }; Assert.AreNotEqual(cplx, cplx2); cplx2.Imaginary = 3.2; Assert.AreEqual(cplx, cplx2); Assert.AreEqual(cplx, p.Parse("(4.2+3.2j)").Root); cplx.Real = 0; Assert.AreEqual(cplx, p.Parse("(0+3.2j)").Root); Assert.AreEqual(cplx, p.Parse("3.2j").Root); Assert.AreEqual(cplx, p.Parse("+3.2j").Root); cplx.Imaginary = -3.2; Assert.AreEqual(cplx, p.Parse("-3.2j").Root); cplx.Real = -9.9; Assert.AreEqual(cplx, p.Parse("(-9.9-3.2j)").Root); cplx.Real = 2; cplx.Imaginary = 3; Assert.AreEqual(cplx, p.Parse("(2+3j)").Root); cplx.Imaginary = -3; Assert.AreEqual(cplx, p.Parse("(2-3j)").Root); cplx.Real = 0; Assert.AreEqual(cplx, p.Parse("-3j").Root); }
public void TestComplex() { Parser p = new Parser(); var cplx = new Ast.ComplexNumberNode() { Real = 4.2, Imaginary = 3.2 }; var cplx2 = new Ast.ComplexNumberNode() { Real = 4.2, Imaginary = 99 }; Assert.NotEqual(cplx, cplx2); cplx2.Imaginary = 3.2; Assert.Equal(cplx, cplx2); Assert.Equal(cplx, p.Parse("(4.2+3.2j)").Root); cplx.Real = 0; Assert.Equal(cplx, p.Parse("(0+3.2j)").Root); Assert.Equal(cplx, p.Parse("3.2j").Root); Assert.Equal(cplx, p.Parse("+3.2j").Root); cplx.Imaginary = -3.2; Assert.Equal(cplx, p.Parse("-3.2j").Root); cplx.Real = -9.9; Assert.Equal(cplx, p.Parse("(-9.9-3.2j)").Root); cplx.Real = 2; cplx.Imaginary = 3; Assert.Equal(cplx, p.Parse("(2+3j)").Root); cplx.Imaginary = -3; Assert.Equal(cplx, p.Parse("(2-3j)").Root); cplx.Real = 0; Assert.Equal(cplx, p.Parse("-3j").Root); cplx.Real = -3.2e32; cplx.Imaginary = -9.9e44; Assert.Equal(cplx, p.Parse("(-3.2e32 -9.9e44j)").Root); Assert.Equal(cplx, p.Parse("(-3.2e+32 -9.9e+44j)").Root); Assert.Equal(cplx, p.Parse("(-3.2e32-9.9e44j)").Root); Assert.Equal(cplx, p.Parse("(-3.2e+32-9.9e+44j)").Root); cplx.Imaginary = 9.9e44; Assert.Equal(cplx, p.Parse("(-3.2e32+9.9e44j)").Root); Assert.Equal(cplx, p.Parse("(-3.2e+32+9.9e+44j)").Root); cplx.Real = -3.2e-32; cplx.Imaginary = -9.9e-44; Assert.Equal(cplx, p.Parse("(-3.2e-32-9.9e-44j)").Root); }
public void TestComplexPrecision() { Parser p = new Parser(); Ast.ComplexNumberNode cv = (Ast.ComplexNumberNode)p.Parse("(98765432123456.12345678987656+665544332211.9998877665544j)").Root; Assert.Equal(98765432123456.12345678987656, cv.Real); Assert.Equal(665544332211.9998877665544, cv.Imaginary); cv = (Ast.ComplexNumberNode)p.Parse("(98765432123456.12345678987656-665544332211.9998877665544j)").Root; Assert.Equal(98765432123456.12345678987656, cv.Real); Assert.Equal(-665544332211.9998877665544, cv.Imaginary); cv = (Ast.ComplexNumberNode)p.Parse("(98765432123456.12345678987656e+33+665544332211.9998877665544e+44j)").Root; Assert.Equal(98765432123456.12345678987656e+33, cv.Real); Assert.Equal(665544332211.9998877665544e+44, cv.Imaginary); cv = (Ast.ComplexNumberNode)p.Parse("(-98765432123456.12345678987656e+33-665544332211.9998877665544e+44j)").Root; Assert.Equal(-98765432123456.12345678987656e+33, cv.Real); Assert.Equal(-665544332211.9998877665544e+44, cv.Imaginary); }
public void TestPrimitivesStuffAtEnd() { Parser p = new Parser(); Assert.AreEqual(new Ast.IntegerNode(42), p.ParseSingle(new SeekableStringReader("42@"))); Assert.AreEqual(new Ast.DoubleNode(42.331), p.ParseSingle(new SeekableStringReader("42.331@"))); Assert.AreEqual(new Ast.BooleanNode(true), p.ParseSingle(new SeekableStringReader("True@"))); Assert.AreEqual(Ast.NoneNode.Instance, p.ParseSingle(new SeekableStringReader("None@"))); var cplx = new Ast.ComplexNumberNode() { Real = 4, Imaginary = 3 }; Assert.AreEqual(cplx, p.ParseSingle(new SeekableStringReader("(4+3j)@"))); cplx.Real = 0; Assert.AreEqual(cplx, p.ParseSingle(new SeekableStringReader("3j@"))); }
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); }
public void TestPrimitivesStuffAtEnd() { Parser p = new Parser(); Assert.AreEqual(new Ast.IntegerNode(42), p.ParseSingle(new SeekableStringReader("42@"))); Assert.AreEqual(new Ast.DoubleNode(42.331), p.ParseSingle(new SeekableStringReader("42.331@"))); Assert.AreEqual(new Ast.BooleanNode(true), p.ParseSingle(new SeekableStringReader("True@"))); Assert.AreEqual(Ast.NoneNode.Instance, p.ParseSingle(new SeekableStringReader("None@"))); var cplx = new Ast.ComplexNumberNode() { Real = 4, Imaginary = 3 }; Assert.AreEqual(cplx, p.ParseSingle(new SeekableStringReader("(4+3j)@"))); cplx.Real=0; Assert.AreEqual(cplx, p.ParseSingle(new SeekableStringReader("3j@"))); }
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); }