Ejemplo n.º 1
0
 public Sym Prepare(Marked <int, bool> element) => Sym.FromMarked(element);
Ejemplo n.º 2
0
        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");
        }