Exemple #1
0
int main(void)
{
     cout << "main by kk. Last updated 15.04.2013\n";

     int i_tab[] = {5, 4, 12, -4, 0};
     char c_tab[] = {'\"', 'a', 'b', 'c', 'z', '\"'};
     char* c_ptr_tab[] = {"to", "jest", "moj", "pierwszy", "program", "na" , "zajeciach"};
     aghFib fib;

     bool t1 = suma(i_tab, 5) == 17;
     bool t2 = suma(c_tab, 6) == 484;
     bool t3 = suma(c_ptr_tab, 7) == 35;
     bool t4 = suma(fib, 5) == 7;

     for(int i=0;i<6;i++)
       cout << c_tab[i] << " = " << (int)c_tab[i] << endl;

     showTestResult(1, t1);
     showTestResult(2, t2);
     showTestResult(3, t3);
     showTestResult(4, t4);

     cout << "Finally, this is the end...\n";

     return 0;
}
int main(int argc, const char * argv[]) {
   
    //case 0 - 0 element
    int *arr = NULL;
    int arrLen = (int)sizeof(arr) / sizeof(int);
    showTestResult(arr, arrLen);
    
    //case 1 - one element
    int arr1[1] = {1};
    int arrLen1 = (int)sizeof(arr1) / sizeof(int);
    showTestResult(arr1, arrLen1);
    
    //case 2.1 - two elements, incremented
    int arr2[2] = {1, 100};
    int arrLen2 = (int)sizeof(arr2) / sizeof(int);
    showTestResult(arr2, arrLen2);
    
    //case 2.2 - two elements, decremented
    int arr22[2] = {100, 23};
    int arrLen22 = (int)sizeof(arr22) / sizeof(int);
    showTestResult(arr22, arrLen22);
    
    //case 2.3 - two elements, same
    int arr23[2] = {51,51};
    int arrLen23 = (int)sizeof(arr23) / sizeof(int);
    showTestResult(arr23, arrLen23);
    
    //case 3.1 - many elements, incremented
    int arr3[20] = {1,2,3,4,5,6,7,8,9,50, 61,62,63,64,65,66,67,68,69, 101};
    int arrLen3 = (int)sizeof(arr3) / sizeof(int);
    showTestResult(arr3, arrLen3);

    //case 3.2 - three elements, decremented
    int arr32[20] = {99, 97, 95., 93, 91, 89, 87, 85, 83, 81, 79, 77, 75, 73, 71, 69, 67, 65, 63, 61};
    int arrLen32 = (int)sizeof(arr32) / sizeof(int);
    showTestResult(arr32, arrLen32);
    
    //case 3.3 - three elements, randomed
    int arr33[10] = {33 , 33, 33, 33, 33, 33, 33, 33, 33, 33};
    int arrLen33 = (int)sizeof(arr33) / sizeof(int);
    showTestResult(arr33, arrLen33);
    

    return 0;
}
Exemple #3
0
int main(void)
{
      aghVector<aghVector<int> > a;
    aghContainer<int>* c1 = new aghVector<int>;
    aghTree<int>* c2;
    a << *((aghVector<int>*)c1);

    // 1st test - dodawanie do pojemnika stalych, zmiennych, tymczasowych
    c1->append(3);
    c1->insert(0, 1+4);
    c1->insert(c1->size(), c1->size());

    bool t1 = c1->size() == 3;
    int ttab1[] = {5, 3, 2};
    for(int i=0;i<3;i++)
        t1 = t1 && (ttab1[i] == c1->at(i));
    showTestResult(1, t1);

    // 2nd test - konstruktor
    c2 = new aghTree<int>(*c1);
    bool t2 = c2->size() == 3;
    int ttab2[] = {2, 3, 5};
    for(int i=0;i<3;i++)
        t2 = t2 && (ttab2[i] == c2->at(i));
    showTestResult(2, t2);

    // 3rd test - odwolania
    try
    {
        c2->at(-1);
        c2->at(100);
        (*c2)[-10];
        (*c2)[100];
        showTestResult(3, true);
    }
    catch(aghException& e)
    {
        showTestResult(3, true);
    }
    catch(...)
    {
        showTestResult(3, false);
    }

    // 4th test - usuwanie z pojemnika
    c2->clear();
    for(int i=0;i<5;i++)
        *c2 += i;
    *c2 << 4 << 2+3 << -5 << 3;
    c2->remove(2);

    int ttab4[] = {-5, 0, 2, 3, 3, 4, 4, 5};
    bool t4 = c2->size() == 8;
    for(int i=0;t4 && i<8;i++)
        t4 = t4 && (ttab4[i] == c2->at(i));
    showTestResult(4, t4);

    // 5th test
    a.at(0).clear();
    a.at(0) << *c2;
    bool t5 = a.at(0).size() == 8;
    int ttab5[] = {-5, 0, 2, 3, 3, 4, 4, 5};
    for(int i=0;i<8;i++)
        t5 = t5 && (ttab5[i] == a.at(0).at(i));
    showTestResult(5, t5);

     // 6th test - metoda indexOf
    showTestResult(6, c2->indexOf(3) == 3);

    // 7th test - metoda indexOf
    showTestResult(7, c2->indexOf(3, 4) == 4);

    // 8th test - metoda indexOf
    showTestResult(8, c2->indexOf(0, 3) == -1);

    // 9th test - metoda contains
    showTestResult(9, !c2->contains(-6));

    // 10th test - sortowanie
    c1->clear();
    bool t10 = (c1->size() == 0) && (c2->size() == 8);
    int ttab10_1[] = {7, -5, 12, 15, 9, -10, -20, -8, 1, -3, 2};
    int ttab10_2[] = {-20, -10, -8, -5, -3, 1, 2, 7, 9, 12, 15};
    for(int i=0;i<11;i++)
        c1->append(ttab10_1[i]);
    for(int i=0;i<11;i++)
        t10 = t10 && (c1->at(i) == ttab10_1[i]);
    *c2 = *c1;
    c1->clear();
    *c1 << *c2;
    for(int i=0;i<11;i++)
        t10 = t10 && (c1->at(i) == ttab10_2[i]);
    showTestResult(10, t10);

      // 11th test - dzialanie operatora przypisania
    a.at(0) = *c1;
    showTestResult(11, a.at(0) == *c2);

    // 12th test - operator przypisania
    *c2 = *c2;
    try
    {
        showTestResult(12, a.at(0) == *c2);
    }
    catch(...)
    {
        showTestResult(12, false);
    }

    // 13th test - usuwanie z pojemnika
    c2->remove(2);    // -8
    c2->remove(0);    // -20
    c2->remove(1);    // -5
    c2->remove(5);    // 9
    c2->remove(5);    // 12
    c2->remove(4);    // 7
    showTestResult(13, c2->size() == 5);

    // 14th test
    bool t14 = c2->size() == 5;
    int ttab14[] = {-10, -3, 1, 2, 15};
    for(int i=0;i<5;i++)
        t14 = t14 && (c2->at(i) == ttab14[i]);
    showTestResult(14, t14);

    // 15th test - zwalnianie paieci
    try
    {
        delete c1;
        delete c2;
        showTestResult(15, true);
    }
    catch(...)
    {
        showTestResult(15, false);
    }
    return 0;
}
Exemple #4
0
int main(void)
{
    cout << "main by kk. Last updated 20.09.2011\n";

    ///////////////////////////////////////////////////////

    int it1[] = {84, 23, 84, 21, 120, 93, -131, 238}; 
    int it2[] = {249, 24, 82, 3};
    int it3[] = {439, 828, 39, 230, 95, 1, -242, 34};

    aghMatrix<int>* imptr1 = new aghMatrix<int>(2, 4);
    aghMatrix<int>* imptr2 = new aghMatrix<int>(4, 1);
    aghMatrix<int>* imptr3 = new aghMatrix<int>(4, 1);
    aghMatrix<int>* imptr4 = new aghMatrix<int>(2, 4);
    aghMatrix<int> imtest1, imtest2, imtest3;

    imtest1.setItems(4, 1, 249, 24, 82, 3);
    imtest2.setItems(2, 4, 500+23, 851, 123, 251, 215, 94, -373, 272);
    imtest3.setItems(2, 1, 28419, 22084);


    aghMatrix<int>& imref1 = *imptr1;
    aghMatrix<int>& imref2 = *imptr2;
    aghMatrix<int>& imref3 = *imptr3;
    aghMatrix<int>& imref4 = *imptr4;

    imptr1->setItems(it1);
    imptr2->setItems(it2);
    imref3 = imref2;
    imptr4->setItems(it3);

    // 1st test - operator przypisania
    showTestResult(1, imref3 == imtest1);

    // 2nd test - operator przypisania
    try
    {
        imref3 = imref3;
        showTestResult(2, imref3 == imref2);
    }
    catch(...)
    {
        showTestResult(2, false);
    }

    // 3rd test - jawne wywolanie destruktora
    imref2.~aghMatrix();
    try
    {
        showTestResult(3, imref3 != imref2);
    }
    catch(...)
    {
        showTestResult(3, false);
    }

    // 4th test - destruktor
    try
    {
        delete imptr2;
        showTestResult(4, true);
    }
    catch(...)
    {
        showTestResult(4, false);
    }

    // 5th test - kopiowanie wartosci
    showTestResult(5, imref3 == imtest1);

    // 6th test - operator dodawania
    try
    {
        showTestResult(6, (imref1+imref4) == imtest2);
    }
    catch(...)
    {
        showTestResult(6, false);
    }

    // 7th test - operator mnożenia
    aghMatrix<int> immulres;
    try
    {
        aghMatrix<int> immultmp = imref1*imref3;
        immulres = immultmp;
    }
    catch(...)
    {
        showTestResult(7, false);
    }

    showTestResult(7, immulres == imtest3);

    // 8th test - range test
    try
    {
        immulres(10, 11);
        immulres(10, -11);
    }
    catch(aghException& e)
    {
        showTestResult(8, true);
    }
    catch(...)
    {
        showTestResult(8, false);
    }

    // 9th test - dimesion test
    try
    {
        imref1+imref3;
    }
    catch(aghException& e)
    {
        showTestResult(9, true);
    }
    catch(...)
    {
        showTestResult(9, false);
    }

    // 10th test - dimesion test
    try
    {
        imref1*imref4;
    }
    catch(aghException& e)
    {
        showTestResult(10, true);
    }
    catch(...)
    {
        showTestResult(10, false);
    }
    /////////////////////////////////////////////////////

    char ct[] = {'b', 'k', 'l', 'd', 'h', 'z', 'd', 'j', 'z', 'x', 'c', 'n', 'b', 'k', 'z', 'd', 'w'};
    aghMatrix<char> cm1(3, 2);
    aghMatrix<char> cm2(3, 2);
    aghMatrix<char> cm3(2, 4);
    cm1.setItems(ct);
    cm2.setItems(ct+5);
    cm3.setItems(ct+8);

    aghMatrix<char> cmtest1, cmtest2;
    cmtest1.setItems(3, 2, 'a', 'n', 'u', 'c', 'e', 'b');
    cmtest2.setItems(3, 4, 'j', 't', 's', 'r', 's', 'x', 't', 'w', 's', 'v', 'p', 'k');

    // 11th test - operator dodawania
    try
    {
        showTestResult(11, (cm1+cm2) == cmtest1);
    }
    catch(...)
    {
        showTestResult(11, false);
    }

    // 12th test - operator mnożenia
    try
    {
        showTestResult(12, (cm1*cm3) == cmtest2);
    }
    catch(...)
    {
        showTestResult(12, false);
    }
    /////////////////////////////////////////////////////

    char* cpt[] = {"to", "jest", "tablica", "wyrazow", "o", "rozmiarze", "jedenascie", "ktore", "beda", "elementami", "macierzy"};
    aghMatrix<char*> cpm1(2, 3);
    aghMatrix<char*> cpm2(2, 3);
    aghMatrix<char*> cpm3(3, 1);
    aghMatrix<char*> cpm4;
    aghMatrix<char*> cpm5;
    aghMatrix<char*>* cpmptr1 = new aghMatrix<char*>(1, 1);
    aghMatrix<char*> cpmtest1, cpmtest2;

    cpm1.setItems(cpt);
    cpm2.setItems(cpt+5);
    cpm3.setItems(cpt+3);
    cpmptr1->setItem(0, 0, cpt[5]);
    cpmtest1.setItems(2, 3, "torzmiae", "jestdnaci", "tablickore", "wyrazobed", "oelmntai", "rozmiaecy");
    cpmtest2.setItems(2, 1, "oai", "wyrazomie");

    // 13th test - destruktor
    char* itemptr = cpmptr1->operator()(0,0);
    itemptr[0] = 'a';

    delete cpmptr1;
    showTestResult(13, strcmp(itemptr, cpt[5]) != 0);

    // 14th test - operator przypisania p1
    cpm5 = cpm4 = cpm3;
    showTestResult(14, (cpm3 == cpm4) && (cpm3 == cpm5));

    // 15th test - operator przypisania p2
    cpm5.setItem(0, 0, "nothing");
    showTestResult(15, (cpm3 == cpm4) && (cpm3 != cpm5) && (strcmp(cpm3(0,0), "wyrazow") == 0));

    // 16th test - operator przypisania
    cpm5 = cpm3;
    try
    {
        cpm5 = cpm5;

        showTestResult(16, cpm3 == cpm5);

    }
    catch(...)
    {
        showTestResult(16, false);
    }

    // 17th test - jawne wywolanie destruktora
    cpm5 = cpm3;
    cpm5.~aghMatrix();
    try
    {
        showTestResult(17, (cpm3 != cpm5));
    }
    catch(...)
    {
        showTestResult(17, false);
    }

    // 18th test - operator dodawania
    try
    {
        showTestResult(18, (cpm1+cpm2) == cpmtest1);
    }
    catch(...)
    {
        showTestResult(18, false);
    }
    // 19th test - operator mnożenia
    try
    {
        showTestResult(19, (cpm1*cpm3) == cpmtest2);
    }
    catch(...)
    {
        showTestResult(19, false);
    }
    /////////////////////////////////////////////////////

    aghComplex cmplxt1[] = {aghComplex(1,1), aghComplex(1,2), aghComplex(2,1), aghComplex(2,2), aghComplex(3,3), aghComplex(3,1), aghComplex(1,0), aghComplex(0,1)};
    aghComplex cmplxt2[] = {aghComplex(-1,2), aghComplex(0,3), aghComplex(2,6), aghComplex(3,2), aghComplex(3,4)};
    aghMatrix<aghComplex> cmplxm1(3, 2);
    aghMatrix<aghComplex> cmplxm2(2, 1);
    aghMatrix<aghComplex> cmplxm3(2, 1);
    aghMatrix<aghComplex> cmplxm4(2, 1);
    aghMatrix<aghComplex> cmplxmtest1(3, 1);
    aghMatrix<aghComplex> cmplxmtest2(2, 1);

    cmplxm1.setItems(cmplxt1);
    cmplxm2.setItems(cmplxt1+6);
    cmplxm3.setItems(cmplxt1+3);

    cmplxmtest1.setItems(cmplxt2);
    cmplxmtest2.setItems(cmplxt2+3);
    cmplxm4 = cmplxm2 + cmplxm3;

    // 20th test - operator dodawania
    try
    {
        showTestResult(20, cmplxm4 == cmplxmtest2);
    }
    catch(...)
    {
        showTestResult(20, false);
    }
    // 21th test - operator mnozenia
    try
    {
        showTestResult(21, (cmplxm1*cmplxm2) == cmplxmtest1);
    }
    catch(...)
    {
        showTestResult(21, false);
    }
    /////////////////////////////////////////////////////

    cout << "Finally, this is the end...\n";
    return 0;
}
Exemple #5
0
int main(void)
{
    cout << "main by kk. Last updated 15.04.2013\n";
    aghVector<aghVector<int> > a;
    aghContainer<int>* c1 = new aghVector<int>;
    aghContainer<int>* c2;
    a << *((aghVector<int>*)c1);

    // 1st test - dodawanie do pojemnika stalych, zmiennych, tymczasowych
    c1->append(3);
    c1->insert(0, 1+1);
    c1->insert(c1->size(), c1->size());

    bool t1 = c1->size() == 3;
    int ttab1[] = {2, 3, 2};
    for(int i=0;i<3;i++)
        t1 = t1 && (ttab1[i] == c1->at(i));
    showTestResult(1, t1);

    // 2nd test - konstruktor
    c2 = new aghVector<int>(*c1);
    bool t2 = c2->size() == 3;
    int ttab2[] = {2, 3, 2};
    for(int i=0;i<3;i++)
        t2 = t2 && (ttab2[i] == c2->at(i));
    showTestResult(2, t2);

    // 3rd test - odwolania
    try
    {
        c2->at(-1);
        c2->at(100);
        c2->at(c2->size());
        (*c2)[-10];
        (*c2)[100];
        showTestResult(3, true);
    }
    catch(aghException& e)
    {
        showTestResult(3, true);
    }
    catch(...)
    {
        showTestResult(3, false);
    }

    // 4th test - usuwanie z pojemnika
    c1->clear();
    for(int i=0;i<5;i++)
        *c1 += i;
    *c1 << 4 << 2+3;
    c1->remove(2);

    int ttab4[] = {0, 1, 3, 4, 4, 5};
    bool t4 = c1->size() == 6;
    for(int i=0;t4 && i<6;i++)
        t4 = t4 && (ttab4[i] == c1->at(i));
    showTestResult(4, t4);

    // 5th test - sprawdzenie dzialanie konstruktora kopiujacego
    bool t5 = c2->size() == 3;
    int ttab5[] = {2, 3, 2};
    for(int i=0;i<3;i++)
        t5 = t5 && (ttab5[i] == c2->at(i));
    showTestResult(5, t5);

    // 6th test - metoda indexOf
    showTestResult(6, c1->indexOf(3) == 2);

    // 7th test - metoda indexOf
    showTestResult(7, c1->indexOf(4, 3) == 3);

    // 8th test - metoda indexOf
    showTestResult(8, c1->indexOf(4, 4) == 4);

    // 9th test - metoda indexOf
    showTestResult(9, c1->indexOf(3, 3) == -1);

    // 10th test - metoda contains
    showTestResult(10, !c1->contains(-6));


    // 11th test - operacje na pojemniku w pojemniku
    for(int i=3;i>=0;i--)
        a.at(0) += i+1;

    bool t11 = a.at(0).size() == 4;
    int ttab11[] = {4, 3, 2, 1};
    for(int i=0;t11 && i<4;i++)
        t11 = t11 && (a.at(0).at(i) == ttab11[i]);
    showTestResult(11, t11);

    // 12th test - usuwanie z pojemnika
    a.at(0).remove(2);   // 4,3,1
    a.at(0).remove(1);   // 4,1
    a.at(0).remove(1);   // 4
    a.at(0).remove(0);   // empty
    showTestResult(12, a.at(0).isEmpty());

    // 13th test - dzialanie operatora przypisania
    *c2  = a.at(0) = *c1;
    showTestResult(13, *c1 == a.at(0));

    // 14th test - operator przypisania
    try
    {
        *c2 = *c2;
        showTestResult(14, *c1 == *c2);
    }
    catch(...)
    {
        showTestResult(14, false);
    }

    // 15th test - zwalnianie paieci
    try
    {
        delete c1;
        delete c2;
        showTestResult(15, true);
    }
    catch(...)
    {
        showTestResult(15, false);
    }

    cout << "Finally, this is the end...\n";

    return 0;
}
Exemple #6
0
int main(void)
{
    cout << "main by kk. Last updated 20.09.2011\n";

    ///////////////////////////////////////////////////////

    int it1[] = {84, 23, 84, 21, 120, 93, -131, 238};
    int it2[] = {249, 24, 82, 3};
    int it3[] = {439, 828, 39, 230, 95, 1, -242, 34};

    aghMatrix<int>* imptr1 = new aghMatrix<int>(2, 4);
    aghMatrix<int>* imptr2 = new aghMatrix<int>(4, 1);
    aghMatrix<int>* imptr3 = new aghMatrix<int>(4, 1);
    aghMatrix<int>* imptr4 = new aghMatrix<int>(2, 4);
    aghMatrix<int> imtest1, imtest2, imtest3;

    imtest1.setItems(4, 1, 249, 24, 82, 3);
    imtest2.setItems(2, 4, 500+23, 851, 123, 251, 215, 94, -373, 272);
    imtest3.setItems(2, 1, 28419, 22084);

    aghMatrix<int>& imref1 = *imptr1;
    aghMatrix<int>& imref2 = *imptr2;
    aghMatrix<int>& imref3 = *imptr3;
    aghMatrix<int>& imref4 = *imptr4;

    imptr1->setItems(it1);
    imptr2->setItems(it2);
    imref3 = imref2;
    imptr4->setItems(it3);


    // 1st test - operator przypisania
    showTestResult(1, imref3 == imtest1);

    // 2nd test - operator przypisania
    try
    {
        imref3 = imref3;

        showTestResult(2, imref3 == imref2);
    }
    catch(...)
    {
        showTestResult(2, false);
    }

    // 3rd test - jawne wywolanie destruktora
    imref2.~aghMatrix();
    try
    {
        showTestResult(3, imref3 != imref2);
    }
    catch(...)
    {
        showTestResult(3, false);
    }

    // 4th test - destruktor
    //try
    //{
     //   delete imptr2;
     //   showTestResult(4, true);
    //}
    //catch(...)
    //{
    //    showTestResult(4, false);
    //}

    // 5th test - kopiowanie wartosci
    showTestResult(5, imref3 == imtest1);

    // 6th test - operator dodawania
    try
    {
        showTestResult(6, (imref1+imref4) == imtest2);


    }
    catch(...)
    {
        showTestResult(6, false);
    }

    return 0;
}