//
// Copyright (C) 2009 Thomas Mullaly
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
//
using System;
using System.Collections.Generic;
using System.Diagnostics;
using STL;
namespace Test
{
class MainClass
{
public static void Main(string[] args)
{
IntegrityTest();
}
public static void IntegrityTest()
{
Console.WriteLine("Beginning integrity test.");
// Used to keep track of time.
Stopwatch watch = new Stopwatch();
watch.Start();
// Vector of TestClass'es.
Vector vector = new Vector();
// Number of TestClass'es to create.
int n = 1000000;
// Used to test whether the item has been collected by the GC.
WeakReference [] refs = new WeakReference[n];
Console.WriteLine("Adding {0} item(s) to the vector.", n);
// Add the items to the vector.
for (int i = 0; i < n; ++i) {
TestClass test = new TestClass(n);
vector.PushBack(test);
refs[i] = new WeakReference(test);
}
Console.WriteLine("All Items added to vector in {0} ms.", watch.ElapsedMilliseconds);
// Force a GC collection so we can test that
// all of the TestClass items are still in
// memory.
GC.Collect();
Console.WriteLine("Testing data integrity.");
// Find out if any items were lost.
int lost = 0;
for (int i = 0; i < n; ++i) {
if (!refs[i].IsAlive) {
++lost;
}
}
if (lost == 0) {
Console.WriteLine("No items lost.");
} else {
Console.WriteLine("{0} of {1} item(s) lost.", lost, n);
}
watch.Stop();
// Clean up.
vector.Dispose();
Console.WriteLine("Integrity test complete.");
Console.WriteLine("Time taken: {0} ms.", watch.ElapsedMilliseconds);
}
}
}