school/cs142/smcquay/lab06/test-add.cc
2016-04-06 20:45:34 -07:00

44 lines
937 B
C++

#include <iostream>
#include <string>
using namespace std;
#include "sm_array.h"
#include "collect.h"
#include "test_constants.h"
int main(int argc, char * argv[]) {
garray a;
bool raised_error = false;
bool correct_error_string = false;
try {
a.add("");
}
catch (string e) {
raised_error = true;
if(e == "cannot add empty string") {
correct_error_string = true;
}
}
if(not raised_error) {
cerr << "should have raised an error trying to add an empty string" << endl;
return 1;
}
if(not correct_error_string) {
cerr << "incorrect error string" << endl;
return 1;
}
garray g = initial_restaurants();
if(g.add("Cafe Rio") or g.add("Jimmy Johns") or not g.add("Jimbo White")) {
cerr << "shouldn't be able to add something that's already in there" << endl;
return 1;
}
return 0;
}