mirror of
https://github.com/samsonjs/lake.git
synced 2026-03-25 08:55:49 +00:00
add integer tests
This commit is contained in:
parent
6ef5fcb299
commit
f1972698a6
2 changed files with 67 additions and 1 deletions
|
|
@ -2,7 +2,7 @@ CC = gcc
|
|||
CFLAGS := -Wall -g -I../src $(shell pkg-config --cflags glib-2.0)
|
||||
LFLAGS := $(shell pkg-config --libs glib-2.0)
|
||||
OBJS = ../build/liblake.a
|
||||
TESTS = test_comment test_dlist test_env test_eval test_fn
|
||||
TESTS = test_comment test_dlist test_env test_eval test_fn test_int
|
||||
|
||||
all: $(TESTS)
|
||||
@clear
|
||||
|
|
@ -28,6 +28,9 @@ test_eval: laketest.o test_eval.o
|
|||
test_fn: laketest.o test_fn.o
|
||||
$(CC) $(CFLAGS) $(LFLAGS) $^ $(OBJS) -o $@
|
||||
|
||||
test_int: laketest.o test_int.o
|
||||
$(CC) $(CFLAGS) $(LFLAGS) $^ $(OBJS) -o $@
|
||||
|
||||
clean:
|
||||
-rm -f *.o $(TESTS)
|
||||
|
||||
|
|
|
|||
63
test/test_int.c
Normal file
63
test/test_int.c
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
/**
|
||||
* test_int.c
|
||||
* Lake Scheme
|
||||
*
|
||||
* Copyright 2011 Sami Samhuri
|
||||
* MIT License
|
||||
*
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "int.h"
|
||||
#include "laketest.h"
|
||||
#include "lake.h"
|
||||
|
||||
/* LakeInt *int_make(void) */
|
||||
static char *test_int_make(void)
|
||||
{
|
||||
LakeInt *i = int_make();
|
||||
lt_assert("int_make returned null", NULL != i);
|
||||
lt_assert("int_make did not return an integer", TYPE_INT == i->base.type);
|
||||
lt_assert("integer has incorrect size", sizeof(LakeInt) == i->base.size);
|
||||
lt_assert("integer was incorrectly initialized", 0 == INT_VAL(i));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* LakeInt *int_from_c(int n) */
|
||||
static char *test_int_from_c(void)
|
||||
{
|
||||
LakeInt *i = int_from_c(42);
|
||||
lt_assert("integer was incorrectly initialized", 42 == INT_VAL(i));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* LakeStr *int_repr(LakeInt *i) */
|
||||
static char *test_int_repr(void)
|
||||
{
|
||||
LakeInt *i = int_from_c(42);
|
||||
lt_assert("int_repr is wrong", strcmp(int_repr(i), "42") == 0);
|
||||
|
||||
i = int_from_c(0);
|
||||
lt_assert("int_repr is wrong", strcmp(int_repr(i), "0") == 0);
|
||||
|
||||
i = int_from_c(-42);
|
||||
lt_assert("int_repr is wrong", strcmp(int_repr(i), "-42") == 0);
|
||||
|
||||
i = int_from_c(2147483647);
|
||||
lt_assert("int_repr is wrong", strcmp(int_repr(i), "2147483647") == 0);
|
||||
|
||||
i = int_from_c(2147483648);
|
||||
lt_assert("int_repr is wrong", strcmp(int_repr(i), "-2147483648") == 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
return !lt_run_tests("Integers", (test_fn[]){
|
||||
test_int_make,
|
||||
test_int_from_c,
|
||||
test_int_repr,
|
||||
NULL
|
||||
});
|
||||
}
|
||||
Loading…
Reference in a new issue