Project 5 Test Data

There were 40 test cases. For the first 12, your decrypt function should have returned false. This was worth 1 point. For the next 27 cases, your decrypt function should have returned true; this was worth 1 point, and you also received 3 points if the decrypt function wrote the proper plaintext. The last case was worth 5 points. The total of your points (125 were possible) was multiplied by 3/5 to produce your correctness score (out of 75).

Each test case produced a single digit of output: 0, 1, 3, or 4 (or 5 for the last case), indicating how many points you earned on that test case. To run the test cases:

  1. Remove the main routine from your decrypt.cpp file.
  2. Append the following text to the end of your decrypt.cpp file, and build the resulting program.
  3. For any test case you wish to try, run the program, providing as input the test number.
#include <iostream> #include <fstream> #include <sstream> #include <string> #include <cstring> #include <cstdlib> using namespace std; const int OKTEXT = 3; bool appendNewline = false; bool decrypt(const char ciphertext[], const char crib[]); int dotest(const char* ciphertext, const char* crib, const char* plaintext) { string s; if (appendNewline) { s.reserve(strlen(ciphertext) + 1); ciphertext = s.assign(ciphertext).append(1, '\n').c_str(); } ostringstream oss; streambuf *sb = cout.rdbuf(oss.rdbuf()); bool result = decrypt(ciphertext, crib); cout.rdbuf(sb); if (plaintext == nullptr) return result ? 0 : 1; // 1 point if returns false when should int retval = 0; if (result) retval++; // 1 point if returns true when should s = oss.str(); if (s == plaintext) retval += OKTEXT; // plus OKTEXT points for correct output text else if (!s.empty() && s.back() == '\n') { s.pop_back(); if (s == plaintext) retval += OKTEXT; // plus OKTEXT points for correct output text } return retval; } void testone(int n) { int res; switch (n) { default: { cout << "Bad argument" << endl; } break; case 1: { res = dotest("", "", nullptr); } break; case 2: { res = dotest("", "a", nullptr); } break; case 3: { res = dotest("a", "", nullptr); } break; case 4: { res = dotest("ab", "b", nullptr); } break; case 5: { res = dotest("abc", "de f", nullptr); } break; case 6: { res = dotest("abc", "de-f", nullptr); } break; case 7: { res = dotest("abc", "ded", nullptr); } break; case 8: { res = dotest("aba", "def", nullptr); } break; case 9: { res = dotest("agbhc\nabcd", "def", nullptr); } break; case 10: { res = dotest("ab cd", "ef ge", nullptr); } break; case 11: { res = dotest("ab ca", "ef gh", nullptr); } break; case 12: { res = dotest("ab\ncd", "ef gh", nullptr); } break; case 13: { res = dotest("a", "b", "B"); } break; case 14: { res = dotest("ab", "ba", "BA"); } break; case 15: { res = dotest("aba", "ded", "DED"); } break; case 16: { res = dotest("ab a", "c", "Cb C"); } break; case 17: { res = dotest("abc ab bca", "de", "DEc DE EcD"); } break; case 18: { res = dotest("abc ab bc a", "de", "DEc DE Ec D"); if (res < OKTEXT) { int res2 = dotest("abc ab bc a", "de", "aDE aD DE a"); if (res2 > res) res = res2; } } break; case 19: { res = dotest("abccd abccc abccb abcca", "xyzzy", "XYZZd XYZZZ XYZZY XYZZX"); } break; case 20: { res = dotest("abc abc", "def", "DEF DEF"); } break; case 21: { res = dotest("abc", "dEf", "DEF"); } break; case 22: { res = dotest("abC", "dEf", "DEF"); } break; case 23: { res = dotest("aba", "dED", "DED"); } break; case 24: { res = dotest("abA", "ded", "DED"); } break; case 25: { res = dotest("abc", "def ", "DEF"); } break; case 26: { res = dotest("abc", "def!32", "DEF"); } break; case 27: { res = dotest("abc", "32!def", "DEF"); } break; case 28: { res = dotest("abc!", "def", "DEF!"); } break; case 29: { res = dotest("@@abc!", "def", "@@DEF!"); } break; case 30: { res = dotest("abc\nagbhc", "def", "DEF\nDgEhF"); } break; case 31: { res = dotest("agbhc\nabc", "def", "DgEhF\nDEF"); } break; case 32: { res = dotest("abc de fab cde", "gh ijk", "JKc GH IJK cGH"); } break; case 33: { res = dotest("abc de fabc ef ab cde fg", "gh ijk", "GHI JK fGHI Kf GH IJK fg"); } break; case 34: { res = dotest("abc de fab dj abd de abc", "gh ijg", "IJc Ge fIJ GH IJG Ge IJc"); } break; case 35: { res = dotest("ab cd", "ef#$% gh", "EF GH"); } break; case 36: { res = dotest("ab#$% cd", "ef gh", "EF#$% GH"); } break; case 37: { res = dotest("ab\nbc", "de", "DE\nEc"); if (res < OKTEXT) { int res2 = dotest("ab\nbc", "de", "aD\nDE"); if (res2 > res) res = res2; } } break; case 38: { string cs; for (int k = 0; k < 60; k++) cs += " a"; cs += '\n'; string ct("ab"); for (int k = 0; k < 59; k++) ct += " a"; ct += '\n'; string ps; for (int k = 0; k < 60; k++) ps += " C"; ps += '\n'; string pt("CD"); for (int k = 0; k < 59; k++) pt += " C"; pt += '\n'; for (int k = 0; k < 49; k++) { ct += cs; pt += ps; } ct.pop_back(); pt.pop_back(); res = dotest(ct.c_str(), "cd", pt.c_str()); } break; case 39: { string crib; crib.reserve(1000003); crib.append(500000,':'); crib += "def"; crib.append(500000,':'); res = dotest("abc", crib.c_str(), "DEF"); } break; case 40: { string crib; crib.reserve(1000003); crib.append(500000,':'); crib += "def"; crib.append(500000,':'); res = dotest("abc", crib.c_str(), "DEF"); if (res > 0) { string crib2; crib2.reserve(1000122); for (int k = 0; k < 60; k++) crib2 += "b "; crib2.append(1000000, ' '); crib2 += "b "; string ct; for (int k = 0; k < 60; k++) ct += "a "; res = dotest(ct.c_str(), crib2.c_str(), nullptr); res *= (2+OKTEXT); } } break; } cout << res << endl; } int main() { cout << "Enter a test number (1 to 40): "; int n; cin >> n; if (n < 1 || n > 40) { cout << "Bad test number" << endl; return 1; } testone(n); }