Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Filename : test-driver.cpp
- Type (class) : source file (none)
- Author : Kuba Sejdak
- Last modification : 09.11.2010
- Description : Test driver for ListMap class and it's methods. ListMap should be implemented as circular
- doubly-linked list.
- */
- #include <iostream>
- #include <string>
- #include <ctime>
- #include "ListMap.h"
- using namespace std;
- #define SHOWVAR(x) cout << #x << " = '" << (x) << "'"
- #define SEN_KEY 0
- #define SEN_VAL "Sentinel"
- #define OPERATOR_VAL ""
- int CCount::count=0;
- int main()
- {
- cout << "-----TESTOWANIE KLASY LISTMAP I JEJ METOD-----" << endl;
- clock_t start = clock();
- // DANE
- ListMap test;
- pair<int, string> entry0(0, "zero");
- pair<int, string> entry1(1, "jeden");
- pair<int, string> entry2(2, "dwa");
- pair<int, string> entry3(3, "trzy");
- pair<int, string> entry4(4, "cztery");
- pair<int, string> entry5(4, "piec");
- // INSERT (UNSAFE_INSERT)
- cout << endl << "* INSERT (UNSAFE_INSERT) *" << endl;
- pair<ListMap::iterator, bool> wynik;
- wynik = test.insert(entry0);
- if(wynik.second == false)
- cout << "Nie wstawiono! - TEST ERROR!" << endl;
- wynik = test.insert(entry1);
- if(wynik.second == false)
- cout << "Nie wstawiono! - TEST ERROR!" << endl;
- wynik = test.insert(entry2);
- if(wynik.second == false)
- cout << "Nie wstawiono! - TEST ERROR!" << endl;
- wynik = test.insert(entry3);
- if(wynik.second == false)
- cout << "Nie wstawiono! - TEST ERROR!" << endl;
- wynik = test.insert(entry4);
- if(wynik.second == false)
- cout << "Nie wstawiono! - TEST ERROR!" << endl;
- wynik = test.insert(entry5);
- if(wynik.second == false)
- cout << "Nie wstawiono! - TEST OK!" << endl;
- // WYSWIETLANIE ZA POMOCA ITERATOROW
- cout << endl << "* WYSWIETLANIE ZA POMOCA ITERATOROW *" << endl;
- ListMap::iterator it;
- cout << endl << "Wersja z preinkrementacja" << endl;
- for(it = test.begin(); it != test.end(); ++it)
- {
- SHOWVAR(it->first);
- cout << " ";
- SHOWVAR(it->second);
- cout << endl;
- }
- cout << endl << "Wersja z postinkrementacja" << endl;
- for(it = test.begin(); it != test.end(); it++)
- {
- SHOWVAR(it->first);
- cout << " ";
- SHOWVAR(it->second);
- cout << endl;
- }
- // SIZE
- cout << endl << "* SIZE *" << endl;
- SHOWVAR(test.size());
- if(test.size() == 5)
- cout << " - TEST OK!";
- else
- cout << " - TEST ERROR!";
- cout << endl;
- // KONSTRUKTOR KOPIUJACY
- cout << endl << "* KONSTRUKTOR KOPIUJACY + WYSWIETLENIE *" << endl;
- ListMap test2 = test;
- for(it = test2.begin(); it != test2.end(); ++it)
- {
- SHOWVAR(it->first);
- cout << " ";
- SHOWVAR(it->second);
- cout << endl;
- }
- // EMPTY
- cout << endl << "* EMPTY *" << endl;
- test2.clear();
- bool wynik2;
- wynik2 = test.empty();
- cout << "Dla niepustej (test): ";
- if(wynik2)
- cout << "pusta! - TEST ERROR!" << endl;
- else
- cout << "niepusta! - TEST OK!" << endl;
- wynik2 = test2.empty();
- cout << "Dla pustej (test2): ";
- if(wynik2)
- cout << "pusta! - TEST OK!" << endl;
- else
- cout << "niepusta! - TEST ERROR!" << endl;
- // FIND
- cout << endl << "* FIND *" << endl;
- ListMap::iterator i1, i2;
- i1 = test.find(1);
- i2 = test.find(444);
- if(i1 == test.end() )
- cout << "Elemetu o kluczu '1' nie ma w mapie! - TEST ERROR!" << endl;
- if(i2 == test.end() )
- cout << "Elemetu o kluczu '444' nie ma w mapie! - TEST OK!" << endl;
- // COUNT
- cout << endl << "* COUNT *" << endl;
- int numer;
- numer = test.count(4);
- if(numer != 1)
- cout << "Uznano ze wartosci o kluczu '1' nie ma! - TEST ERROR!" << endl;
- numer = test.count(110);
- if(numer == 0)
- cout << "Wartosci o kluczu '110' nie ma. - TEST OK!" << endl;
- else
- cout << "Uznano ze istnieje wartosc o kluczu '110'! - TEST ERROR!" << endl;
- // OPERATOR []
- cout << endl << "* OPERATOR [] *" << endl;
- string wynik3 = test[3];
- if(wynik3 == OPERATOR_VAL)
- cout << "Uznano, ze nie ma wartosci o kluczu '3'! - TEST ERROR!";
- else
- cout << "test[3] = '" << test[3] << "' - TEST OK!" << endl;
- wynik3 = test[666];
- if(wynik3 == OPERATOR_VAL)
- cout << "test[666] = '" << test[666] << "' - TEST OK!" << endl;
- else
- cout << "Zle dodana wartosc dla klucza '666'! - TEST ERROR!" << endl;
- // STRUCT_EQ i INFO_EQ
- cout << endl << "* STRUCT_EQ i INFO_EQ *" << endl;
- ListMap testing; // dla porownania
- testing.insert(entry0);
- testing.insert(entry1);
- testing.insert(entry2);
- testing.insert(entry3);
- testing.insert(entry4);
- ListMap test3 = testing; // strukturalnie i informacyjnie ta sama
- if(testing.info_eq(test3))
- cout << "testing i test3 informacyjnie takie same. - TEST OK!" << endl;
- else
- cout << "testing i test3 informacyjnie nie sa takie same. - TEST ERROR!" << endl;
- if(testing.struct_eq(test3))
- cout << "testing i test3 strukturalnie takie same. - TEST OK!" << endl;
- else
- cout << "testing i test3 strukturalnie nie sa takie same. - TEST ERROR!" << endl;
- ListMap test4; // tylko informacyjnie ta sama
- test4.insert(entry3);
- test4.insert(entry0);
- test4.insert(entry2);
- test4.insert(entry4);
- test4.insert(entry1);
- if(testing.info_eq(test4))
- cout << "testing i test4 informacyjnie takie same. - TEST OK!" << endl;
- else
- cout << "testing i test4 informacyjnie nie sa takie same. - TEST ERROR!" << endl;
- if(testing.struct_eq(test4))
- cout << "testing i test4 strukturalnie takie same. - TEST ERROR!" << endl;
- else
- cout << "testing i test4 strukturalnie nie sa takie same. - TEST OK!" << endl;
- pair<int, string> entry6(6, "szesc");
- pair<int, string> entry7(7, "siedem");
- pair<int, string> entry8(SEN_KEY, SEN_VAL);
- pair<int, string> entry9(9, "dziewiec");
- pair<int, string> entry10(10, "dziesiec");
- ListMap test5; // ani informacyjnie ani strukturalnie nie takie same (rozne pary)
- test5.insert(entry6);
- test5.insert(entry7);
- test5.insert(entry8);
- test5.insert(entry9);
- test5.insert(entry10);
- if(testing.info_eq(test5))
- cout << "testing i test5 informacyjnie takie same. - TEST ERROR!" << endl;
- else
- cout << "testing i test5 informacyjnie nie sa takie same. - TEST OK!" << endl;
- if(testing.struct_eq(test5))
- cout << "testing i test5 strukturalnie takie same. - TEST ERROR!" << endl;
- else
- cout << "testing i test5 strukturalnie nie sa takie same. - TEST OK!" << endl;
- ListMap test6; // ani informacyjnie ani strukturalnie nie takie same (krotsza)
- test6.insert(entry6);
- test6.insert(entry7);
- test6.insert(entry8);
- if(testing.info_eq(test6))
- cout << "testing i test6 informacyjnie takie same. - TEST ERROR!" << endl;
- else
- cout << "testing i test6 informacyjnie nie sa takie same. - TEST OK!" << endl;
- if(testing.struct_eq(test6))
- cout << "testing i test6 strukturalnie takie same. - TEST ERROR!" << endl;
- else
- cout << "testing i test6 strukturalnie nie sa takie same. - TEST OK!" << endl;
- ListMap test7; // ani informacyjnie ani strukturalnie nie takie same (dluzsza)
- test7.insert(entry3);
- test7.insert(entry0);
- test7.insert(entry2);
- test7.insert(entry4);
- test7.insert(entry1);
- test7.insert(entry8);
- if(testing.info_eq(test7))
- cout << "testing i test7 informacyjnie takie same. - TEST ERROR!" << endl;
- else
- cout << "testing i test7 informacyjnie nie sa takie same. - TEST OK!" << endl;
- if(testing.struct_eq(test7))
- cout << "testing i test7 strukturalnie takie same. - TEST ERROR!" << endl;
- else
- cout << "testing i test7 strukturalnie nie sa takie same. - TEST OK!" << endl;
- ListMap test8; // ani informacyjnie ani strukturalnie nie takie same (rozne wartosci dla tych samych kluczy)
- pair<int, string> entry11(0, "szesc");
- pair<int, string> entry12(1, "siedem");
- pair<int, string> entry13(2, "osiem");
- pair<int, string> entry14(3, "dziewiec");
- pair<int, string> entry15(4, "dziesiec");
- test8.insert(entry11);
- test8.insert(entry12);
- test8.insert(entry13);
- test8.insert(entry14);
- test8.insert(entry15);
- if(testing.info_eq(test5))
- cout << "testing i test8 informacyjnie takie same. - TEST ERROR!" << endl;
- else
- cout << "testing i test8 informacyjnie nie sa takie same. - TEST OK!" << endl;
- if(testing.struct_eq(test8))
- cout << "testing i test8 strukturalnie takie same. - TEST ERROR!" << endl;
- else
- cout << "testing i test8 strukturalnie nie sa takie same. - TEST OK!" << endl;
- clock_t end = clock();
- cout << endl << "-----KONIEC TESTU!-----" << endl;
- cout << "CZAS WYKONANIA TESTU WYNOSI: " << static_cast<int>(end - start) << " ms." << endl;
- cin.get();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement