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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
#include "homework6.h"
#include "homework6_templates.h"
#include <iostream>
#include <string>
#include <vector>
#include <utility>
int main( int argc, char** argv) {
int score = 100;
if (-1 != problem1(-1, 10) or
0 != problem1(20, 20) or
1 != problem1(56, 12)) {
std::cout<<"problem1 failed, -10\n";
score -= 10;
}
int problem2_test[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
int* ans1 = problem2_test + 9;
int* ans2 = problem2_test;
int* ans3 = problem2_test+2;
if (ans1 != problem2(problem2_test, problem2_test+9, 0) or
ans2 != problem2(problem2_test, problem2_test, 2) or
ans3 != problem2(problem2_test, problem2_test+9, 3)) {
std::cout<<"problem2 failed, -10\n";
score -= 10;
}
std::vector<int> a;
a.push_back(1);
a.push_back(2);
a.push_back(3);
std::vector<int> b;
b.push_back(3);
b.push_back(2);
b.push_back(1);
std::vector<int> result = a;
result.push_back(3);
result.push_back(2);
result.push_back(1);
problem3(a, b);
if (a != result or not b.empty()) {
std::cerr<<"problem3 failed, -10\n";
score -= 10;
}
std::vector< std::vector<int> > matrix(3, std::vector<int>(3, 0));
matrix.at(2).at(1) = 5;
if (std::make_pair(2, 1) != problem4(matrix, 5) or
std::make_pair(-1, -1) != problem4(matrix, 8)) {
std::cerr<<"problem4 failed, -10\n";
score -= 10;
}
std::vector<int> bin_vals;
bin_vals.push_back(-1);
bin_vals.push_back(1);
bin_vals.push_back(2);
bin_vals.push_back(3);
bin_vals.push_back(4);
if (1 != problem5(bin_vals, 2) or
3 != problem5(bin_vals, 0) or
2 != problem5(bin_vals, 4)) {
std::cerr<<"problem5 failed, -10\n";
score -= 10;
}
std::string x = "test1";
std::string y = "test2";
problem6_7(x, y);
int q = 6;
float r = 2.0;
problem6_7(q, r);
if ( x != "test2" or y != "test1" or q != 0 or r != 0) {
std::cerr<<"problem6_7 failed, -10\n";
score -= 10;
}
if (46 != problem8(100, 100)) {
std::cout<<"Problem 8 failed, -10\n";
score -= 10;
}
//Creation sets total to 1, then to 2, then deletion brings it to 1 again
int zero = problem9::total_problem9s;
problem9 p9;
int one = problem9::total_problem9s;
problem9* p9_p = new problem9();
int two = problem9::total_problem9s;
delete p9_p;
int one_again = problem9::total_problem9s;
if (0 != zero or
1 != one or
2 != two or
1 != one_again) {
std::cerr<<"problem9 failed, -15\n";
score -= 15;
}
int two_again, now_three;
{
problem10 p10_1;
two_again = problem9::total_problem9s;
problem10 p10_2;
now_three = problem9::total_problem9s;
}
int back_to_one = problem9::total_problem9s;
if (2 != two_again or
3 != now_three or
1 != back_to_one) {
std::cerr<<"problem10 failed, -15\n";
score -= 15;
}
//Print out the final score after all tests
std::cerr<<"Score is "<<score<<" out of "<<100<<'\n';
std::cerr<<"This assignment is worth 15 points, including 5 extra points to help make up for any bad days you've had this semester.\n";
}
|