// -----------------------------------------------------------------------
//
// TODO: Update copyright text.
//
// -----------------------------------------------------------------------
namespace OpenTraffic.Collections
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
///
/// TODO: Update summary.
///
public static class TestCode
{
public static bool TestQueue(int n)
{
TrafficQueue heap = new TrafficQueue();
System.Random rand = new System.Random();
for (int i = 0; i < n; i++)
{
double f = rand.NextDouble();
heap.Add(f, 1);
if (!heap.ControlInnerState())
{
System.Console.WriteLine("FAILED TESTHEAP: Bad innerstate with insert");
System.Console.WriteLine("Tried to insert " + f);
System.Console.WriteLine(heap);
return false;
}
}
double s = double.MaxValue;
while (heap.Count != 0)
{
KeyValuePair kv = heap.Pop();
if (kv.Key > s)
{
System.Console.WriteLine("FAILED TESTHEAP");
return false;
}
if (!heap.ControlInnerState())
{
System.Console.WriteLine("FAILED TESTHEAP: Bad innerstate with pop");
System.Console.WriteLine("Just Removed " + kv.Key);
System.Console.WriteLine(heap);
return false;
}
s = kv.Key;
}
System.Console.WriteLine("OK: TESTHEAP");
return true;
}
public static bool TestHeap(int n)
{
TrafficHeap heap = new TrafficHeap(10);
System.Random rand = new System.Random();
for (int i = 0; i < n; i++)
{
double f = rand.NextDouble();
heap.Add(f, 1);
if (!heap.ControlInnerState())
{
System.Console.WriteLine("FAILED TESTHEAP: Bad innerstate with insert");
System.Console.WriteLine("Tried to insert " + f);
System.Console.WriteLine(heap);
return false;
}
}
double s = double.MaxValue;
while (heap.Count != 0)
{
KeyValuePair kv = heap.Pop();
if (kv.Key > s)
{
System.Console.WriteLine("FAILED TESTHEAP");
return false;
}
if (!heap.ControlInnerState())
{
System.Console.WriteLine("FAILED TESTHEAP: Bad innerstate with pop");
System.Console.WriteLine("Just Removed " + kv.Key);
System.Console.WriteLine(heap);
return false;
}
s = kv.Key;
}
System.Console.WriteLine("OK: TESTHEAP");
return true;
}
}
}