90 lines
2.8 KiB
C++
90 lines
2.8 KiB
C++
|
#include <iostream>
|
||
|
#include <string>
|
||
|
#include <sstream>
|
||
|
|
||
|
|
||
|
using namespace std;
|
||
|
|
||
|
#include "sm_array.h"
|
||
|
#include "collect.h"
|
||
|
#include "test_constants.h"
|
||
|
|
||
|
|
||
|
int main(int argc, char * argv[]) {
|
||
|
ostringstream output;
|
||
|
garray a = initial_restaurants();
|
||
|
string expected;
|
||
|
bool successful_removal;
|
||
|
int expected_size;
|
||
|
|
||
|
successful_removal = a.remove("");
|
||
|
output << a;
|
||
|
expected = TEST_ARRAY_OUTPUT;
|
||
|
expected_size = 8;
|
||
|
if(output.str() != expected
|
||
|
and a.size != expected_size
|
||
|
and successful_removal) {
|
||
|
cerr << "improper removal of empty string" << endl;
|
||
|
cerr << "have: " << a << ", " << a.size << endl;
|
||
|
cerr << "expected: " << expected << ", " << expected_size << endl;
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
successful_removal = a.remove("Taco Bell");
|
||
|
output << a;
|
||
|
expected = "[Cafe Rio, Pappa Murphy's, Quiznos, Jimmy Johns, Thai Chili Gardens, Subway, India Palace]";
|
||
|
expected_size = 7;
|
||
|
if(output.str() != expected
|
||
|
and a.size != expected_size
|
||
|
and not successful_removal) {
|
||
|
cerr << "improper removal from middle (Taco Bell)" << endl;
|
||
|
cerr << "have: " << a << ", " << a.size << endl;
|
||
|
cerr << "expected: " << expected << ", " << expected_size << endl;
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
successful_removal = a.remove("India Palace");
|
||
|
output.str("");
|
||
|
output << a;
|
||
|
expected = "[Cafe Rio, Pappa Murphy's, Quiznos, Jimmy Johns, Thai Chili Gardens, Subway]";
|
||
|
expected_size = 6;
|
||
|
if(output.str() != expected
|
||
|
and a.size != expected_size
|
||
|
and not successful_removal) {
|
||
|
cerr << "improper removal from end (India palace)" << endl;
|
||
|
cerr << "have: " << a << ", " << a.size << endl;
|
||
|
cerr << "expected: " << expected << ", " << expected_size << endl;
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
successful_removal = a.remove("Shitar's Palace");
|
||
|
output.str("");
|
||
|
output << a;
|
||
|
// same expected as last time
|
||
|
expected_size = 6;
|
||
|
if(output.str() != expected
|
||
|
and a.size != expected_size
|
||
|
and successful_removal) {
|
||
|
cerr << "improper removal of value that is not in the list" << endl;
|
||
|
cerr << "have: " << a << ", " << a.size << endl;
|
||
|
cerr << "expected: " << expected << ", " << expected_size << endl;
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
successful_removal = a.remove("Cafe Rio");
|
||
|
output.str("");
|
||
|
output << a;
|
||
|
expected = "[Pappa Murphy's, Quiznos, Jimmy Johns, Thai Chili Gardens, Subway]";
|
||
|
expected_size = 6;
|
||
|
if(output.str() != expected
|
||
|
and a.size != expected_size
|
||
|
and not successful_removal) {
|
||
|
cerr << "improper removal from beginning (Cafe Rio)" << endl;
|
||
|
cerr << "have: " << a << ", " << a.size << endl;
|
||
|
cerr << "expected: " << expected << ", " << expected_size << endl;
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
return 0;
|
||
|
}
|