When the following program is compiled along with Table.cpp, it can be run with input 1 through 58 to test your solution. Test cases 1 through 9 were worth 2.1 points each; cases 10 through 21, 3.6 points each; cases 22 through 50, 1.3 points each; and 51 through 58, testing for the bonus, 0.625 points each.
#include "Table.h" #include <iostream> #include <string> #include <vector> #include <initializer_list> #include <algorithm> #include <type_traits> #include <cstdlib> #include <cassert> using namespace std; using VS = vector<string>; using VVS = vector<VS>; bool goodCanReturnTrue() { return Table("Z", VS{ "N", "Z" }).good(); } void insert(Table& t, const initializer_list<string>& sl) { for (auto& s : sl) t.insert(s); } bool eq(VVS& lhs, const initializer_list<VS>& rhs) { if (lhs.size() != rhs.size()) return false; sort(lhs.begin(), lhs.end()); return equal(lhs.begin(), lhs.end(), rhs.begin()); } void testone(int n) { VVS v; switch (n) { default: { cout << "Bad argument" << endl; } break; case 1: { assert( ! Table("", VS{ }).good()); assert(goodCanReturnTrue()); } break; case 2: { assert( ! Table("", VS{ "" }).good()); assert(goodCanReturnTrue()); } break; case 3: { assert( ! Table("", VS{ "cc", "aa" }).good()); assert(goodCanReturnTrue()); } break; case 4: { assert( ! Table("bb", VS{ }).good()); assert(goodCanReturnTrue()); } break; case 5: { assert( ! Table("cc", VS{ "cc", "", "aa" }).good()); assert(goodCanReturnTrue()); } break; case 6: { assert( ! Table("cc", VS{ "cc", "aa", "tt", "aa" }).good()); assert(goodCanReturnTrue()); } break; case 7: { assert( ! Table("cc", VS{ "aa", "cc", "tt", "aa" }).good()); assert(goodCanReturnTrue()); } break; case 8: { assert( ! Table("bb", VS{ "cc", "aa" }).good()); assert(goodCanReturnTrue()); } break; case 9: { // good table doesn't need good to finish setting up Table t("Z", VS{ "N", "Z" }); t.insert("nn 99"); t.find("99", v); assert(eq(v, { { "nn", "99" } })); } break; case 10: { Table t("aa", VS{ "cc", "aa", "tt"}); assert(!t.insert("xx yy")); assert(!t.insert("xx yy zz ww")); assert(t.insert("xx yy zz")); } break; case 11: { Table t("aa", VS{ "cc", "aa", "tt" }); t.insert("xx yy"); t.insert("xx yy zz ww"); t.find("yy", v); assert(v.empty()); } break; case 12: { Table t("aa", VS{ "cc", "aa", "tt" }); t.insert(" \txx\t yy \tzz \t"); t.insert("'xx' 'yy' 'ww'"); t.insert("xx' yy zz'"); t.insert("x'x yy z'z"); t.insert("x''x yy z''z"); t.insert("'x''x' yy 'zz'''"); t.insert("'xx'yy vv"); t.find("yy", v); assert(eq(v, { { "x''x", "yy", "z''z" }, { "x'x", "yy", "z'z" }, { "x'x", "yy", "zz'" }, { "xx", "yy", "vv" }, { "xx", "yy", "ww" }, { "xx", "yy", "zz" }, { "xx'", "yy", "zz'" } })); } break; case 13: { Table t("aa", VS{ "cc", "aa", "tt" }); t.insert("xx yy zz"); t.insert("xx yy xx"); t.find("gg", v); assert(v.empty()); } break; case 14: { Table t("aa", VS{ "cc", "aa", "tt" }); t.insert("xx yy zz"); t.insert("xx yy xx"); t.find("xx", v); assert(v.empty()); } break; case 15: { Table t("aa", VS{ "cc", "aa", "tt" }); t.insert("xx yy zz"); t.insert("xx yy ww"); v.push_back(VS{ "dd", "ee", "ff" }); t.find("gg", v); assert(v.empty()); } break; case 16: { Table t("aa", VS{ "cc", "aa", "tt" }); t.insert("xx yy zz"); t.insert("xx dd ww"); t.insert("xx yy ww"); t.insert("xx yy vv"); t.insert("xx dd vv"); t.insert("xx dd uu"); t.insert("xx yy uu"); t.find("yy", v); assert(eq(v, { { "xx", "yy", "uu" }, { "xx", "yy", "vv" }, { "xx", "yy", "ww" }, { "xx", "yy", "zz" } })); } break; case 17: { Table t("aa", VS{ "cc", "aa", "tt" }); t.insert("xx yy zz"); t.insert("xx dd ww"); t.insert("xx yy ww"); t.insert("xx yy vv"); t.insert("xx dd vv"); t.insert("xx dd uu"); t.insert("xx yy uu"); v.push_back(VS{ "dd", "ee", "ff" }); t.find("yy", v); assert(eq(v, { { "xx", "yy", "uu" }, { "xx", "yy", "vv" }, { "xx", "yy", "ww" }, { "xx", "yy", "zz" } })); } break; case 18: { Table t("aa", VS{ "cc", "aa", "tt" }); t.insert("xx yy zz"); t.insert("xx yy ww"); t.insert("xx yy zz"); t.insert("xx yy zz"); t.insert("xx dd ww"); t.insert("xx yy ww"); t.find("yy", v); assert(eq(v, { { "xx", "yy", "ww" }, { "xx", "yy", "ww" }, { "xx", "yy", "zz" }, { "xx", "yy", "zz" }, { "xx", "yy", "zz" } })); } break; case 19: { Table t("aa", VS{ "cc", "aaaa", "tt", "aabb", "aa" }); t.insert("xx yy zz ww vv"); t.find("yy", v); assert(v.empty()); t.find("ww", v); assert(v.empty()); t.find("vv", v); assert(eq(v, { { "xx", "yy", "zz", "ww", "vv" } })); } break; case 20: { Table t("aa aa", VS{ "cc", "aa aa", "tt" }); t.insert("xx yy zz"); t.find("yy", v); assert(eq(v, { { "xx", "yy", "zz" } })); } break; case 21: { Table t("aa", VS{ "cc", "aa", "tt" }); t.insert("xx 'yy yy' zz"); t.find("yy yy", v); assert(eq(v, { { "xx", "yy yy", "zz" } })); } break; case 22: { Table t("aa", VS{ "cc", "aa", "tt" }); t.insert("xx yy zz"); assert(t.select("", v) == -1 && v.empty()); } break; case 23: { Table t("aa", VS{ "cc", "aa", "tt" }); t.insert("xx yy zz"); assert(t.select("cc", v) == -1 && v.empty()); } break; case 24: { Table t("aa", VS{ "cc", "aa", "tt" }); t.insert("xx yy zz"); assert(t.select("cc =", v) == -1 && v.empty()); } break; case 25: { Table t("aa", VS{ "cc", "aa", "tt" }); t.insert("xx yy zz"); assert(t.select("cc = xx yy", v) == -1 && v.empty()); } break; case 26: { Table t("aa", VS{ "cc", "aa", "tt" }); t.insert("xx yy zz"); assert(t.select("bb = xx", v) == -1 && v.empty()); } break; case 27: { Table t("aa", VS{ "cc", "aa", "tt" }); t.insert("xx yy zz"); assert(t.select("cc xx xx", v) == -1 && v.empty()); } break; case 28: { Table t("aa", VS{ "cc", "aa", "tt" }); t.insert("xx yy zz"); v.push_back(VS{ "dd", "ee", "ff" }); assert(t.select("cc =", v) == -1 && v.empty()); } break; case 29: { Table t("aa", VS{ "cc", "aa", "tt" }); t.insert("xx yy zz"); t.insert("yy yy zz"); t.insert("xx yy vv"); t.insert("ww yy vv"); assert(t.select("cc = xx", v) == 0 && eq(v, { { "xx", "yy", "vv" }, { "xx", "yy", "zz" } })); } break; case 30: { Table t("aa", VS{ "cc", "aa", "tt" }); t.insert("xx yy zz"); t.insert("yy yy zz"); t.insert("xx yy vv"); t.insert("ww yy vv"); v.push_back(VS{ "dd", "ee", "ff" }); assert(t.select("cc = xx", v) == 0 && eq(v, { { "xx", "yy", "vv" }, { "xx", "yy", "zz" } })); } break; case 31: { Table t("aa", VS{ "cc", "aa", "tt" }); t.insert("xx yy zz"); t.insert("yy yy zz"); t.insert("xx yy vv"); t.insert("ww yy vv"); assert(t.select("cc == xx", v) == 0 && eq(v, { { "xx", "yy", "vv" }, { "xx", "yy", "zz" } })); } break; case 32: { Table t("aa", VS{ "cc", "aa", "tt" }); t.insert("xx yy zz"); t.insert("yy yy zz"); t.insert("xx yy vv"); t.insert("ww yy vv"); assert(t.select("cc != xx", v) == 0 && eq(v, { { "ww", "yy", "vv" }, { "yy", "yy", "zz" } })); } break; case 33: { Table t("aa", VS{ "cc", "aa", "tt" }); t.insert("xx yy zz"); t.insert("yy yy zz"); t.insert("xx yy vv"); t.insert("ww yy vv"); assert(t.select("cc != xx", v) == 0 && eq(v, { { "ww", "yy", "vv" }, { "yy", "yy", "zz" } })); } break; case 34: { Table t("aa", VS{ "cc", "aa", "tt" }); t.insert("xx yy zz"); t.insert("yy yy zz"); t.insert("xx yy vv"); t.insert("ww yy vv"); assert(t.select("cc < xx", v) == 0 && eq(v, { { "ww", "yy", "vv" } })); assert(t.select("cc > xx", v) == 0 && eq(v, { { "yy", "yy", "zz" } })); } break; case 35: { Table t("aa", VS{ "cc", "aa", "tt" }); t.insert("xx yy zz"); t.insert("yy yy zz"); t.insert("xx yy vv"); t.insert("ww yy vv"); assert(t.select("cc <= xx", v) == 0 && eq(v, { { "ww", "yy", "vv" }, { "xx", "yy", "vv" }, { "xx", "yy", "zz" } })); assert(t.select("cc >= xx", v) == 0 && eq(v, { { "xx", "yy", "vv" }, { "xx", "yy", "zz" }, { "yy", "yy", "zz" } })); } break; case 36: { Table t("aa", VS{ "cc", "aa", "tt" }); t.insert("xx yy zz"); t.insert("yy yy zz"); t.insert("xx yy vv"); t.insert("ww yy vv"); assert(t.select("'cc' '=' 'xx'", v) == 0 && eq(v, { { "xx", "yy", "vv" }, { "xx", "yy", "zz" } })); } break; case 37: { Table t("aa", VS{ "cc", "aa", "tt" }); t.insert("xx yy zz"); t.insert("42 yy zz"); assert(t.select("cc NE xx", v) == -1 && v.empty()); } break; case 38: { Table t("aa", VS{ "cc", "aa", "tt" }); t.insert("42 yy zz"); assert(t.select("cc EQ 42#", v) == -1 && v.empty()); } break; case 39: { Table t("aa", VS{ "cc", "aa", "tt" }); t.insert("42 yy zz"); t.insert("43 yy zz"); assert(t.select("cc EQ 42", v) == 0 && eq(v, { { "42", "yy", "zz" } })); } break; case 40: { Table t("aa", VS{ "cc", "aa", "tt" }); t.insert("42.1 yy zz"); t.insert("0042.0 yy zz"); assert(t.select("cc EQ 42", v) == 0 && eq(v, { { "0042.0", "yy", "zz" } })); } break; case 41: { Table t("aa", VS{ "cc", "aa", "tt" }); t.insert("42.1 yy zz"); t.insert("42 yy zz"); assert(t.select("cc EQ 0042.0", v) == 0 && eq(v, { { "42", "yy", "zz" } })); } break; case 42: { Table t("aa", VS{ "cc", "aa", "tt" }); t.insert("-42 yy zz"); t.insert("42 yy ww"); assert(t.select("cc EQ -42", v) == 0 && eq(v, { { "-42", "yy", "zz" } })); } break; case 43: { Table t("aa", VS{ "cc", "aa", "tt" }); t.insert("41 yy ww"); t.insert("42 yy zz"); t.insert("43 yy vv"); for (string op : { "EQ", "Eq", "eQ", "eq" }) { assert(t.select("cc " + op + " 42", v) == 0 && eq(v, { { "42", "yy", "zz" } })); } } break; case 44: { Table t("aa", VS{ "cc", "aa", "tt" }); t.insert("41 yy ww"); t.insert("42 yy zz"); t.insert("43 yy vv"); for (string op : { "NE", "Ne", "nE", "ne" }) { assert(t.select("cc " + op + " 42", v) == 0 && eq(v, { { "41", "yy", "ww" }, { "43", "yy", "vv" } })); } } break; case 45: { Table t("aa", VS{ "cc", "aa", "tt" }); t.insert("41 yy ww"); t.insert("42 yy zz"); t.insert("43 yy vv"); for (string op : { "GT", "Gt", "gT", "gt" }) { assert(t.select("cc " + op + " 42", v) == 0 && eq(v, { { "43", "yy", "vv" } })); } } break; case 46: { Table t("aa", VS{ "cc", "aa", "tt" }); t.insert("41 yy ww"); t.insert("42 yy zz"); t.insert("43 yy vv"); for (string op : { "GE", "Ge", "gE", "ge" }) { assert(t.select("cc " + op + " 42", v) == 0 && eq(v, { { "42", "yy", "zz" }, { "43", "yy", "vv" } })); } } break; case 47: { Table t("aa", VS{ "cc", "aa", "tt" }); t.insert("41 yy ww"); t.insert("42 yy zz"); t.insert("43 yy vv"); for (string op : { "LT", "Lt", "lT", "lt" }) { assert(t.select("cc " + op + " 42", v) == 0 && eq(v, { { "41", "yy", "ww" } })); } } break; case 48: { Table t("aa", VS{ "cc", "aa", "tt" }); t.insert("41 yy ww"); t.insert("42 yy zz"); t.insert("43 yy vv"); for (string op : { "LE", "Le", "lE", "le" }) { assert(t.select("cc " + op + " 42", v) == 0 && eq(v, { { "41", "yy", "ww" }, { "42", "yy", "zz" } })); } } break; case 49: { Table t("aa", VS{ "cc", "aa", "tt" }); t.insert("42 yy zz"); t.insert("43 yy zz"); t.insert("xx yy zz"); t.insert("42 yy ww"); t.insert("xx yy ww"); t.insert("xx yy vv"); t.insert("41 yy zz"); assert(t.select("cc EQ 42", v) == 3); } break; case 50: { Table t("aa", VS{ "cc", "aa", "tt" }); t.insert("42 yy zz"); t.insert("43 yy zz"); t.insert("xx yy zz"); t.insert("42 yy ww"); t.insert("xx yy ww"); t.insert("xx yy vv"); t.insert("41 yy zz"); t.select("cc EQ 42", v); assert(eq(v, { { "42", "yy", "ww" }, { "42", "yy", "zz" } })); } break; case 51: { Table t("aa", VS{ "cc", "aa", "tt" }); t.insert("xx yy zz"); t.insert("xx yy uu"); t.insert("xx yy zz"); t.insert("xx yy vv"); t.insert("xx dd uu"); t.insert("ww yy uu"); assert(t.select("tt = uu & aa != dd", v) == 0 && eq(v, { { "ww", "yy", "uu" }, { "xx", "yy", "uu" } })); } break; case 52: { Table t("aa", VS{ "cc", "aa", "tt" }); t.insert("xx yy zz"); t.insert("xx yy uu"); t.insert("xx yy zz"); t.insert("xx yy vv"); t.insert("xx dd uu"); t.insert("ww yy uu"); assert(t.select("cc = ww | aa < ee", v) == 0 && eq(v, { { "ww", "yy", "uu" }, { "xx", "dd", "uu" } })); } break; case 53: { Table t("aa", VS{ "cc", "aa", "tt" }); t.insert("xx yy zz"); t.insert("xx yy uu"); t.insert("xx dd zz"); t.insert("xx yy vv"); t.insert("xx dd uu"); t.insert("ww yy uu"); assert(t.select("cc = ww | tt != zz & aa = dd", v) == 0 && eq(v, { { "ww", "yy", "uu" }, { "xx", "dd", "uu" } })); } break; case 54: { Table t("aa", VS{ "cc", "aa", "tt" }); t.insert("xx yy zz"); t.insert("xx yy uu"); t.insert("xx dd zz"); t.insert("xx yy vv"); t.insert("xx dd uu"); t.insert("ww yy uu"); assert(t.select("( aa = dd | cc = ww ) & tt = uu", v) == 0 && eq(v, { { "ww", "yy", "uu" }, { "xx", "dd", "uu" } })); } break; case 55: { Table t("aa", VS{ "cc", "aa", "tt" }); t.insert("xx yy zz"); t.insert("xx & uu"); t.insert("| dd zz"); t.insert("xx yy vv"); t.insert("xx dd uu"); t.insert("ww yy uu"); assert(t.select("aa = & | cc = |", v) == 0 && eq(v, { { "xx", "&", "uu" }, { "|", "dd", "zz" } })); } break; case 56: { Table t("aa", VS{ "cc", "aa", "tt" }); t.insert("xx yy zz"); t.insert("xx yy uu"); t.insert("xx dd zz"); t.insert("xx yy vv"); t.insert("xx dd uu"); t.insert("ww yy uu"); assert(t.select("( aa = dd | cc = ww ) ( tt = uu )", v) == -1 && v.empty()); assert(t.select("( aa = dd | cc = ww ) & ( tt = uu )", v) == 0 && eq(v, { { "ww", "yy", "uu" }, { "xx", "dd", "uu" } })); } break; case 57: { Table t("aa", VS{ "cc", "aa", "tt" }); t.insert("41 yy ww"); t.insert("42 yy zz"); t.insert("43 yy vv"); t.insert("xx yy vv"); t.insert("44 yy vv"); t.insert("45 yy vv"); t.insert("99uu yy vv"); t.insert("46 yy vv"); assert(t.select("cc GT 42 & aa = yy", v) == 2 && eq(v, { { "43", "yy", "vv" }, { "44", "yy", "vv" }, { "45", "yy", "vv" }, { "46", "yy", "vv" } } )); } break; case 58: { assert( ! Table("cc", VS{ "cc", "&", "aa" }).good()); assert(goodCanReturnTrue()); } } } int main() { cout << "Enter test number: "; int n; cin >> n; testone(n); cout << "Passed" << endl; }