Beispiel #1
0
        private static void DoTest(List <Item> testData, ISymbolTable symbolTable)
        {
            Stack <Item> inserted = new Stack <Item>(testData.Count);
            Random       r        = new Random(DateTime.Now.Millisecond);
            DateTime     start    = DateTime.Now;

            foreach (Item item in testData)
            {
                symbolTable.Insert(item);
                inserted.Push(item);
            }
            foreach (Item item in inserted.Reverse())
            {
                Item found = symbolTable.Search(item.Key);
                if (!found.Value.Equals(item.Value))
                {
                    throw new Exception();
                }
            }
            for (int i = 0; i < testData.Count; i++)
            {
                int  randomIndex = r.Next(testData.Count);
                Item searched    = testData[randomIndex];
                Item found       = symbolTable.Search(searched.Key);
                if (!found.Value.Equals(searched.Value))
                {
                    throw new Exception();
                }
            }
            DateTime finish = DateTime.Now;
            TimeSpan span   = finish - start;

            Console.WriteLine("Timing for {0}: {1} ms", symbolTable.GetType(), span.TotalMilliseconds);
        }
Beispiel #2
0
 private static void DoTest(List<Item> testData, ISymbolTable symbolTable)
 {
     Stack<Item> inserted = new Stack<Item>(testData.Count);
     Random r = new Random(DateTime.Now.Millisecond);
     DateTime start = DateTime.Now;
     foreach (Item item in testData)
     {
         symbolTable.Insert(item);
         inserted.Push(item);
     }
     foreach (Item item in inserted.Reverse())
     {
         Item found = symbolTable.Search(item.Key);
         if (!found.Value.Equals(item.Value))
         {
             throw new Exception();
         }
     }
     for (int i = 0; i < testData.Count; i++)
     {
         int randomIndex = r.Next(testData.Count);
         Item searched = testData[randomIndex];
         Item found = symbolTable.Search(searched.Key);
         if (!found.Value.Equals(searched.Value))
         {
             throw new Exception();
         }
     }
     DateTime finish = DateTime.Now;
     TimeSpan span = finish - start;
     Console.WriteLine("Timing for {0}: {1} ms", symbolTable.GetType(), span.TotalMilliseconds);
 }