public static void Run() { Sym inf = new SymInf(); Sym loose4 = new SymLoose(4); Sym loose5 = new SymLoose(5); Sym divs3left = new SymDivs(1, 3, 0, 0); var semi = new ConveyorSR(); Console.WriteLine("Starting unit tests..."); TestEq <Sym>("Left additive identity", semi.Add(inf, loose4), loose4); TestEq <Sym>("Right additive identity", semi.Add(loose4, inf), loose4); TestEq <Sym>("Left multiplicative zero", semi.Mult(inf, loose4), inf); TestEq <Sym>("Right multiplicative zero", semi.Mult(loose4, inf), inf); TestEq <Sym>("Left multiplicative identity", semi.Mult(new SymLoose(0), loose4), loose4); TestEq <Sym>("Right multiplicative identity", semi.Mult(loose4, new SymLoose(0)), loose4); TestEq <Sym>("Sym.Add", semi.Add(loose4, loose4), loose4); TestEq <Sym>("Loose 4 add Loose 5", semi.Add(loose4, loose5), loose4); TestEq <Sym>("Loose 5 add Loose 4", semi.Add(loose5, loose4), loose4); TestEq <Sym>("Loose 4 (X) Loose 5", semi.Mult(loose4, loose5), new SymLoose(9)); TestEq <Sym>("Loose 5 (X) Divs 1 3 0 0", semi.Mult(loose5, new SymDivs(1, 3, 0, 0)), new SymDivs(1, 8, 0, 0)); TestEq <Sym>("Divs 1 3 0 0 (X) Loose 5", semi.Mult(new SymDivs(1, 3, 0, 0), loose5), new SymDivs(1, 3, 0, 5)); Console.WriteLine("Done unit tests..."); }
public static void Run(int count) { var r = new Random(); var conveyorSR = new ConveyorSR(); /* * var aa = new SymDivs(17, 5, 10, 13); * var bb = new SymDivs(9, 9, 5, 15); * var cc = new SymDivs(13, 16, 5, 5); * * Console.WriteLine("Debug: {0} {1} {2}", aa, bb, cc); * Console.WriteLine("b (+) c = {0}", conveyorSR.Add(bb, cc)); * Console.WriteLine("a (X) b = {0}", conveyorSR.Mult(aa, bb)); * Console.WriteLine("a (X) c = {0}", conveyorSR.Mult(aa, cc)); * * Console.WriteLine("a (X) (b + c) = {0}", conveyorSR.Mult(aa, conveyorSR.Add(bb, cc))); * Console.WriteLine("a (X) b (+) (a (X) c) = {0}", conveyorSR.Add(conveyorSR.Mult(aa, bb), * conveyorSR.Mult(aa, cc))); */ Console.WriteLine("Starting property tests"); /* Associativity of ConveyorSR.Add over Sym */ for (int i = 1; i <= count; i++) { Sym a = RandomSym(r); Sym b = RandomSym(r); Sym c = RandomSym(r); var p = conveyorSR.Add(a, conveyorSR.Add(b, c)); var q = conveyorSR.Add(conveyorSR.Add(a, b), c); if (!p.Equals(q)) { Console.WriteLine("{3} Found non-associative triple of Syms under addition: {0}, {1}, {2}", a.ToString(), b.ToString(), c.ToString(), i); } } /* Associativity of ConveyorSR.Mult over Sym */ for (int i = 1; i <= count; i++) { Sym a = RandomSym(r); Sym b = RandomSym(r); Sym c = RandomSym(r); var p = conveyorSR.Mult(a, conveyorSR.Mult(b, c)); var q = conveyorSR.Mult(conveyorSR.Mult(a, b), c); if (!p.Equals(q)) { Console.WriteLine("{3} Found non-associative triple of Syms under multiplication: {0}, {1}, {2} --- {4}, {5}", a.ToString(), b.ToString(), c.ToString(), i, p, q); } } /* Left-distributivity of ConveyorSR over Sym */ for (int i = 1; i <= count; i++) { Sym a = RandomSym(r); Sym b = RandomSym(r); Sym c = RandomSym(r); var p = conveyorSR.Mult(a, conveyorSR.Add(b, c)); var q = conveyorSR.Add(conveyorSR.Mult(a, b), conveyorSR.Mult(a, c)); if (!p.Equals(q)) { Console.WriteLine("{3} Found non-left-distributive triple of Syms: {0}, {1}, {2} --- {4}, {5}", a.ToString(), b.ToString(), c.ToString(), i, p, q); } } /* Right-distributivity of ConveyorSR over Sym */ for (int i = 1; i <= count; i++) { Sym a = RandomSym(r); Sym b = RandomSym(r); Sym c = RandomSym(r); var p = conveyorSR.Mult(conveyorSR.Add(a, b), c); var q = conveyorSR.Add(conveyorSR.Mult(a, c), conveyorSR.Mult(b, c)); if (!p.Equals(q)) { Console.WriteLine("{3} Found non-right-distributive triple of Syms: {0}, {1}, {2}", a.ToString(), b.ToString(), c.ToString(), i); } } Console.WriteLine("Done property tests"); }