Beispiel #1
0
 /**
  * @param rand
  * @param nextInt
  * @param test
  * @return
  */
 private SortedDictionary <String, Integer> fillRandomMap(Random rand, int max, 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);
 }
Beispiel #2
0
        /**
         * @param me
         * @param stayWithMe
         */
        private void checkEquals(UnicodeMap <Integer> me, SortedDictionary <String, Integer> stayWithMe)
        {
            temp.Clear();
            foreach (var e in me.EntrySet())
            {
                temp.Add(e);
            }
            ISet <KeyValuePair <String, Integer> > entrySet = new HashSet <KeyValuePair <string, Integer> >(stayWithMe);

            if (!entrySet.SetEquals(temp))
            {
                Logln(me.EntrySet().ToString());
                Logln(me.ToString());
                assertEquals("are in parallel", entrySet, temp);
                // we failed. Reset and start again
                entrySet.Clear();
                temp.Clear();
                return;
            }
            foreach (String key in stayWithMe.Keys)
            {
                assertEquals("containsKey", stayWithMe.ContainsKey(key), me.ContainsKey(key));
                Integer value = stayWithMe.Get(key);
                assertEquals("get", value, me.Get(key));
                assertEquals("containsValue", stayWithMe.ContainsValue(value), me.ContainsValue(value));
                int cp = UnicodeSet.GetSingleCodePoint(key);
                if (cp != int.MaxValue)
                {
                    assertEquals("get", value, me.Get(cp));
                }
            }
            // ICU4N TODO: complete implementation
            //ISet<String> nonCodePointStrings = stayWithMe.tailMap("").keySet();
            //if (nonCodePointStrings.Count == 0) nonCodePointStrings = null; // for parallel api
            //assertEquals("getNonRangeStrings", nonCodePointStrings, me.GetNonRangeStrings());

            SortedSet <Integer> values   = new SortedSet <Integer>(stayWithMe.Values);
            SortedSet <Integer> myValues = new SortedSet <Integer>(me.Values());

            assertEquals("values", myValues, values);

            foreach (String key in stayWithMe.Keys)
            {
                assertEquals("containsKey", stayWithMe.ContainsKey(key), me.ContainsKey(key));
            }
        }
Beispiel #3
0
        public void TestAMonkey()
        {
            SortedDictionary <String, Integer> stayWithMe = new 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;
            SortedDictionary <String, Integer> test = new 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);
            }
        }