Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.output
29 changes: 29 additions & 0 deletions test/Makefile
Original file line number Diff line number Diff line change
@@ -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
78 changes: 78 additions & 0 deletions test/test1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#include <stdio.h>
#include <stdlib.h>
#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;
}
13 changes: 13 additions & 0 deletions test/test1.expected
Original file line number Diff line number Diff line change
@@ -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)