diff options
author | David McMackins II <contact@mcmackins.org> | 2017-05-12 16:24:33 -0500 |
---|---|---|
committer | David McMackins II <contact@mcmackins.org> | 2017-05-12 16:24:33 -0500 |
commit | e2ff9ed5ab8a6f1df6318ceb464dcd7273d6c020 (patch) | |
tree | 82dcb4bfb9af9f846056cc20b45a0a95715da4a4 | |
parent | 7913a340d216cbcff98c196acdc4d31a175ee3a7 (diff) |
Switch to normal makefile and add unit test
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile.am | 14 | ||||
-rwxr-xr-x | autogen.sh | 5 | ||||
-rw-r--r-- | configure.ac | 18 | ||||
-rw-r--r-- | pfxtree-test.c | 48 | ||||
-rw-r--r-- | pfxtree.c | 19 | ||||
-rw-r--r-- | pfxtree.pc | 2 |
7 files changed, 68 insertions, 39 deletions
@@ -60,3 +60,4 @@ pkg/ # Emacs \#*\# .\#* +pfxtree-test diff --git a/Makefile.am b/Makefile.am deleted file mode 100644 index 2c42d6c..0000000 --- a/Makefile.am +++ /dev/null @@ -1,14 +0,0 @@ -ACLOCAL_AMFLAGS = -I m4 --install -dist_doc_DATA = README -pkgconfigdir = $(libdir)/pkgconfig -dist_pkgconfig_DATA = pfxtree.pc - -include_HEADERS = pfxtree.h -lib_LTLIBRARIES = libpfxtree.la - -libpfxtree_la_SOURCES = pfxtree.c -libpfxtree_la_LDFLAGS = -version-info 2:0:2 -libpfxtree_la_CFLAGS = -Wall -Wextra -Wunreachable-code -ftrapv -std=c89 - -AM_CFLAGS = $(DEPS_CFLAGS) -AM_LIBS = $(DEPS_LIBS) diff --git a/autogen.sh b/autogen.sh deleted file mode 100755 index 5b883a6..0000000 --- a/autogen.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh -set -e -srcdir="$(dirname $0)" -cd "$srcdir" -autoreconf --install --force diff --git a/configure.ac b/configure.ac deleted file mode 100644 index e4536a1..0000000 --- a/configure.ac +++ /dev/null @@ -1,18 +0,0 @@ -AC_PREREQ([2.60]) -AC_INIT([libpfxtree],[0.2.0],[support@delwink.com]) - -AC_CONFIG_SRCDIR([pfxtree.c]) -AC_CONFIG_AUX_DIR([build-aux]) -AC_CONFIG_MACRO_DIR([m4]) -AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects]) -m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES]) -AM_SILENT_RULES([yes]) -AM_PROG_AR -LT_INIT -AC_PROG_CC - -AC_CONFIG_HEADERS([config.h]) -AC_CONFIG_FILES([ - Makefile -]) -AC_OUTPUT diff --git a/pfxtree-test.c b/pfxtree-test.c new file mode 100644 index 0000000..d7cb67d --- /dev/null +++ b/pfxtree-test.c @@ -0,0 +1,48 @@ +/* + * pfxtree-test - Delwink prefix tree library unit test + * Copyright (C) 2017 Delwink, LLC + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, version 3 only. + * + * 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <assert.h> +#include <stdbool.h> +#include <stdlib.h> + +#include "pfxtree.h" + +int +main(void) +{ + PrefixTree *p = pt_new(); + assert(p != NULL); + + assert(0 == pt_add(p, "hello", 1)); + assert(0 == pt_add(p, "world", 2)); + assert(0 == pt_add(p, "hell", -1)); + + assert('i' == pt_data_type(pt_search(p, "hell"))); + assert(-1 == pt_data(pt_search(p, "hell"))); + + assert(0 == pt_del(p, "hello")); + assert(NULL == pt_search(p, "hello")); + assert(pt_search(p, "hell") != NULL); + + void *dummy = malloc(0xDFDF); + assert(dummy != NULL); + assert(0 == pt_add_p(p, "hello", dummy)); + assert('p' == pt_data_type(pt_search(p, "hello"))); + + pt_deep_free(p, true); + return 0; +} @@ -182,8 +182,25 @@ pt_del(PrefixTree *self, const char *word) while (p->parent != NULL && num_children(p->parent) == 1) p = p->parent; - if (!p->parent) + if (p->parent) + { + if (p == p->parent->children) + { + p->parent->children = p->next; + } + else + { + PrefixTree *child = p->parent->children; + while (child->next != p) + child = child->next; + + child->next = p->next; + } + } + else + { p = p->children; + } pt_deep_free(p, true); return 0; @@ -3,7 +3,7 @@ exec_prefix = ${prefix} libdir = ${exec_prefix}/lib includedir = ${prefix}/include -Version: 0.2.0 +Version: 0.3.0 Cflags = -I${includedir} Description: Delwink prefix tree library Name: pfxtree |