diff options
author | Calvin Morrison <mutantturkey@gmail.com> | 2013-10-31 15:47:03 -0400 |
---|---|---|
committer | Calvin Morrison <mutantturkey@gmail.com> | 2013-10-31 15:47:03 -0400 |
commit | dd8aba39b848ec48c943ea3d3cbb75bbe9616f30 (patch) | |
tree | feee3e37c77defdb987aee1c63c1f0a6635448b7 | |
parent | 8b543ec38690a7a41297fda56335b7f15cb0be8d (diff) |
inital test system in place
-rw-r--r-- | src/c/Makefile | 13 | ||||
-rw-r--r-- | src/c/test.c | 124 |
2 files changed, 131 insertions, 6 deletions
diff --git a/src/c/Makefile b/src/c/Makefile index 1d3581d..0039230 100644 --- a/src/c/Makefile +++ b/src/c/Makefile @@ -1,10 +1,9 @@ VERSION=\"v1.0.4\" UNAME := $(shell uname) +PWD = $(shell pwd) CC = gcc -QUIKR_TRAIN_CFLAGS = -D$(UNAME) -DVERSION=$(VERSION) -MULTIFASTA_CFLAGS = -pthread -L../ -I../ -std=gnu99 -fopenmp -D$(UNAME) -DVERSION=$(VERSION) -QUIKR_CFLAGS = -D$(UNAME) -DVERSION=$(VERSION) -CFLAGS = -Wall -Wextra -lm -lz +MULTIFASTA_CFLAGS = -pthread -L../ -I../ -std=gnu99 -fopenmp +CFLAGS = -Wall -Wextra -lm -lz -D$(UNAME) -DVERSION=$(VERSION) ifndef DEBUG @@ -13,7 +12,7 @@ else CFLAGS += -ggdb3 -O0 endif -all: nnls.o kmer_utils.o quikr_train quikr multifasta_to_otu +all: nnls.o kmer_utils.o quikr_functions.o quikr_train quikr multifasta_to_otu test nnls.o: nnls.c $(CC) -c nnls.c -o nnls.o $(CFLAGS) @@ -26,6 +25,8 @@ multifasta_to_otu: kmer_utils.o nnls.o quikr_functions.o multifasta_to_otu.c quikr_train: kmer_utils.o quikr_functions.o quikr_train.c $(CC) quikr_train.c quikr_functions.o kmer_utils.o -o quikr_train $(CFLAGS) $(QUIKR_TRAIN_CFLAGS) quikr: kmer_utils.o nnls.o quikr_functions.o quikr.c - $(CC) quikr.c quikr_functions.o nnls.o kmer_utils.o -o quikr $(CFLAGS) $(QUIKR_CFLAGS) -I../ + $(CC) quikr.c quikr_functions.o nnls.o kmer_utils.o -o quikr $(CFLAGS) $(QUIKR_CFLAGS) clean: rm -v quikr_train quikr multifasta_to_otu *.o +test: kmer_utils.o nnls.o quikr_functions.o test.c + $(CC) test.c quikr_functions.o nnls.o kmer_utils.o -o test $(CFLAGS) -I$(PWD) diff --git a/src/c/test.c b/src/c/test.c new file mode 100644 index 0000000..fa905af --- /dev/null +++ b/src/c/test.c @@ -0,0 +1,124 @@ +#include <ctype.h> +#include <errno.h> +#include <math.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <zlib.h> + +#include "quikr.h" +#include "quikr_functions.h" + + +static int failed = 0; + +void status(int test, int pass, char *testname) { + fprintf(stdout, "test %d in %s ", test, testname); + + if(pass) + fprintf(stdout, "passed.\n"); + else { + fprintf(stdout, "failed. \n"); + failed = 1; + } +} + +#define test_eq(data, value) status(test_number, (data == value), test_name); test_number++; +#define test_n_eq(data, value) status(test_number, (data != value), test_name); test_number++; +#define test_gt(data, value) status(test_number, (data < value), test_name); test_number++; +#define test_lt(data, value) status(test_number, (data > value), test_name); test_number++; + +#define header(test_name) printf("testing %s:\n", test_name); +#define footer() printf("\n\n");; + +void test_count_sequences() { + + int test_number = 1; + char *test_name = "test_count_sequences"; + + // test 1 + // Make sure we can count this properly + int t_count_sequences_res = count_sequences("tests/data/test.fa"); + test_eq(t_count_sequences_res, 17414); + + // test 2 + // Should be zero, since the file is empty + t_count_sequences_res = count_sequences("tests/data/empty.fa"); + test_eq(t_count_sequences_res, 0); + + // test 3 + // Doesn't exist, count should be zero + t_count_sequences_res = count_sequences("non-existant-file"); + test_eq(t_count_sequences_res, 0); + +} + + +void test_normalize_matrix() { + + int test_number = 1; + int fail_flag = 0; + char *test_name = "test_normailze_matrix"; + char *type = "%lf"; + + double sum = 0; + int i = 0; + int j = 0; + + double matrix_1[4] = {1,1,1,1}; + double matrix_2[8] = {2,2,4,4,8,8,16,16}; + + + // test 1 + // our matrix to sum to 1 properly even with only one row + normalize_matrix(matrix_1, 1, 4); + for(i = 0; i < 4; i++) + sum += matrix_1[i]; + + test_eq(sum, 1); + + // test 2 + // each element in the array should be .25 + for(i = 0; i < 4; i++) + if(matrix_1[i] != 0.25) + fail_flag = 1; + + test_eq(fail_flag, 0); + + fail_flag = 0; + sum = 0; + // test 3 + // make sure a multidimensional array sums each row properly + normalize_matrix(matrix_2, 2, 4); + for(j = 0; j < 2; j++) { + double row_sum = 0; + + for(i = 0; i < 4; i++) + row_sum += matrix_2[j*2 + i]; + + // floating point hack + if(fabsl(row_sum - 1.0) > .0001) + fail_flag = 1; + } + + test_eq(fail_flag, (double)0); + +} + +int main(int argc, char **argv) { + int test_number = 1; + + header("count_sequences"); + test_count_sequences(); + footer(); + + header("normalize_matrix"); + test_normalize_matrix(); + footer(); + + if(failed) + return EXIT_FAILURE; + else + return EXIT_SUCCESS; +}; |