Ejemplo n.º 1
0
void testRemove() {
	Hash<int, int> h;

	for (vector<pair<int, int> >::const_iterator i = ints.begin(); i != ints.begin() + ints.size() / 2; ++i) {
		h.put(i->first, i->second);
	}

	for (vector<pair<int, int> >::const_iterator i = ints.begin(); i != ints.begin() + ints.size() / 2; ++i) {
		h.remove(i->first);
	}

	if (!h.isEmpty()) {
		cout << "testRemove failed\n";
	}

	for (vector<pair<int, int> >::const_iterator i = ints.begin(); i != ints.end(); ++i) {
		h.put(i->first, i->second);
	}

	for (map<int, int>::const_iterator i = uniqueInts.begin(); i != uniqueInts.end(); ++i) {
		if (h.get(i->first)->value != i->second) {
			cout << "Fail on remove test with number " << i->first << ". Expected: " << i->second << " Got: " << h.get(i->first)->value << endl;
		}
	}
}
Ejemplo n.º 2
0
int main(int argc, const char *argv[])
{
    Node first(10, 20);
    Node second(30, 40);
    Node third(100, 50);
    Node forth(100, 33);
    first.setNext(&second);
    second.setNext(&third);
    std::cout << first.getTail()->getValue() << std::endl;
    std::cout << second.getTail()->getValue() << std::endl;
    std::cout << third.getTail()->getValue() << std::endl;

    Hash h;
    h.put(10,20);
    h.put(30,40);
    h.put(10,30);
    h.put(30,50);
    std::cout << h.get(10,20) << std::endl;
    std::cout << h.get(11,20) << std::endl;
    std::cout << h.get(10,30) << std::endl;
    std::cout << h.get(31,100) << std::endl;
    std::cout << h.get(30,40) << std::endl;
    std::cout << h.get(30,50) << std::endl;

    return 0;
}
Ejemplo n.º 3
0
void testReplace() {
	Hash<int, int> h;

	h.put(42, 11);
	h.put(32, 10);
	h.put(90, 3);
	h.put(42, 9);
	h.put(50, 3);

	if (h.get(42)->value != 9) {
		cout << "testReplace failed\n";
	}
}
Ejemplo n.º 4
0
void testAdd() {
	Hash<int, int> h;

	h.put(42, 11);

	if (h.get(42) == h.end()) {
		cout << "testAdd failed\n";
	}
}
Ejemplo n.º 5
0
int bfs(int x){
	//x is goal money
	queue<int> Q;
	Hash m;//money -> step
    m.put(0,0);
	Q.push(0);
	while(!Q.empty()){
		int h = Q.front();
		Q.pop();
		if(h==x) return m.get(x);
		for(int i=0;i<6;i++)
			for(int j=-1;j<=1;j+=2){
				int y = h+j*d[i];
				if(m.get(y)!=-1) continue;
				m.put(y,m.get(h)+1);
				Q.push(y);
			}
	}
	return -1;
}
Ejemplo n.º 6
0
void testManyStrings() {
	Hash<string, string> h;

	for (vector<pair<string, string> >::const_iterator i = strings.begin(); i != strings.end(); ++i) {
		h.put(i->first, i->second);
	}

	for (vector<pair<string, string> >::const_iterator i = strings.begin(); i != strings.end(); ++i) {
		if (h.get(i->first)->value != i->second) {
			cout << "Fail on string test with string " << i->first << ". Expected: " << i->second << " Got: " << h.get(i->first)->value << endl;
		}
	}
}
Ejemplo n.º 7
0
void testManyInts() {
	Hash<int, int> h;

	for (vector<pair<int, int> >::const_iterator i = ints.begin(); i != ints.end(); ++i) {
		h.put(i->first, i->second);
	}

	for (map<int, int>::const_iterator i = uniqueInts.begin(); i != uniqueInts.end(); ++i) {
		if (h.get(i->first)->value != i->second) {
			cout << "Fail on int test with number " << i->first << ". Expected: " << i->second << " Got: " << h.get(i->first)->value << endl;
		}
	}
}