aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorGravatar Gediminas Jakutis <gediminas@varciai.lt> 2015-01-31 20:35:30 +0200
committerGravatar Gediminas Jakutis <gediminas@varciai.lt> 2015-03-03 23:36:16 +0200
commit8b26e3ef33e3871762ebd62acbff85b2c3abd9fc (patch)
tree67d917b8694572b735662d2786fb77eac23ccaa9 /test
downloadlibrin-8b26e3ef33e3871762ebd62acbff85b2c3abd9fc.tar.gz
librin-8b26e3ef33e3871762ebd62acbff85b2c3abd9fc.tar.bz2
librin-8b26e3ef33e3871762ebd62acbff85b2c3abd9fc.zip
Initial commit - Release 0.0.1librin-0.0.1
Diffstat (limited to 'test')
-rw-r--r--test/Makefile.am72
-rw-r--r--test/diagnostic.c28
-rw-r--r--test/diagnostic_test.h26
-rw-r--r--test/diagnostic_test_private.h26
-rw-r--r--test/float.c172
-rw-r--r--test/float_test.h28
-rw-r--r--test/float_test_private.h37
-rw-r--r--test/main.c38
-rw-r--r--test/test.c38
-rw-r--r--test/test.h35
10 files changed, 500 insertions, 0 deletions
diff --git a/test/Makefile.am b/test/Makefile.am
new file mode 100644
index 0000000..65e6c2c
--- /dev/null
+++ b/test/Makefile.am
@@ -0,0 +1,72 @@
+# Copyright (C) 2015 Gediminas Jakutis
+#
+# This Makefile.am is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; version 2.1
+# of the License.
+#
+# 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+
+AM_CFLAGS = \
+ -I$(top_srcdir)/include/ \
+ -Wall \
+ -Wextra
+
+check_PROGRAMS = test
+check_LTLIBRARIES = \
+ libtest.la \
+ libfloat_test.la \
+ libdiagnostic_test.la
+
+# test program
+test_LDADD = \
+ libtest.la \
+ libfloat_test.la \
+ libdiagnostic_test.la
+
+test_SOURCES = \
+ main.c \
+ test.h \
+ float_test.h \
+ diagnostic_test.h
+
+# test lib
+libtest_la_SOURCES = \
+ test.c \
+ test.h
+
+# float module test
+libfloat_test_la_SOURCES = \
+ float.c \
+ float_test.h \
+ float_test_private.h \
+ test.h
+
+libfloat_test_la_LIBADD = \
+ libtest.la \
+ $(top_srcdir)/src/librin.la
+
+# diagnostic module test
+libdiagnostic_test_la_SOURCES = \
+ diagnostic.c \
+ diagnostic_test.h \
+ diagnostic_test_private.h \
+ test.h
+
+libdiagnostic_test_la_LIBADD = \
+ libtest.la \
+ $(top_srcdir)/src/librin.la
+
+noinst_HEADERS = \
+ test.h \
+ float_test.h \
+ float_test_private.h \
+ diagnostic_test.h \
+ diagnostic_test_private.h
diff --git a/test/diagnostic.c b/test/diagnostic.c
new file mode 100644
index 0000000..f8a2bd4
--- /dev/null
+++ b/test/diagnostic.c
@@ -0,0 +1,28 @@
+/*
+ * The Rin Library – library "conformance" tests
+ *
+ * Copyright (C) 2015 Gediminas Jakutis
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; version 2.1
+ * of the License.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "test.h"
+#include "diagnostic_test_private.h"
+
+struct test_results diagnostic_test(void)
+{
+ /* basically a NOOP */
+ return ok(0, "");
+}
diff --git a/test/diagnostic_test.h b/test/diagnostic_test.h
new file mode 100644
index 0000000..e8f2967
--- /dev/null
+++ b/test/diagnostic_test.h
@@ -0,0 +1,26 @@
+/*
+ * The Rin Library – library "conformance" tests
+ *
+ * Copyright (C) 2015 Gediminas Jakutis
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; version 2.1
+ * of the License.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef LIBRIN_DIAGNOSTIC_TEST_INCLUDED
+#define LIBRIN_DIAGNOSTIC_TEST_INCLUDED
+
+struct test_results diagnostic_test(void);
+
+#endif /* LIBRIN_DIAGNOSTIC_TEST_INCLUDED */
diff --git a/test/diagnostic_test_private.h b/test/diagnostic_test_private.h
new file mode 100644
index 0000000..ad2aa43
--- /dev/null
+++ b/test/diagnostic_test_private.h
@@ -0,0 +1,26 @@
+/*
+ * The Rin Library – library "conformance" tests
+ *
+ * Copyright (C) 2015 Gediminas Jakutis
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; version 2.1
+ * of the License.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef LIBRIN_DIAGNOSTIC_TEST_PRIVATE_INCLUDED
+#define LIBRIN_DIAGNOSTIC_TEST_PRIVATE_INCLUDED
+
+/* NOOP */
+
+#endif /* LIBRIN_DIAGNOSTIC_TEST_PRIVATE_INCLUDED */
diff --git a/test/float.c b/test/float.c
new file mode 100644
index 0000000..9940ff4
--- /dev/null
+++ b/test/float.c
@@ -0,0 +1,172 @@
+/*
+ * The Rin Library – library "conformance" tests
+ *
+ * Copyright (C) 2015 Gediminas Jakutis
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; version 2.1
+ * of the License.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "test.h"
+#include "float_test_private.h"
+
+struct test_results float_test(void)
+{
+ struct test_results ret;
+
+ ret = rin_signbitf_test();
+ ret = rin_signbitd_test();
+ ret = rin_float_to_hexstring_test();
+ ret = rin_double_to_hexstring_test();
+ ret = rin_compare_float_test();
+ ret = rin_compare_double_test();
+
+ return ret;
+}
+
+static struct test_results rin_signbitf_test(void)
+{
+ struct test_results ret;
+ size_t i;
+ static const float in[] = { 1.0f, -1.0f, 987656.4321f, -987656.4321f };
+ static const uint32_t expected[] = { 0, 0x80000000u, 0, 0x80000000u };
+
+ for (i = 0; i < 4; ++i) {
+ ret = ok(rin_signbitf(in[i]) != expected[i],
+ "%s: expected: %"PRIu32", got: %"PRIu32" (%1.8e)",
+ __func__,
+ expected[i],
+ rin_signbitf(in[i]),
+ in[i]);
+ }
+
+ return ret;
+}
+
+static struct test_results rin_signbitd_test(void)
+{
+ struct test_results ret;
+ size_t i;
+ static const double in[] = { 1.0, -1.0, 987656.4321, -987656.4321 };
+ static const uint64_t expected[] = { 0, 0x8000000000000000ull, 0, 0x8000000000000000ull };
+
+ for (i = 0; i < 4; ++i) {
+ ret = ok(rin_signbitd(in[i]) != expected[i],
+ "%s: expected: %"PRIu64", got: %"PRIu64" (%1.16e)",
+ __func__,
+ expected[i],
+ rin_signbitf(in[i]),
+ in[i]);
+ }
+
+ return ret;
+}
+
+static struct test_results rin_float_to_hexstring_test(void)
+{
+ struct test_results ret;
+ size_t i;
+ static const float in[] = { 1.0f, -1.0f, 98765.4321f, -98765.4321f };
+ static const char *expected_default[] = { "0x3f800000", "0xbf800000", "0x47c0e6b7", "0xc7c0e6b7" };
+ static const char *expected_noprefix[] = { "3f800000", "bf800000", "47c0e6b7", "c7c0e6b7" };
+ char buffer[16] = { '\0' };
+
+ for (i = 0; i < 4; ++i) {
+ ret = ok(strcmp(rin_float_to_hexstring(in[i], buffer, RIN_HEXSTRING_DEFAULT), expected_default[i]),
+ "%s: expected: %s, got: %s (%1.8e)",
+ __func__,
+ expected_default[i],
+ rin_float_to_hexstring(in[i], buffer, RIN_HEXSTRING_DEFAULT),
+ in[i]);
+
+ ret = ok(strcmp(rin_float_to_hexstring(in[i], buffer, RIN_HEXSTRING_NOPREFIX), expected_noprefix[i]),
+ "%s: expected: %s, got: %s (%1.8e)",
+ __func__,
+ expected_noprefix[i],
+ rin_float_to_hexstring(in[i], buffer, RIN_HEXSTRING_NOPREFIX),
+ in[i]);
+ }
+
+ return ret;
+}
+
+
+static struct test_results rin_double_to_hexstring_test(void)
+{
+ struct test_results ret;
+ size_t i;
+ static const double in[] = { 1.0, -1.0, 98765.4321, -98765.4321 };
+ static const char *expected_default[] = { "0x3ff0000000000000", "0xbff0000000000000", "0x40f81cd6e9e1b08a", "0xc0f81cd6e9e1b08a" };
+ static const char *expected_noprefix[] = { "3ff0000000000000", "bff0000000000000", "40f81cd6e9e1b08a", "c0f81cd6e9e1b08a" };
+ char buffer[32] = { '\0' };
+
+ for (i = 0; i < 4; ++i) {
+ ret = ok(strcmp(rin_double_to_hexstring(in[i], buffer, RIN_HEXSTRING_DEFAULT), expected_default[i]),
+ "%s: expected: %s, got: %s (%1.16e)",
+ __func__,
+ expected_default[i],
+ rin_double_to_hexstring(in[i], buffer, RIN_HEXSTRING_DEFAULT),
+ in[i]);
+
+ ret = ok(strcmp(rin_double_to_hexstring(in[i], buffer, RIN_HEXSTRING_NOPREFIX), expected_noprefix[i]),
+ "%s: expected: %s, got: %s (%1.16e)",
+ __func__,
+ expected_noprefix[i],
+ rin_double_to_hexstring(in[i], buffer, RIN_HEXSTRING_NOPREFIX),
+ in[i]);
+ }
+
+ return ret;
+}
+
+static struct test_results rin_compare_float_test(void)
+{
+ struct test_results ret;
+ size_t i;
+ static const float a[] = { 0.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 98765.4321f, 98765.4321f, 98765.4321f };
+ static const float b[] = { -0.0f, 1.0f, 1.0f, 1.0000001f, -9.8f, 1.000001f, 98765.436f, 98777.7777f, -98765.4321f };
+ static const unsigned int expected[] = { 0, 0, 1, 0, 1, 1, 0, 1, 1};
+
+ for (i = 0; i < 4; ++i) {
+ ret = ok(rin_compare_float(a[i], b[i], 2) != expected[i],
+ "%s: expected: %s, got: %s (%1.8e, %1.8e)",
+ __func__,
+ expected[i] ? "non-equal" : "equal",
+ rin_compare_float(a[i], b[i], 2) ? "non-equal" : "equal",
+ a[i], b[i]);
+ }
+
+ return ret;
+}
+
+
+static struct test_results rin_compare_double_test(void)
+{
+ struct test_results ret;
+ size_t i;
+ static const double a[] = { 0.0, 1.0, -1.0, 1.0, -1.0f, 1.0, 98765.4321, 98765.4321, 98765.4321 };
+ static const double b[] = { -0.0, 1.0, 1.0, 1.0000000000000003, -9.8f, 1.000001, 98765.43210000002, 98777.7777, -98765.4321 };
+ static const unsigned int expected[] = { 0, 0, 1, 0, 1, 1, 0, 1, 1};
+
+ for (i = 0; i < 4; ++i) {
+ ret = ok(rin_compare_double(a[i], b[i], 2) != expected[i],
+ "%s: expected: %s, got: %s (%1.16e, %1.16e)",
+ __func__,
+ expected[i] ? "non-equal" : "equal",
+ rin_compare_double(a[i], b[i], 2) ? "non-equal" : "equal",
+ a[i], b[i]);
+ }
+
+ return ret;
+}
diff --git a/test/float_test.h b/test/float_test.h
new file mode 100644
index 0000000..1787bd7
--- /dev/null
+++ b/test/float_test.h
@@ -0,0 +1,28 @@
+/*
+ * The Rin Library – library "conformance" tests
+ *
+ * Copyright (C) 2015 Gediminas Jakutis
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; version 2.1
+ * of the License.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef LIBRIN_FLOAT_TEST_INCLUDED
+#define LIBRIN_FLOAT_TEST_INCLUDED
+
+#include "test.h"
+
+struct test_results float_test(void);
+
+#endif /* LIBRIN_FLOAT_TEST_INCLUDED */
diff --git a/test/float_test_private.h b/test/float_test_private.h
new file mode 100644
index 0000000..a64aaeb
--- /dev/null
+++ b/test/float_test_private.h
@@ -0,0 +1,37 @@
+/*
+ * The Rin Library – library "conformance" tests
+ *
+ * Copyright (C) 2015 Gediminas Jakutis
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; version 2.1
+ * of the License.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef LIBRIN_FLOAT_TEST_INCLUDED
+#define LIBRIN_FLOAT_TEST_INCLUDED
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdint.h>
+#include <inttypes.h>
+#include "rin/float.h"
+
+static struct test_results rin_signbitf_test(void);
+static struct test_results rin_signbitd_test(void);
+static struct test_results rin_float_to_hexstring_test(void);
+static struct test_results rin_double_to_hexstring_test(void);
+static struct test_results rin_compare_float_test(void);
+static struct test_results rin_compare_double_test(void);
+
+#endif /* LIBRIN_FLOAT_TEST_INCLUDED */
diff --git a/test/main.c b/test/main.c
new file mode 100644
index 0000000..c8fae63
--- /dev/null
+++ b/test/main.c
@@ -0,0 +1,38 @@
+/*
+ * The Rin Library – library "conformance" tests
+ *
+ * Copyright (C) 2015 Gediminas Jakutis
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; version 2.1
+ * of the License.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "test.h"
+#include "float_test.h"
+#include "diagnostic_test.h"
+
+/* TODO: allow individual tests to be selected */
+
+
+int main(int argc, char **argv)
+{
+ struct test_results res;
+
+ res = float_test();
+ res = diagnostic_test();
+
+ printf("%u tests executed, %u test succeeded, %u tests failed.\n", res.executed, res.executed - res.failed, res.failed);
+
+ return EXIT_SUCCESS;
+}
diff --git a/test/test.c b/test/test.c
new file mode 100644
index 0000000..e790538
--- /dev/null
+++ b/test/test.c
@@ -0,0 +1,38 @@
+/*
+ * The Rin Library – library "conformance" tests
+ *
+ * Copyright (C) 2015 Gediminas Jakutis
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; version 2.1
+ * of the License.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "test.h"
+
+struct test_results ok(const unsigned int test, const char *format, ...)
+{
+ static struct test_results ret;
+ va_list args;
+
+ ++ret.executed;
+
+ if (test) {
+ ++ret.failed;
+ va_start(args, format);
+ vprintf(format, args);
+ putchar('\n');
+ }
+
+ return ret;
+}
diff --git a/test/test.h b/test/test.h
new file mode 100644
index 0000000..0597207
--- /dev/null
+++ b/test/test.h
@@ -0,0 +1,35 @@
+/*
+ * The Rin Library – library "conformance" tests
+ *
+ * Copyright (C) 2015 Gediminas Jakutis
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; version 2.1
+ * of the License.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef LIBRIN_TEST_INCLUDED
+#define LIBRIN_TEST_INCLUDED
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdarg.h>
+
+struct test_results {
+ unsigned int executed;
+ unsigned int failed;
+};
+
+struct test_results ok(const unsigned int test, const char *format, ...);
+
+#endif /* LIBRIN_TEST_INCLUDED */