#include "repo_tests.h"
#include "../repository/repository.h"
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <stdlib.h>


void repo_tests(){
    printf("Running repository tests\n");
    Repository* repository = _Repository_Constructor();
    assert(_Repository_getLenght(repository) == 0);
    char *name = (char *)malloc(20);
    char *supplier = (char *)malloc(20);
    strcpy(name, "name");
    strcpy(supplier, "supplier");
    Material* material = _Material_Constructor(name,supplier,10,1,2,2005);
    _Repository_add(repository, material);
    assert(_Repository_getLenght(repository) == 1);
    assert(strcmp(_Material_GetName(_Repository_getItem(repository,0)), "name") == 0);
    assert(strcmp(_Material_GetSupplier(_Repository_getItem(repository,0)), "supplier") == 0);
    assert(_Material_GetQuantity(_Repository_getItem(repository,0)) == 10);
    assert(_Material_GetDate(_Repository_getItem(repository,0)).tm_mday == 1);
    assert(_Material_GetDate(_Repository_getItem(repository,0)).tm_mon == 1);
    assert(_Material_GetDate(_Repository_getItem(repository,0)).tm_year == 2005);
    _Repository_Destructor(repository);
    _Material_Destructor(material);
}