Last active
June 10, 2018 10:07
-
-
Save mkondratek/1bbded340335afaefa0f0f5e055bee93 to your computer and use it in GitHub Desktop.
zadanie_G_test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
#include "BST.h" | |
template <typename T> | |
void _assert(int line, T const& expected, T const& actual) { | |
if (expected != actual) { | |
std::cerr << "assert failed in line " << line | |
<< "\n\texpected: " << expected | |
<< "\n\t actual: " << actual << "\n"; | |
} | |
} | |
#define assertEquals(expected, actual) _assert(__LINE__, (expected), (actual)) | |
#define assertTrue(actual) _assert(__LINE__, true, (actual)) | |
#define assertFalse(actual) _assert(__LINE__, false, (actual)) | |
struct poorStruct { | |
bool operator<(poorStruct const& pr) const { return false; } | |
friend std::ostream& operator<<(std::ostream& stream, poorStruct const& pr) { | |
return stream << "k0cham pr0gram0wank"; | |
} | |
}; | |
bool PRINTING = false; | |
template <typename T> | |
void runPrints(T const& t) { | |
if (PRINTING) { | |
t.PreOrder(); | |
std::cout << std::endl; | |
t.InOrder(); | |
std::cout << std::endl; | |
t.PostOrder(); | |
std::cout << std::endl; | |
t.LevelOrder(); | |
std::cout << std::endl; | |
} | |
} | |
void TestCase01() { | |
BST<int, std::string> istrmap; | |
runPrints(istrmap); | |
assertEquals(-1, istrmap.Height()); | |
assertTrue(istrmap.Insert(0, "zero")); | |
assertEquals(0, istrmap.Height()); | |
assertFalse(istrmap.Insert(0, "orez")); | |
assertEquals(0, istrmap.Height()); | |
assertTrue(istrmap.Insert(1, "one")); | |
assertEquals(1, istrmap.Height()); | |
assertTrue(istrmap.Insert(-1, "mone")); | |
assertEquals(1, istrmap.Height()); | |
assertTrue(istrmap.Insert(-2, "mtwo")); | |
assertEquals(2, istrmap.Height()); | |
runPrints(istrmap); | |
assertFalse(istrmap.Delete(-3)); | |
assertFalse(istrmap.Delete(2)); | |
assertTrue(istrmap.Delete(0)); | |
assertEquals(2, istrmap.Height()); | |
assertFalse(istrmap.Delete(0)); | |
assertTrue(istrmap.Delete(1)); | |
assertEquals(1, istrmap.Height()); | |
assertTrue(istrmap.Delete(-2)); | |
assertEquals(0, istrmap.Height()); | |
assertTrue(istrmap.Delete(-1)); | |
assertEquals(-1, istrmap.Height()); | |
runPrints(istrmap); | |
assertTrue(istrmap.Insert(100, "lorem ipsum")); | |
runPrints(istrmap); | |
} | |
void TestCase02() { | |
BST<poorStruct, int> psmap; | |
runPrints(psmap); | |
assertTrue(psmap.Insert(poorStruct(), 0)); | |
assertEquals(0, psmap.Height()); | |
assertFalse(psmap.Insert(poorStruct(), 0)); | |
assertEquals(0, psmap.Height()); | |
runPrints(psmap); | |
assertTrue(psmap.Delete(poorStruct())); | |
assertEquals(-1, psmap.Height()); | |
runPrints(psmap); | |
} | |
int main(int argc, char* argv[]) { | |
PRINTING = argc > 1; | |
TestCase01(); | |
TestCase02(); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0zero-1mone-2mtwo1one | |
-2mtwo-1mone0zero1one | |
-2mtwo-1mone1one0zero | |
0zero-1mone1one-2mtwo | |
100lorem ipsum | |
100lorem ipsum | |
100lorem ipsum | |
100lorem ipsum | |
k0cham pr0gram0wank0 | |
k0cham pr0gram0wank0 | |
k0cham pr0gram0wank0 | |
k0cham pr0gram0wank0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment