From a0a8c6218d027dd4b8b877cd9941a55fc6b4de65 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 4 Mar 2009 23:22:32 +0000 Subject: Add a unit test program --- .gitignore | 2 ++ Makefile | 7 +++++-- crystal.c | 4 ++-- crystal.h | 3 +++ test.c | 33 +++++++++++++++++++++++++++++++++ 5 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 test.c diff --git a/.gitignore b/.gitignore index 6003c91..bd54b70 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ *.o triclinator +test + diff --git a/Makefile b/Makefile index 3878741..b83eec3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,8 @@ triclinator: main.o crystal.o util.o - gcc main.o crystal.o util.o -o triclinator -lgsl -lgslcblas + gcc main.o crystal.o util.o -o triclinator -lgsl -lgslcblas -lm + +test: test.o crystal.o util.o + gcc test.o crystal.o util.o -o test -lm main.o: main.c gcc -g -c -I/usr/include main.c -o main.o @@ -11,6 +14,6 @@ util.o: util.c gcc -g -c -I/usr/include util.c -o util.o clean: - rm -f triclinator main.o crystal.o util.o + rm -f triclinator test main.o crystal.o util.o test.o .PHONY: clean diff --git a/crystal.c b/crystal.c index 065236a..cd6ef8a 100644 --- a/crystal.c +++ b/crystal.c @@ -65,7 +65,7 @@ static double volume(Cell cell) } -static double dspacing(Cell cell, double h, double k, double l) +double dspacing(Cell cell, double h, double k, double l) { double sum_S_terms, one_over_Vsq, one_over_LHS; @@ -80,7 +80,7 @@ static double dspacing(Cell cell, double h, double k, double l) } -static double plane_angle(Cell cell, double h1, double k1, double l1, +double plane_angle(Cell cell, double h1, double k1, double l1, double h2, double k2, double l2) { double sum_S_terms, d1, d2, dd_over_Vsq; diff --git a/crystal.h b/crystal.h index 5c38da8..21dc5c8 100644 --- a/crystal.h +++ b/crystal.h @@ -29,5 +29,8 @@ typedef struct /* Return what the measurement 'val' would have been if the cell were 'cell' */ extern double crystal_calc(MVal val, Cell cell); +extern double dspacing(Cell cell, double h, double k, double l); +extern double plane_angle(Cell cell, double h1, double k1, double l1, + double h2, double k2, double l2); #endif /* CRYSTAL_H */ diff --git a/test.c b/test.c new file mode 100644 index 0000000..b807681 --- /dev/null +++ b/test.c @@ -0,0 +1,33 @@ +/* + * test.c + * + * Unit tests + * + * (c) 2009 Thomas White + * + * Triclinator - solve nasty triclinic unit cells + * + */ + + +#include +#include +#include + +#include "crystal.h" + +int main(void) +{ + Cell cell; + + cell.a = 1.0; + cell.b = 1.0; + cell.c = 1.0; + cell.al = DEG2RAD(90.0); + cell.be = DEG2RAD(120.0); + cell.ga = DEG2RAD(90.0); + + printf("%8.5f deg\n", RAD2DEG(plane_angle(cell, 0, 0, 1, 0, 1, 0))); + + return 0; +} -- cgit v1.2.3