summaryrefslogtreecommitdiff
path: root/src/tests/hash.cpp
blob: f9a8f1262459b996ff7ac727932571c63b8fe08e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "hash.h"
#include "staticstring.h"

int main()
{
	const char *names[]={
		"Homer the Great",
		"And Maggie Makes Three",
		"Bart's Comet",
		"Homie The Clown",
		"Bart Vs Australia",
		"Homer vs Patty and Selma",
		"A star is burns",
		"Lisa's Wedding",
		"Two Dozen and One Greyhounds",
		"The PTA Disbands",
		"Round Springfield",
		"The Springfield connection",
		"Lemon of Troy",
		"Who Shot Mr. Burns (Pt. 1)",
		"Who Shot Mr. Burns (pt. 2)",
		"Radioactive Man",
		"Home Sweet Homediddly-dum-doodly",
		"Bart Sells His Soul",
		"Lisa the Vegetarian",
		"Treehouse of horror VI",
		"King Size Homer",
		"Mother Simpson",
		"Sideshow Bob's Last Gleaming",
		"The Simpson's 138th Show Spectacular",
		"Marge Be Not Proud",
		"Team Homer",
		"Two Bad Neighbors",
		"Scenes From the Class Struggle in Springfield",
		"Bart the Fink",
		"Lisa the Iconoclast",
		"Homer the Smithers",
		"The Day the Violence Died",
		"A Fish Called Selma",
		"Bart on the road",
		"22 Short Films about Springfield",
		"The Curse of the Flying Hellfish",
		"Much Apu about Nothing",
		"Homerpalooza",
		"The Summer of 4 Ft 2",
		"Treehouse of Horror VII",
		"You Only Move Twice",
		"The Homer They Fall",
		"Burns Baby Burns",
		"Bart After Dark",
		"A Millhouse Divided",
		"Lisas Date With Destiny",
		"Hurricane Neddy",
		"The Mysterious Voyage of Our Homer",
		"The Springfield Files",
		"The Twisted World of Marge Simpson",
		"Mountain of Madness",
		NULL
	};

	Hash<std::string, int> sTest;

	printf("Inserting\n-------------------\n\n");
	for( int j = 0; j < 33; j++ )
	{
		sTest[names[j]] = j;
	}

	printf("Getting\n-------------------\n\n");

	sTest.erase("Homer the Great");
	sTest["Bart's Comet"].erase();

	for( Hash<std::string, int>::iterator i = sTest.begin();
		 i != sTest.end(); i++ )
	{
		Hash<std::string, int>::iterator j = i;
		printf("%d: %s\n", (*j).second, (*j).first.c_str() );
	}

	for( int j = 0; j < 33; j++ )
	{
		if( sTest[names[j]].isFilled() )
		{
			if( sTest[names[j]] != j )
			{
				printf("'%s' should be %d, is %d\n",
					names[j], j,
					sTest[names[j]].value()
					);
			}
		}
		else
		{
			printf("Missing element %d, '%s'\n", j, names[j] );
		}
	}
}