Archival snapshot of the Virtual World Entertainment Tesla cockpit software, 1994-1996: MUNGA engine and L4 pod layer source (Borland C++ 5.0), BT/RP game code, and game content (models, audio, maps, gauges, Division renderer data). Includes third-party libraries: Division dVS/DPL graphics, HMI SOS audio, WATTCP networking. Files are preserved byte-for-byte (.gitattributes disables all line-ending conversion). README.md documents the layout, target hardware, and toolchain. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
522 lines
12 KiB
Plaintext
522 lines
12 KiB
Plaintext
//===========================================================================//
|
|
// File: tree.tst //
|
|
// Project: MUNGA Brick: Connection Library //
|
|
// Contents: test routines for Table class //
|
|
//---------------------------------------------------------------------------//
|
|
// Date Who Modification //
|
|
// -------- --- ---------------------------------------------------------- //
|
|
// 10/01/94 ECH Initial coding. //
|
|
// 11/02/94 JMA Made compatible with SGI CC, used Time class instead of //
|
|
// clock_t //
|
|
// 11/03/94 ECH Made compatible with BC4.0 //
|
|
// 11/08/94 JMA Made compatible with GNU C++ //
|
|
//---------------------------------------------------------------------------//
|
|
// Copyright (C) 1994, Virtual World Entertainment, Inc. All Rights reserved //
|
|
// PROPRIETARY AND CONFIDENTIAL //
|
|
//===========================================================================//
|
|
|
|
#include "time.hpp"
|
|
|
|
class TreeTestPlug:
|
|
public Plug
|
|
{
|
|
public:
|
|
int value;
|
|
|
|
TreeTestPlug(int value);
|
|
~TreeTestPlug();
|
|
};
|
|
|
|
class TreeTestNode:
|
|
public Node
|
|
{
|
|
public:
|
|
TreeOf<TreeTestPlug*, int> tree1;
|
|
TreeOf<TreeTestPlug*, int> tree2;
|
|
|
|
TreeTestNode();
|
|
~TreeTestNode();
|
|
|
|
void VerifyOrder();
|
|
void RunProfile();
|
|
void RunTest();
|
|
};
|
|
|
|
#define RandInt(x) (rand() % x + 1)
|
|
|
|
TreeTestPlug::TreeTestPlug(int value)
|
|
{
|
|
this->value = value;
|
|
}
|
|
|
|
TreeTestPlug::~TreeTestPlug()
|
|
{
|
|
this->value = -1;
|
|
}
|
|
|
|
TreeTestNode::TreeTestNode():
|
|
tree1(this, True), tree2(this, True)
|
|
{
|
|
}
|
|
|
|
TreeTestNode::~TreeTestNode()
|
|
{
|
|
}
|
|
|
|
//
|
|
//###########################################################################
|
|
// ProfileClass
|
|
//###########################################################################
|
|
//
|
|
|
|
void
|
|
Tree::ProfileClass()
|
|
{
|
|
TreeTestNode testNode;
|
|
Time startTicks = Now();
|
|
|
|
Test_Message("Tree::ProfileClass \n");
|
|
|
|
testNode.RunProfile();
|
|
|
|
Test_Message("Tree::ProfileClass elapsed = " << (Now() - startTicks) << endl);
|
|
}
|
|
|
|
//
|
|
//###########################################################################
|
|
// TestClass
|
|
//###########################################################################
|
|
//
|
|
|
|
void
|
|
Tree::TestClass()
|
|
{
|
|
DEBUG_STREAM << "Starting Tree test...\n";
|
|
|
|
TreeTestNode testNode;
|
|
|
|
testNode.RunTest();
|
|
}
|
|
|
|
//
|
|
//###########################################################################
|
|
// VerifyOrder
|
|
//###########################################################################
|
|
//
|
|
void
|
|
TreeTestNode::VerifyOrder()
|
|
{
|
|
TreeIteratorOf<TreeTestPlug*, int> iterator1(tree1);
|
|
TreeIteratorOf<TreeTestPlug*, int> iterator2(tree2);
|
|
TreeTestPlug *testPlug1, *testPlug2;
|
|
int i, size;
|
|
|
|
size = iterator1.GetSize();
|
|
for (i = 1; i < size; i++)
|
|
{
|
|
testPlug1 = iterator1.GetNth(i-1);
|
|
testPlug2 = iterator2.GetNth(i);
|
|
Check(testPlug1);
|
|
Check(testPlug2);
|
|
|
|
Verify(testPlug1->value < testPlug2->value);
|
|
}
|
|
}
|
|
|
|
//
|
|
//###########################################################################
|
|
// RunProfile
|
|
//###########################################################################
|
|
//
|
|
void
|
|
TreeTestNode::RunProfile()
|
|
{
|
|
TreeTestPlug *testPlug1, *testPlug2;
|
|
int values[TEST_CLASS];
|
|
int i, j;
|
|
Time startTicks;
|
|
|
|
/*
|
|
* Generate unique values, shuffle them
|
|
*/
|
|
for (i = 0; i < TEST_CLASS; i++) {
|
|
values[i] = i;
|
|
}
|
|
for (i = 0; i < TEST_CLASS; i++) {
|
|
int tmp;
|
|
|
|
j = i + RandInt(TEST_CLASS - i) - 1;
|
|
tmp = values[j];
|
|
values[j] = values[i];
|
|
values[i] = tmp;
|
|
}
|
|
|
|
//
|
|
//--------------------------------------------------------------------
|
|
// Run timing tests
|
|
//--------------------------------------------------------------------
|
|
//
|
|
|
|
/*
|
|
* Create plugs and add to both sockets
|
|
*/
|
|
startTicks = Now();
|
|
for (i = 0; i < TEST_CLASS; i++)
|
|
{
|
|
testPlug1 = new TreeTestPlug(values[i]);
|
|
Register_Object( testPlug1 );
|
|
tree1.AddValue(testPlug1, values[i]);
|
|
tree2.AddValue(testPlug1, values[i]);
|
|
}
|
|
Test_Message("TreeTestNode::RunTest Create = " << (Now() - startTicks) << endl);
|
|
|
|
/*
|
|
* Iterate over both sockets
|
|
*/
|
|
startTicks = Now();
|
|
{
|
|
TreeIteratorOf<TreeTestPlug*, int> iterator1(tree1);
|
|
TreeIteratorOf<TreeTestPlug*, int> iterator2(tree2);
|
|
|
|
Verify( iterator1.GetSize() == TEST_CLASS );
|
|
Verify( iterator2.GetSize() == TEST_CLASS );
|
|
|
|
i = 0;
|
|
while ((testPlug1 = iterator1.ReadAndNext()) != NULL)
|
|
{
|
|
Check( testPlug1 );
|
|
Verify( testPlug1->value == i );
|
|
i++;
|
|
}
|
|
Verify( i == TEST_CLASS );
|
|
|
|
i = 0;
|
|
while ((testPlug1 = iterator2.ReadAndNext()) != NULL)
|
|
{
|
|
Check( testPlug1 );
|
|
Verify( testPlug1->value == i );
|
|
i++;
|
|
}
|
|
Verify( i == TEST_CLASS );
|
|
}
|
|
Test_Message("TreeTestNode::RunTest Iterate = " << (Now() - startTicks) << endl);
|
|
|
|
/*
|
|
* Find
|
|
*/
|
|
startTicks = Now();
|
|
{
|
|
TreeIteratorOf<TreeTestPlug*, int> iterator1(tree1);
|
|
TreeIteratorOf<TreeTestPlug*, int> iterator2(tree2);
|
|
|
|
for (i = 0; i < TEST_CLASS; i++)
|
|
{
|
|
testPlug1 = iterator1.Find(i);
|
|
testPlug2 = iterator2.Find(i);
|
|
|
|
Check( testPlug1 );
|
|
Check( testPlug2 );
|
|
|
|
Verify( testPlug1->value == i );
|
|
Verify( testPlug2->value == i );
|
|
|
|
Verify( testPlug1 == testPlug2 );
|
|
}
|
|
}
|
|
Test_Message("TreeTestNode::RunTest Find = " << (Now() - startTicks) << endl);
|
|
|
|
/*
|
|
* Destroy from tree1, verify with tree2
|
|
*/
|
|
startTicks = Now();
|
|
{
|
|
TreeIteratorOf<TreeTestPlug*, int> iterator1(tree1);
|
|
TreeIteratorOf<TreeTestPlug*, int> iterator2(tree2);
|
|
|
|
Verify( iterator1.GetSize() == TEST_CLASS );
|
|
Verify( iterator2.GetSize() == TEST_CLASS );
|
|
|
|
i = 0;
|
|
while ((testPlug1 = iterator1.ReadAndNext()) != NULL)
|
|
{
|
|
Check( testPlug1 );
|
|
Verify( testPlug1->value == i );
|
|
i++;
|
|
|
|
Unregister_Object(testPlug1);
|
|
delete(testPlug1);
|
|
}
|
|
Verify( i == TEST_CLASS );
|
|
|
|
Verify( iterator1.GetSize() == 0 );
|
|
Verify( iterator2.GetSize() == 0 );
|
|
}
|
|
Test_Message("TreeTestNode::RunTest Destroy = " << (Now() - startTicks) << endl);
|
|
}
|
|
|
|
//
|
|
//###########################################################################
|
|
// RunTest
|
|
//###########################################################################
|
|
//
|
|
void
|
|
TreeTestNode::RunTest()
|
|
{
|
|
TreeTestPlug *testPlug1, *testPlug2;
|
|
int values[TEST_CLASS];
|
|
int i, j;
|
|
// Time startTicks;
|
|
|
|
/*
|
|
* Generate unique values, shuffle them
|
|
*/
|
|
for (i = 0; i < TEST_CLASS; i++) {
|
|
values[i] = i;
|
|
}
|
|
for (i = 0; i < TEST_CLASS; i++) {
|
|
int tmp;
|
|
|
|
j = i + RandInt(TEST_CLASS - i) - 1;
|
|
tmp = values[j];
|
|
values[j] = values[i];
|
|
values[i] = tmp;
|
|
}
|
|
|
|
//
|
|
//--------------------------------------------------------------------
|
|
// Stress tests
|
|
//--------------------------------------------------------------------
|
|
//
|
|
|
|
/*
|
|
* Create plugs and add to both sockets
|
|
*/
|
|
for (i = 0; i < TEST_CLASS; i++)
|
|
{
|
|
testPlug1 = new TreeTestPlug(values[i]);
|
|
Register_Object(testPlug1);
|
|
tree1.AddValue(testPlug1, values[i]);
|
|
tree2.AddValue(testPlug1, values[i]);
|
|
}
|
|
VerifyOrder();
|
|
|
|
/*
|
|
* Find
|
|
*/
|
|
{
|
|
for (i = 0; i < TEST_CLASS; i++)
|
|
{
|
|
testPlug1 = tree1.Find(i);
|
|
testPlug2 = tree2.Find(i);
|
|
|
|
Check( testPlug1 );
|
|
Check( testPlug2 );
|
|
|
|
Verify( testPlug1->value == i );
|
|
Verify( testPlug2->value == i );
|
|
|
|
Verify( testPlug1 == testPlug2 );
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Test first and last
|
|
*/
|
|
{
|
|
TreeIteratorOf<TreeTestPlug*, int> iterator1(tree1);
|
|
TreeIteratorOf<TreeTestPlug*, int> iterator2(tree2);
|
|
|
|
Verify( iterator1.GetSize() == TEST_CLASS );
|
|
Verify( iterator2.GetSize() == TEST_CLASS );
|
|
|
|
iterator1.First();
|
|
iterator2.First();
|
|
|
|
testPlug1 = iterator1.GetCurrent();
|
|
testPlug2 = iterator2.GetCurrent();
|
|
Check( testPlug1 );
|
|
Check( testPlug2 );
|
|
|
|
Verify( testPlug1 == testPlug2 );
|
|
Verify( testPlug1 == iterator1.GetNth(0) );
|
|
Verify( testPlug1 == iterator2.GetNth(0) );
|
|
}
|
|
|
|
/*
|
|
* Test next and prev
|
|
*/
|
|
{
|
|
TreeIteratorOf<TreeTestPlug*, int> iterator1(tree1);
|
|
TreeIteratorOf<TreeTestPlug*, int> iterator2(tree2);
|
|
|
|
Verify( iterator1.GetSize() == TEST_CLASS );
|
|
Verify( iterator2.GetSize() == TEST_CLASS );
|
|
|
|
i = 0;
|
|
while ((testPlug1 = iterator1.GetCurrent()) != NULL)
|
|
{
|
|
testPlug2 = iterator2.GetCurrent();
|
|
|
|
Check( testPlug1 );
|
|
Check( testPlug2 );
|
|
Verify( testPlug1 == testPlug2 );
|
|
|
|
Verify( testPlug1->value == i );
|
|
Verify( testPlug2->value == i );
|
|
|
|
iterator1.Next();
|
|
iterator2.Next();
|
|
|
|
i++;
|
|
}
|
|
Verify( i == TEST_CLASS );
|
|
}
|
|
|
|
/*
|
|
* Test read next and read prev
|
|
*/
|
|
{
|
|
TreeIteratorOf<TreeTestPlug*, int> iterator1(tree1);
|
|
TreeIteratorOf<TreeTestPlug*, int> iterator2(tree2);
|
|
|
|
Verify( iterator1.GetSize() == TEST_CLASS );
|
|
Verify( iterator2.GetSize() == TEST_CLASS );
|
|
|
|
i = 0;
|
|
while ((testPlug1 = iterator1.ReadAndNext()) != NULL)
|
|
{
|
|
testPlug2 = iterator2.ReadAndNext();
|
|
|
|
Check( testPlug1 );
|
|
Check( testPlug2 );
|
|
Verify( testPlug1 == testPlug2 );
|
|
|
|
Verify( testPlug1->value == i );
|
|
Verify( testPlug2->value == i );
|
|
|
|
i++;
|
|
}
|
|
Verify( i == TEST_CLASS );
|
|
}
|
|
|
|
/*
|
|
* Test nth
|
|
*/
|
|
{
|
|
TreeIteratorOf<TreeTestPlug*, int> iterator1(tree1);
|
|
TreeIteratorOf<TreeTestPlug*, int> iterator2(tree2);
|
|
|
|
Verify( iterator1.GetSize() == TEST_CLASS );
|
|
Verify( iterator2.GetSize() == TEST_CLASS );
|
|
|
|
for (i = 0; i < TEST_CLASS; i++)
|
|
{
|
|
testPlug1 = iterator1.GetNth((int)i);
|
|
testPlug2 = iterator2.GetNth((int)i);
|
|
|
|
Check( testPlug1 );
|
|
Check( testPlug2 );
|
|
Verify( testPlug1 == testPlug2 );
|
|
|
|
Verify( testPlug1->value == i );
|
|
Verify( testPlug2->value == i );
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Test Remove
|
|
*/
|
|
{
|
|
TreeIteratorOf<TreeTestPlug*, int> iterator1(tree1);
|
|
TreeIteratorOf<TreeTestPlug*, int> iterator2(tree2);
|
|
|
|
Verify( iterator1.GetSize() == TEST_CLASS );
|
|
Verify( iterator2.GetSize() == TEST_CLASS );
|
|
|
|
i = 0;
|
|
while ((testPlug1 = iterator1.GetCurrent()) != NULL)
|
|
{
|
|
Check( testPlug1 );
|
|
Verify( testPlug1->value == i );
|
|
|
|
iterator1.Remove();
|
|
|
|
testPlug2 = iterator2.GetNth(0);
|
|
|
|
Check( testPlug2 );
|
|
Verify( testPlug2->value == i );
|
|
Verify( testPlug1 == testPlug2 );
|
|
|
|
Unregister_Object(testPlug2);
|
|
delete testPlug2;
|
|
|
|
i++;
|
|
VerifyOrder();
|
|
}
|
|
Verify( i == TEST_CLASS );
|
|
Verify( iterator1.GetSize() == 0 );
|
|
Verify( iterator2.GetSize() == 0 );
|
|
}
|
|
|
|
/*
|
|
* Test random deletion
|
|
*/
|
|
/*
|
|
* Add plugs to both sockets
|
|
*/
|
|
{
|
|
TreeIteratorOf<TreeTestPlug*, int> iterator1(tree1);
|
|
TreeIteratorOf<TreeTestPlug*, int> iterator2(tree2);
|
|
|
|
Verify( iterator1.GetSize() == 0 );
|
|
Verify( iterator2.GetSize() == 0 );
|
|
|
|
for (i = 0; i < TEST_CLASS; i++)
|
|
{
|
|
testPlug1 = new TreeTestPlug(values[i]);
|
|
Register_Object( testPlug1 );
|
|
tree1.AddValue(testPlug1, values[i]);
|
|
tree2.AddValue(testPlug1, values[i]);
|
|
|
|
VerifyOrder();
|
|
}
|
|
VerifyOrder();
|
|
}
|
|
|
|
/*
|
|
* Perform random deletion
|
|
*/
|
|
{
|
|
int size, index;
|
|
TreeIteratorOf<TreeTestPlug*, int> iterator1(tree1);
|
|
TreeIteratorOf<TreeTestPlug*, int> iterator2(tree2);
|
|
|
|
Verify( iterator1.GetSize() == TEST_CLASS );
|
|
Verify( iterator2.GetSize() == TEST_CLASS );
|
|
|
|
i = 0;
|
|
while((size = iterator1.GetSize()) != 0)
|
|
{
|
|
index = RandInt(size) - 1;
|
|
testPlug1 = iterator1.GetNth(index);
|
|
Check( testPlug1 );
|
|
iterator1.Remove();
|
|
|
|
testPlug2 = iterator2.GetNth(index);
|
|
Check( testPlug2 );
|
|
Verify( testPlug1 == testPlug2 );
|
|
|
|
Unregister_Object( testPlug2 );
|
|
delete(testPlug2);
|
|
|
|
i++;
|
|
VerifyOrder();
|
|
}
|
|
Verify( i == TEST_CLASS );
|
|
Verify( iterator1.GetSize() == 0 );
|
|
Verify( iterator2.GetSize() == 0 );
|
|
}
|
|
}
|
|
|
|
|