diff --git a/test/.gitignore b/test/.gitignore new file mode 100644 index 0000000..7de0b67 --- /dev/null +++ b/test/.gitignore @@ -0,0 +1 @@ +*.output diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000..e85c565 --- /dev/null +++ b/test/Makefile @@ -0,0 +1,29 @@ +CC = cc +AR = ar +RM = rm -f + +.c.o: + $(CC) -c -o $@ $< -I.. + +all: test + +test: exec_test1 + +exec_test1: test1 + @echo "Test1..." + @./test1 | tee test1.output 2>&1 + @if diff -u test1.expected test1.output; then \ + echo "Test1: passed."; \ + else \ + echo "Test1: failed."; \ + fi + +test1.o: test1.c ../longnumber.h + +test1: test1.o ../liblongnumber.a + $(CC) -o test1 test1.o -llongnumber -L.. + +clean:: + $(RM) test1 + $(RM) test1.o + $(RM) test1.output diff --git a/test/test1.c b/test/test1.c new file mode 100644 index 0000000..ce8c03e --- /dev/null +++ b/test/test1.c @@ -0,0 +1,78 @@ +#include +#include +#include "longnumber.h" + +void test_ln_create01(void) +{ + LongNumber *a; + a = ln_create(10, 0, 0); + ln_print(a, 10+1, "c01"); + ln_free(a); +} + +void test_ln_create02(void) +{ + LongNumber *a; + a = ln_create(10, 1, 3); + ln_print(a, 10+1, "c02"); + ln_free(a); +} + +void test_ln_create03(void) +{ + LongNumber *a; + a = ln_create(10, 2, 3); + ln_print(a, 10+1, "c03"); + ln_free(a); +} + +void test_ln_add01(void) +{ + LongNumber *a, *b; + a = ln_create(10, 0, 0); + b = ln_create(10, 0, 0); + ln_add(b, b, a, 10); + ln_print(b, 10+1, "a01"); + ln_free(a); + ln_free(b); +} + +void test_ln_add02(void) +{ + LongNumber *a, *b; + a = ln_create(10, 1, 3); + b = ln_create(10, 2, 3); + ln_add(b, b, a, 10); + ln_print(b, 10+1, "a02"); + ln_free(a); + ln_free(b); +} + +void test_ln_add03(void) +{ + LongNumber *a, *b; + a = ln_create(10, 2, 3); + b = ln_create(10, 2, 3); + ln_add(b, b, a, 10); + ln_print(b, 10+1, "a03"); + ln_free(a); + ln_free(b); +} + +int main(void) +{ + unsetenv("COLUMNS"); + + ln_init(4); + test_ln_create01(); + test_ln_create02(); + test_ln_create03(); + test_ln_add01(); + test_ln_add02(); + test_ln_add03(); + + ln_init(1); + test_ln_create01(); + + return 0; +} diff --git a/test/test1.expected b/test/test1.expected new file mode 100644 index 0000000..6e59098 --- /dev/null +++ b/test/test1.expected @@ -0,0 +1,13 @@ +c01 0.0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 ( 1- 40) + 0000 ( 41- 44) +c02 0.3333 3333 3333 3333 3333 3333 3333 3333 3333 3333 ( 1- 40) + 3333 ( 41- 44) +c03 0.6666 6666 6666 6666 6666 6666 6666 6666 6666 6666 ( 1- 40) + 6666 ( 41- 44) +a01 0.0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 ( 1- 40) + 0000 ( 41- 44) +a02 0.9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 ( 1- 40) + 9999 ( 41- 44) +a03 1.3333 3333 3333 3333 3333 3333 3333 3333 3333 3333 ( 1- 40) + 3332 ( 41- 44) +c01 0.0 0 0 0 0 0 0 0 0 0 0 ( 1- 11)