Implementa teste para lista
authorThadeu Lima de Souza Cascardo <cascardo@cascardo.eti.br>
Sat, 25 Jul 2015 19:10:25 +0000 (16:10 -0300)
committerThadeu Lima de Souza Cascardo <cascardo@cascardo.eti.br>
Sat, 25 Jul 2015 20:09:53 +0000 (17:09 -0300)
Makefile.am
listtest.c [new file with mode: 0644]

index a0d646a..2304b38 100644 (file)
@@ -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 (file)
index 0000000..b449fe4
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ *  Copyright (C) 2012-2015  Thadeu Lima de Souza Cascardo <cascardo@minaslivre.org>
+ *
+ *  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 <list.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+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;
+}