From c6679060241d5665f4002e312e40e7bc4d939f28 Mon Sep 17 00:00:00 2001 From: Thadeu Lima de Souza Cascardo Date: Sat, 25 Jul 2015 16:10:25 -0300 Subject: [PATCH] Implementa teste para lista --- Makefile.am | 5 ++++ listtest.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 listtest.c diff --git a/Makefile.am b/Makefile.am index a0d646a..2304b38 100644 --- a/Makefile.am +++ b/Makefile.am @@ -9,3 +9,8 @@ declara_SOURCES = declara.c declaracao.c declaracao.h \ util.c util.h \ contribuinte.c contribuinte.h \ rendimento.c rendimento.h + +check_PROGRAMS = listtest +listtest_SOURCES = listtest.c list.c list.h + +TESTS = $(check_PROGRAMS) diff --git a/listtest.c b/listtest.c new file mode 100644 index 0000000..b449fe4 --- /dev/null +++ b/listtest.c @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2012-2015 Thadeu Lima de Souza Cascardo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include +#include +#include +#include + +static char *names[] = { + "backwards", + "end to start", + "finish", + "english", +}; + +int main(int argc, char **argv) +{ + struct list *l; + int i; + int arraylen; + + arraylen = sizeof(names)/sizeof(names[0]); + + l = list_new(); + list_add(&l, "GNU"); + list_free(l, NULL); + printf("Single static list test pass\n"); + fflush(stdout); + + l = list_new(); + for (i = 0; i < arraylen; i++) { + list_add(&l, strdup(names[i])); + } + for (i = 0; i < arraylen; i++) { + if (strcmp(list_get(l, i), names[i])) + return 1; + } + list_free(l, free); + printf("Multiple add ordering list test pass\n"); + fflush(stdout); + + l = list_new(); + for (i = 0; i < arraylen; i++) { + list_insert(&l, 0, strdup(names[i])); + } + for (i = 0; i < arraylen; i++) { + if (strcmp(list_get(l, i), names[arraylen - i - 1])) + return 1; + } + list_free(l, free); + printf("Multiple insertion at start ordering list test pass\n"); + fflush(stdout); + + l = list_new(); + for (i = 0; i < arraylen; i++) { + list_insert(&l, i, strdup(names[i])); + } + for (i = 0; i < arraylen; i++) { + if (strcmp(list_get(l, i), names[i])) + return 1; + } + list_free(l, free); + printf("Multiple insertion at end ordering list test pass\n"); + fflush(stdout); + + return 0; +} -- 2.20.1