Skip to content

Commit

Permalink
Merge pull request #41 from jenniferliddle/devel
Browse files Browse the repository at this point in the history
Added unit test for array.c, and tidied tests generally
  • Loading branch information
jenniferliddle authored Nov 25, 2016
2 parents a93478f + d0e8493 commit 9019ccf
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 6 deletions.
10 changes: 9 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
ACLOCAL_AMFLAGS= -I m4
TESTS = test/t_bamit test/t_chrsplit test/t_select test/t_bclfile test/t_decode test/t_filterfile test/t_posfile test/t_i2b
TESTS = test/t_array \
test/t_bamit \
test/t_chrsplit \
test/t_select \
test/t_bclfile \
test/t_decode \
test/t_filterfile \
test/t_posfile \
test/t_i2b
SUBDIRS = src test
dist_doc_DATA = README.md LICENSE
AM_COLOR_TESTS=always
1 change: 0 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
AC_INIT([bambi], m4_esyscmd_s([git describe --dirty --always --tags]), [[email protected]])
AC_ARG_VAR(HTSDIR,Directory to look for hts)
#AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects tar-pax no-dependencies])
AM_INIT_AUTOMAKE([-Wall -Werror foreign tar-pax no-dependencies])
AC_PROG_CC

Expand Down
6 changes: 5 additions & 1 deletion test/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
AM_CPPFLAGS = $(HTSLIB_CPPFLAGS) -std=gnu99
AM_LDFLAGS = $(HTSLIB_LDFLAGS)

check_PROGRAMS = t_bamit t_chrsplit t_select t_bclfile t_decode t_filterfile t_posfile t_i2b
check_PROGRAMS = t_array t_bamit t_chrsplit t_select t_bclfile t_decode t_filterfile t_posfile t_i2b

t_select_SOURCES = t_select.c $(top_srcdir)/src/select.c ../src/array.c ../src/bamit.c ../src/parse.c ../src/hts_addendum.c
t_select_CFLAGS = -I$(top_srcdir)/src -DDATA_DIR=$(abs_srcdir)/data
Expand All @@ -15,6 +15,10 @@ t_bamit_SOURCES = t_bamit.c $(top_srcdir)/src/bamit.c
t_bamit_CFLAGS = -I$(top_srcdir)/src -DDATA_DIR=$(abs_srcdir)/data
t_bamit_LDADD = $(HTSLIB_HOME)/lib/libhts.a -lz -ldl -lxml2 -lpthread -llzma -lbz2

t_array_SOURCES = t_array.c $(top_srcdir)/src/array.c
t_array_CFLAGS = -I$(top_srcdir)/src -DDATA_DIR=$(abs_srcdir)/data
t_array_LDADD = $(HTSLIB_HOME)/lib/libhts.a -lz -ldl -lxml2 -lpthread -llzma -lbz2

