Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.48 KB | None | 0 0
  1. /*
  2.         Filename                :       test-driver.cpp
  3.         Type (class)            :       source file (none)
  4.         Author                  :       Kuba Sejdak
  5.         Last modification       :       09.11.2010
  6.         Description             :       Test driver for ListMap class and it's methods. ListMap should be implemented as circular
  7.                                         doubly-linked list.
  8. */
  9.  
  10. #include <iostream>
  11. #include <string>
  12. #include <ctime>
  13. #include "ListMap.h"
  14. using namespace std;
  15.  
  16. #define SHOWVAR(x) cout << #x << " = '" << (x) << "'"
  17. #define SEN_KEY 0
  18. #define SEN_VAL "Sentinel"
  19. #define OPERATOR_VAL ""
  20. int CCount::count=0;
  21.  
  22. int main()
  23. {
  24.     cout << "-----TESTOWANIE KLASY LISTMAP I JEJ METOD-----" << endl;
  25.     clock_t start = clock();
  26.  
  27.     // DANE
  28.     ListMap test;
  29.     pair<int, string> entry0(0, "zero");
  30.     pair<int, string> entry1(1, "jeden");
  31.     pair<int, string> entry2(2, "dwa");
  32.     pair<int, string> entry3(3, "trzy");
  33.     pair<int, string> entry4(4, "cztery");
  34.     pair<int, string> entry5(4, "piec");
  35.  
  36.     // INSERT (UNSAFE_INSERT)
  37.     cout << endl << "* INSERT (UNSAFE_INSERT) *" << endl;
  38.     pair<ListMap::iterator, bool> wynik;
  39.     wynik = test.insert(entry0);
  40.     if(wynik.second == false)
  41.         cout << "Nie wstawiono! - TEST ERROR!" << endl;
  42.     wynik = test.insert(entry1);
  43.     if(wynik.second == false)
  44.         cout << "Nie wstawiono! - TEST ERROR!" << endl;
  45.     wynik = test.insert(entry2);
  46.     if(wynik.second == false)
  47.         cout << "Nie wstawiono! - TEST ERROR!" << endl;
  48.     wynik = test.insert(entry3);
  49.     if(wynik.second == false)
  50.         cout << "Nie wstawiono! - TEST ERROR!" << endl;
  51.     wynik = test.insert(entry4);
  52.     if(wynik.second == false)
  53.         cout << "Nie wstawiono! - TEST ERROR!" << endl;
  54.     wynik = test.insert(entry5);
  55.     if(wynik.second == false)
  56.         cout << "Nie wstawiono! - TEST OK!" << endl;
  57.  
  58.     // WYSWIETLANIE ZA POMOCA ITERATOROW
  59.     cout << endl << "* WYSWIETLANIE ZA POMOCA ITERATOROW *" << endl;
  60.  
  61.     ListMap::iterator it;
  62.     cout << endl << "Wersja z preinkrementacja" << endl;
  63.     for(it = test.begin(); it != test.end(); ++it)
  64.     {
  65.         SHOWVAR(it->first);
  66.         cout << " ";
  67.         SHOWVAR(it->second);
  68.         cout << endl;
  69.     }
  70.     cout << endl << "Wersja z postinkrementacja" << endl;
  71.     for(it = test.begin(); it != test.end(); it++)
  72.     {
  73.         SHOWVAR(it->first);
  74.         cout << " ";
  75.         SHOWVAR(it->second);
  76.         cout << endl;
  77.     }
  78.  
  79.     // SIZE
  80.     cout << endl << "* SIZE *" << endl;
  81.  
  82.     SHOWVAR(test.size());
  83.     if(test.size() == 5)
  84.         cout << " - TEST OK!";
  85.     else
  86.         cout << " - TEST ERROR!";
  87.     cout << endl;
  88.  
  89.     // KONSTRUKTOR KOPIUJACY
  90.     cout << endl << "* KONSTRUKTOR KOPIUJACY + WYSWIETLENIE *" << endl;
  91.  
  92.     ListMap test2 = test;
  93.     for(it = test2.begin(); it != test2.end(); ++it)
  94.     {
  95.         SHOWVAR(it->first);
  96.         cout << " ";
  97.         SHOWVAR(it->second);
  98.         cout << endl;
  99.     }
  100.  
  101.     // EMPTY
  102.     cout << endl << "* EMPTY *" << endl;
  103.  
  104.     test2.clear();
  105.     bool wynik2;
  106.     wynik2 = test.empty();
  107.     cout << "Dla niepustej (test): ";
  108.     if(wynik2)
  109.         cout << "pusta! - TEST ERROR!" << endl;
  110.     else
  111.         cout << "niepusta! - TEST OK!" << endl;
  112.  
  113.     wynik2 = test2.empty();
  114.     cout << "Dla pustej (test2): ";
  115.     if(wynik2)
  116.         cout << "pusta! - TEST OK!" << endl;
  117.     else
  118.         cout << "niepusta! - TEST ERROR!" << endl;
  119.  
  120.     // FIND
  121.     cout << endl << "* FIND *" << endl;
  122.  
  123.     ListMap::iterator i1, i2;
  124.     i1 = test.find(1);
  125.     i2 = test.find(444);
  126.     if(i1 == test.end() )
  127.         cout << "Elemetu o kluczu '1' nie ma w mapie! - TEST ERROR!" << endl;
  128.     if(i2 == test.end() )
  129.         cout << "Elemetu o kluczu '444' nie ma w mapie! - TEST OK!" << endl;
  130.  
  131.     // COUNT
  132.     cout << endl << "* COUNT *" << endl;
  133.  
  134.     int numer;
  135.     numer = test.count(4);
  136.     if(numer != 1)
  137.         cout << "Uznano ze wartosci o kluczu '1' nie ma! - TEST ERROR!" << endl;
  138.  
  139.     numer = test.count(110);
  140.     if(numer == 0)
  141.         cout << "Wartosci o kluczu '110' nie ma. - TEST OK!" << endl;
  142.     else
  143.         cout << "Uznano ze istnieje wartosc o kluczu '110'! - TEST ERROR!" << endl;
  144.  
  145.     // OPERATOR []
  146.     cout << endl << "* OPERATOR [] *" << endl;
  147.  
  148.     string wynik3 = test[3];
  149.     if(wynik3 == OPERATOR_VAL)
  150.         cout << "Uznano, ze nie ma wartosci o kluczu '3'! - TEST ERROR!";
  151.     else
  152.         cout << "test[3] = '" << test[3] << "' - TEST OK!" << endl;
  153.  
  154.     wynik3 = test[666];
  155.     if(wynik3 == OPERATOR_VAL)
  156.         cout << "test[666] = '" << test[666] << "' - TEST OK!" << endl;
  157.     else
  158.         cout << "Zle dodana wartosc dla klucza '666'! - TEST ERROR!" << endl;
  159.  
  160.     // STRUCT_EQ i INFO_EQ
  161.     cout << endl << "* STRUCT_EQ i INFO_EQ *" << endl;
  162.  
  163.     ListMap testing;        // dla porownania
  164.     testing.insert(entry0);
  165.     testing.insert(entry1);
  166.     testing.insert(entry2);
  167.     testing.insert(entry3);
  168.     testing.insert(entry4);
  169.  
  170.     ListMap test3 = testing;    // strukturalnie i informacyjnie ta sama
  171.     if(testing.info_eq(test3))
  172.         cout << "testing i test3 informacyjnie takie same. - TEST OK!" << endl;
  173.     else
  174.         cout << "testing i test3 informacyjnie nie sa takie same. - TEST ERROR!" << endl;
  175.  
  176.     if(testing.struct_eq(test3))
  177.         cout << "testing i test3 strukturalnie takie same. - TEST OK!" << endl;
  178.     else
  179.         cout << "testing i test3 strukturalnie nie sa takie same. - TEST ERROR!" << endl;
  180.  
  181.     ListMap test4;          // tylko informacyjnie ta sama
  182.     test4.insert(entry3);
  183.     test4.insert(entry0);
  184.     test4.insert(entry2);
  185.     test4.insert(entry4);
  186.     test4.insert(entry1);
  187.  
  188.     if(testing.info_eq(test4))
  189.         cout << "testing i test4 informacyjnie takie same. - TEST OK!" << endl;
  190.     else
  191.         cout << "testing i test4 informacyjnie nie sa takie same. - TEST ERROR!" << endl;
  192.  
  193.     if(testing.struct_eq(test4))
  194.         cout << "testing i test4 strukturalnie takie same. - TEST ERROR!" << endl;
  195.     else
  196.         cout << "testing i test4 strukturalnie nie sa takie same. - TEST OK!" << endl;
  197.  
  198.     pair<int, string> entry6(6, "szesc");
  199.     pair<int, string> entry7(7, "siedem");
  200.     pair<int, string> entry8(SEN_KEY, SEN_VAL);
  201.     pair<int, string> entry9(9, "dziewiec");
  202.     pair<int, string> entry10(10, "dziesiec");
  203.  
  204.     ListMap test5;      // ani informacyjnie ani strukturalnie nie takie same (rozne pary)
  205.     test5.insert(entry6);
  206.     test5.insert(entry7);
  207.     test5.insert(entry8);
  208.     test5.insert(entry9);
  209.     test5.insert(entry10);
  210.  
  211.     if(testing.info_eq(test5))
  212.         cout << "testing i test5 informacyjnie takie same. - TEST ERROR!" << endl;
  213.     else
  214.         cout << "testing i test5 informacyjnie nie sa takie same. - TEST OK!" << endl;
  215.  
  216.     if(testing.struct_eq(test5))
  217.         cout << "testing i test5 strukturalnie takie same. - TEST ERROR!" << endl;
  218.     else
  219.         cout << "testing i test5 strukturalnie nie sa takie same. - TEST OK!" << endl;
  220.  
  221.     ListMap test6;      // ani informacyjnie ani strukturalnie nie takie same (krotsza)
  222.     test6.insert(entry6);
  223.     test6.insert(entry7);
  224.     test6.insert(entry8);
  225.  
  226.     if(testing.info_eq(test6))
  227.         cout << "testing i test6 informacyjnie takie same. - TEST ERROR!" << endl;
  228.     else
  229.         cout << "testing i test6 informacyjnie nie sa takie same. - TEST OK!" << endl;
  230.  
  231.     if(testing.struct_eq(test6))
  232.         cout << "testing i test6 strukturalnie takie same. - TEST ERROR!" << endl;
  233.     else
  234.         cout << "testing i test6 strukturalnie nie sa takie same. - TEST OK!" << endl;
  235.  
  236.     ListMap test7;      // ani informacyjnie ani strukturalnie nie takie same (dluzsza)
  237.     test7.insert(entry3);
  238.     test7.insert(entry0);
  239.     test7.insert(entry2);
  240.     test7.insert(entry4);
  241.     test7.insert(entry1);
  242.     test7.insert(entry8);
  243.    
  244.     if(testing.info_eq(test7))
  245.         cout << "testing i test7 informacyjnie takie same. - TEST ERROR!" << endl;
  246.     else
  247.         cout << "testing i test7 informacyjnie nie sa takie same. - TEST OK!" << endl;
  248.  
  249.     if(testing.struct_eq(test7))
  250.         cout << "testing i test7 strukturalnie takie same. - TEST ERROR!" << endl;
  251.     else
  252.         cout << "testing i test7 strukturalnie nie sa takie same. - TEST OK!" << endl;
  253.  
  254.     ListMap test8;      // ani informacyjnie ani strukturalnie nie takie same (rozne wartosci dla tych samych kluczy)
  255.     pair<int, string> entry11(0, "szesc");
  256.     pair<int, string> entry12(1, "siedem");
  257.     pair<int, string> entry13(2, "osiem");
  258.     pair<int, string> entry14(3, "dziewiec");
  259.     pair<int, string> entry15(4, "dziesiec");
  260.     test8.insert(entry11);
  261.     test8.insert(entry12);
  262.     test8.insert(entry13);
  263.     test8.insert(entry14);
  264.     test8.insert(entry15);
  265.  
  266.     if(testing.info_eq(test5))
  267.         cout << "testing i test8 informacyjnie takie same. - TEST ERROR!" << endl;
  268.     else
  269.         cout << "testing i test8 informacyjnie nie sa takie same. - TEST OK!" << endl;
  270.  
  271.     if(testing.struct_eq(test8))
  272.         cout << "testing i test8 strukturalnie takie same. - TEST ERROR!" << endl;
  273.     else
  274.         cout << "testing i test8 strukturalnie nie sa takie same. - TEST OK!" << endl;
  275.  
  276.     clock_t end = clock();
  277.     cout << endl << "-----KONIEC TESTU!-----" << endl;
  278.     cout << "CZAS WYKONANIA TESTU WYNOSI: " << static_cast<int>(end - start) << " ms." << endl;
  279.  
  280.     cin.get();
  281.     return 0;
  282. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement