File: deque_map.test.cpp

package info (click to toggle)
tilemaker 3.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 78,284 kB
  • sloc: cpp: 28,715; ansic: 4,052; makefile: 180; ruby: 77; sh: 6
file content (67 lines) | stat: -rw-r--r-- 1,716 bytes parent folder | download
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
#include <iostream>
#include <algorithm>
#include "external/minunit.h"
#include "deque_map.h"

MU_TEST(test_deque_map) {
	DequeMap<std::string> strs;

	mu_check(strs.size() == 0);
	mu_check(!strs.full());
	mu_check(strs.find("foo") == -1);
	mu_check(strs.add("foo") == 0);
	mu_check(!strs.full());
	mu_check(strs.find("foo") == 0);
	mu_check(strs.size() == 1);
	mu_check(strs.add("foo") == 0);
	mu_check(strs.size() == 1);
	mu_check(strs.add("bar") == 1);
	mu_check(strs.size() == 2);
	mu_check(strs.add("aardvark") == 2);
	mu_check(strs.size() == 3);
	mu_check(strs.add("foo") == 0);
	mu_check(strs.add("bar") == 1);
	mu_check(strs.add("quux") == 3);
	mu_check(strs.size() == 4);

	mu_check(strs.at(0) == "foo");
	mu_check(strs[0] == "foo");
	mu_check(strs.at(1) == "bar");
	mu_check(strs[1] == "bar");
	mu_check(strs.at(2) == "aardvark");
	mu_check(strs[2] == "aardvark");
	mu_check(strs.at(3) == "quux");
	mu_check(strs[3] == "quux");

	std::vector<std::string> rv;
	for (std::string x : strs) {
		rv.push_back(x);
	}
	mu_check(rv[0] == "aardvark");
	mu_check(rv[1] == "bar");
	mu_check(rv[2] == "foo");
	mu_check(rv[3] == "quux");

	DequeMap<std::string> boundedMap(1);
	mu_check(!boundedMap.full());
	mu_check(boundedMap.add("foo") == 0);
	mu_check(boundedMap.add("foo") == 0);
	mu_check(boundedMap.full());
	mu_check(boundedMap.add("bar") == -1);
	boundedMap.clear();
	mu_check(!boundedMap.full());
	mu_check(boundedMap.find("foo") == -1);
	mu_check(boundedMap.add("bar") == 0);
	mu_check(boundedMap.add("bar") == 0);
	mu_check(boundedMap.full());
}

MU_TEST_SUITE(test_suite_deque_map) {
	MU_RUN_TEST(test_deque_map);
}

int main() {
	MU_RUN_SUITE(test_suite_deque_map);
	MU_REPORT();
	return MU_EXIT_CODE;
}