t_bclfile_SOURCES = t_bclfile.c
t_bclfile_CFLAGS = -DDATA_DIR=$(abs_srcdir)/data
t_bclfile_LDADD = -lz -ldl -lxml2 -lpthread
Expand Down
2 changes: 1 addition & 1 deletion test/data/out/select_1_metrics.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/data/select_1_human.sam
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,4 @@ IL16_986:1:9:9:307 129 12 54468914 0 37M 1 90707227 0 AAAAAAAAAAAAAAAAAAAAAAAAAA
IL16_986:1:9:9:47 113 5 34606831 0 37M 1 187335121 0 TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> X0:i:24815 MD:Z:37 RG:Z:1 XG:i:0 AM:i:0 NM:i:0 SM:i:0 XM:i:0 XO:i:0 XT:A:R
IL16_986:1:9:9:47 177 1 187335121 0 37M 5 34606831 0 TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< X0:i:24815 MD:Z:37 RG:Z:1 XG:i:0 AM:i:0 NM:i:0 SM:i:0 XM:i:0 XO:i:0 XT:A:R
IL16_986:1:9:9:954 113 6 84008653 0 37M 5 143379477 0 TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> X0:i:24815 MD:Z:37 RG:Z:1 XG:i:0 AM:i:0 NM:i:0 SM:i:0 XM:i:0 XO:i:0 XT:A:R
IL16_986:1:9:9:954 177 5 143379477 0 37M 6 84008653 0 TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< X0:i:24815 MD:Z:37 RG:Z:1 XG:i:0 AM:i:0 NM:i:0 SM:i:0 XM:i:0 XO:i:0 XT:A:R
IL16_986:1:9:9:954 173 5 143379477 0 37M 6 84008653 0 TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< X0:i:24815 MD:Z:37 RG:Z:1 XG:i:0 AM:i:0 NM:i:0 SM:i:0 XM:i:0 XO:i:0 XT:A:R
96 changes: 96 additions & 0 deletions test/t_array.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/* t_array.c -- array test cases.
Copyright (C) 2016 Genome Research Ltd.
Author: Jennifer Liddle <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include "array.h"
#include "htslib/hts.h"

#define xMKNAME(d,f) #d f
#define MKNAME(d,f) xMKNAME(d,f)


int verbose = 0;

int success = 0;
int failure = 0;

void checkEqual(char *name, char *expected, char *actual)
{
if (actual == NULL) actual = "<null>";
if (strcmp(expected, actual)) {
fprintf(stderr, "%s: Expected: %s \tGot: %s\n", name, expected, actual);
failure++;
}
}

void icheckEqual(char *name, int expected, int actual)
{
if (expected != actual) {
fprintf(stderr, "%s: Expected: %d \tGot: %d\n", name, expected, actual);
failure++;
}
}

int main(int argc, char**argv)
{
va_t *va = va_init(2,free);
ia_t *ia = ia_init(3);

icheckEqual("va Initially empty", true, va_isEmpty(va));
icheckEqual("ia Initially empty", true, ia_isEmpty(ia));

va_push(va,strdup("Hello world"));
ia_push(ia, 1);
icheckEqual("va one item", 1, va->end);
icheckEqual("ia one item", 1, ia->end);

va_push(va,strdup("xyzzy"));
ia_push(ia, 2);
va_push(va,strdup("xyzzy"));
ia_push(ia, 3);
va_push(va,strdup("xyzzy"));
ia_push(ia, 9);
va_push(va,strdup("plugh"));
ia_push(ia, 5);
icheckEqual("va five items", 5, va->end);
icheckEqual("ia five items", 5, ia->end);

checkEqual("va first item", "Hello world", va->entries[0]);
icheckEqual("ia first item", 1, ia->entries[0]);
checkEqual("va last item", "plugh", va->entries[va->end-1]);
icheckEqual("ia last item", 5, ia->entries[ia->end-1]);

ia_sort(ia);
icheckEqual("ia sort first", 1, ia->entries[0]);
icheckEqual("ia sort last", 9, ia->entries[ia->end-1]);

char *s = ia_join(ia,"xyz");
checkEqual("ia join", "1xyz2xyz3xyz5xyz9", s);

ia_free(ia);
va_free(va);

printf("array tests: %s\n", failure ? "FAILED" : "Passed");
return failure ? EXIT_FAILURE : EXIT_SUCCESS;
}
3 changes: 3 additions & 0 deletions test/t_bamit.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,7 @@ int main(int argc, char**argv)
icheckEqual("Number of records", 6, n);
icheckEqual("End of records", false, BAMit_hasnext(bit));
BAMit_free(bit);

printf("BAMit tests: %s\n", failure ? "FAILED" : "Passed");
return failure ? EXIT_FAILURE : EXIT_SUCCESS;
}
2 changes: 1 addition & 1 deletion test/t_chrsplit.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,6 @@ int main(int argc, char**argv)
testxahuman(TMPDIR);
testxahuman_exclude_unaligned(TMPDIR);

printf("select tests: %s\n", failure ? "FAILED" : "Passed");
printf("chrsplit tests: %s\n", failure ? "FAILED" : "Passed");
return failure ? EXIT_FAILURE : EXIT_SUCCESS;
}

0 comments on commit 9019ccf

Please sign in to comment.