Exemple #1
0
 /**
  * @param rand
  * @param nextInt
  * @param test
  * @return
  */
 private JCG.SortedDictionary <String, Integer> fillRandomMap(Random rand, int max, JCG.SortedDictionary <String, Integer> test)
 {
     test.Clear();
     max = rand.Next(max);
     for (int i = 0; i < max; ++i)
     {
         test[GetRandomKey(rand)] = new Integer(rand.Next(50) + 50);
     }
     return(test);
 }
Exemple #2
0
        public void TestAMonkey()
        {
            JCG.SortedDictionary <String, Integer> stayWithMe = new JCG.SortedDictionary <String, Integer>(OneFirstComparator);

            UnicodeMap <Integer> me = new UnicodeMap <Integer>().PutAll(stayWithMe);

            // check one special case, removal near end
            me.PutAll(0x10FFFE, 0x10FFFF, 666);
            me.Remove(0x10FFFF);

            int iterations = 100000;

            JCG.SortedDictionary <String, Integer> test = new JCG.SortedDictionary <string, Integer>(StringComparer.Ordinal);

            Random  rand = new Random(0);
            String  other;
            Integer value;

            // try modifications
            for (int i = 0; i < iterations; ++i)
            {
                switch (i == 0 ? 0 : rand.Next(20))
                {
                case 0:
                    Logln("clear");
                    stayWithMe.Clear();
                    me.Clear();
                    break;

                case 1:
                    fillRandomMap(rand, 5, test);
                    Logln("putAll\t" + test);
                    stayWithMe.PutAll(test);
                    me.PutAll(test);
                    break;

                case 2:
                case 3:
                case 4:
                case 5:
                case 6:
                case 7:
                case 8:
                    other = GetRandomKey(rand);
                    //                if (other.equals("\uDBFF\uDFFF") && me.containsKey(0x10FFFF) && me.get(0x10FFFF).equals(me.get(0x10FFFE))) {
                    //                    System.out.println("Remove\t" + other + "\n" + me);
                    //                }
                    Logln("remove\t" + other);
                    stayWithMe.Remove(other);
                    try
                    {
                        me.Remove(other);
                    }
                    catch (ArgumentException e)
                    {
                        Errln("remove\t" + other + "\tfailed: " + e.ToString() + "\n" + me);
                        me.Clear();
                        stayWithMe.Clear();
                    }
                    break;

                default:
                    other = GetRandomKey(rand);
                    value = new Integer(rand.Next(50) + 50);
                    Logln("put\t" + other + " = " + value);
                    stayWithMe[other] = value;
                    me.Put(other, value);
                    break;
                }
                checkEquals(me, stayWithMe);
            }
        }