#include "vector_tests.h"
#include "../../domain/trench.h"
#include "../../vector/vector.h"
#include "../../exceptions/exceptions.h"
#include <assert.h>
#include <string.h>
#include <stdio.h>

void test_vector(void){
    Vector<Trench*> *v = new Vector<Trench*>();
    Trench *t1 = new Trench(1,"Blue",10,10,"Photo1");
    int check=0;
    v->add(t1);
    assert(v->size() == 1);
    assert(v->get(t1)==0);
    Trench *t2 = new Trench(2,"Red",20,20,"Photo2");
    assert(v->get(t2)==-1);
    v->add(t2);
    assert(v->size() == 2);
    assert(v->get(t2)==1);
    v->remove(t1);
    t1 = new Trench(1,"Blue",10,10,"Photo1");
    assert(v->size() == 1);
    assert(v->get(t1)==-1);
    assert(v->get(t2)==0);
    v->remove(0);
    t2 = new Trench(2,"Red",20,20,"Photo2");
    assert(v->size() == 0);
    assert(v->get(t2)==-1);
    v->add(t1);
    (*v)[0]=t2;
    assert(v->get(t2)==0);
    assert((*v)[0]==t2);
    assert(v->capacity()==10);
    assert(*(v->begin())==t2);
    assert(*(v->end()-1)==t2);
    Trench* t3 = new Trench(3,"Yellow",30,30,"Photo3");
    try{
        v->remove(t3);
    }
    catch(VectorException& e){
        check=1;
        assert(strcmp(e.what(),"Element not found")==0);
    }
    assert(check);
    check=0;
    try{
        v->remove(-4);
    }
    catch(VectorException& e){
        check=1;
        assert(strcmp(e.what(),"Index out of bounds")==0);
    }
    assert(check);
    check=0;
    try{
        (*v)[44];
    }
    catch(VectorException& e){
        check=1;
        assert(strcmp(e.what(),"Index out of bounds")==0);
    }
    assert(check);
    v->add(t1);
    v->add(t3);
    Trench* t4 = new Trench(13,"Yellow",31,30,"Photo3");
    Trench* t5 = new Trench(4,"Yellow",32,30,"Photo3");
    Trench* t6 = new Trench(5,"Yellow",33,30,"Photo3");
    Trench* t7 = new Trench(6,"Yellow",34,30,"Photo3");
    Trench* t8 = new Trench(7,"Yellow",35,30,"Photo3");
    Trench* t9 = new Trench(8,"Yellow",36,30,"Photo3");
    Trench* t10 = new Trench(9,"Yellow",37,30,"Photo3");
    Trench* t11 = new Trench(10,"Yellow",38,30,"Photo3");
    v->add(t4);
    v->add(t5);
    v->add(t6);
    v->add(t7);
    v->add(t8);
    v->add(t9);
    v->add(t10);
    v->add(t11);
    Vector<Trench*> *v2 = new Vector<Trench*>(23);
    assert(v2->capacity()==23);
    Trench* t12 = new Trench(10,"Yellow",38,30,"Photo3");
    Trench* t13 = new Trench(10,"Yellow",38,30,"Photo3");
    v2->add(t12);
    Vector<Trench*> v3 = *v2;
    assert(v3.capacity()==23);
    v3[0]=t13;
    delete v2;
    delete v;

}