Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "entry.h"
- #include <vector>
- #include <iostream>
- #include <sstream>
- using namespace std;
- int main()
- {
- int error_counter = 0;
- //konstruktor, operator* i operator(int)
- vector<string> vals_1 { "Yossarian", "Mitsubishi", "Major" };
- cout << "Testing constructor:" << endl;
- for (int i = 0; i < (int)vals_1.size(); i++)
- {
- entry test(vals_1[i]);
- string test_1_1 = *test;
- int test_1_2 = int(test);
- if (test_1_1 == vals_1[i] && test_1_2 == 0)
- cout << test << " passed\n";
- else
- {
- cout << "Problem with " << test<< ": " << test_1_1 << " seems to be wrong\n";
- error_counter++;
- }
- }
- //operator ++
- vector<string> vals_2 { "Serpukhov", "Catch", "LV", "Fleetex", "HAL", "Indeks:"};
- vector<int> ticks_1 {15, 22, 426, 831, 9000, 304523};
- cout << "\nTesting operator++:" << endl;
- for (int i = 0; i < (int)vals_2.size(); i++)
- {
- entry test(vals_2[i]);
- for (int j = 0; j < ticks_1[i]; j++)
- {
- test++;
- }
- string test_2_1 = *test;
- int test_2_2 = int(test);
- if (test_2_1 == vals_2[i] && test_2_2 == ticks_1[i])
- cout << test << " passed\n";
- else
- {
- cout << "Problem with " << test << ": " << test_2_2 << "seems to be wrong t\n";
- error_counter++;
- }
- }
- //operator<
- vector<string> vals_3 {"Major Major Major Major", "Chief White Halfoat", "Milo Minderbinder", "Scheisskopf" };
- cout << "\nTesting operator<:" << endl;
- for (int i = 0; i < (int)vals_3.size() - 1; i++)
- {
- entry test(vals_3[i]);
- entry test_1(vals_3[i + 1]);
- if ((test < test_1) == (vals_3[i] < vals_3[i + 1]))
- cout << test << " < " << test_1 << " passed\n";
- else
- {
- cout << "Problem with " << test << " and " << test_1 << "\n";
- error_counter++;
- }
- }
- //operator<<
- vector<entry> vals_4 {{"Major"}, {"MiG"}, {"M"}, {"Million"}};
- vector<int> ticks_2 {0, 29, 134, 1000000};
- vector<string>result {"[Major 0]", "[MiG 29]", "[M 134]", "[Million 1000000]"};
- cout << "\nTesting operator<<:" << endl;
- ostringstream ss;
- for (int i = 0; i < (int)vals_4.size(); i++)
- {
- entry test(vals_4[i]);
- for (int j = 0; j < ticks_2[i]; j++)
- {
- test++;
- }
- ss << test;
- if(ss.str() == result[i])
- cout << test << " passed\n";
- else
- {
- cout << "Problem with " << test << "\n";
- error_counter++;
- }
- ss.str("");
- }
- //operator>>
- vector<string> entry_objects {"[Sukhoi 15]", "[Uranium 235]", "[Pip-Boy 3000]", "Error 1]", "[Error 2"};
- vector<string> vals_5 {"Sukhoi", "Uranium", "Pip-Boy"};
- vector<int> ticks_3 {15, 235, 3000, 1, 2};
- cout << "\nTesting operator>>:" << endl;
- for (int i = 0; i < (int)entry_objects.size(); i++)
- {
- try
- {
- entry et("");
- istringstream is;
- is.str(entry_objects[i]);
- is >> et;
- if(*et == vals_5[i] && (int)et == ticks_3[i])
- cout << entry_objects[i] << " passed\n";
- else
- {
- cout << "Problem with " << entry_objects[i] << "\n";
- error_counter++;
- }
- }
- catch(invalid_argument& err)
- {
- err.what();
- cout << "Exception caught" << endl;
- }
- }
- cout << "\nErrors: " << error_counter;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement