Exemplo n.º 1
0
 public static void SelfTest()
 {
     for (int tests = 0; tests < 1000; tests++)
     {
         uint c0 = 0, c1 = 0, c2 = 0, c3 = 0;
         var  node        = new BinaryHashNode();
         bool done        = false;
         var  checkCounts = Ut.Lambda(() =>
         {
             uint ac0, ac1, ac2, ac3;
             node.GetCounts(out ac0, out ac1, out ac2, out ac3);
             if (ac0 != c0 || ac1 != c1 || ac2 != c2 || ac3 != c3)
             {
                 throw new Exception();
             }
             if (c0 == 0xFFF || c1 == 0xFFF || c2 == 0x7FF || c3 == 0xFFF)
             {
                 node.AddCount(0);
                 node.AddCount(1);
                 node.AddCount(2);
                 node.AddCount(3);
                 node.GetCounts(out ac0, out ac1, out ac2, out ac3);
                 if (ac0 != c0 || ac1 != c1 || ac2 != c2 || ac3 != c3) // must not have incremented since one of the counters is saturated
                 {
                     throw new Exception();
                 }
                 done = true;
             }
         });
         do
         {
             if (Rnd.NextDouble() < 0.25)
             {
                 c0++;
                 node.AddCount(0);
                 checkCounts();
             }
             else if (Rnd.NextDouble() < 0.33)
             {
                 c1++;
                 node.AddCount(1);
                 checkCounts();
             }
             else if (Rnd.NextDouble() < 0.50)
             {
                 c2++;
                 node.AddCount(2);
                 checkCounts();
             }
             else
             {
                 c3++;
                 node.AddCount(3);
                 checkCounts();
             }
         }while (!done);
     }
 }
Exemplo n.º 2
0
 public static void SelfTest()
 {
     BinaryHashNode.SelfTest();
 }