summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2009-03-04 23:22:32 +0000
committerThomas White <taw@bitwiz.org.uk>2009-03-04 23:23:00 +0000
commita0a8c6218d027dd4b8b877cd9941a55fc6b4de65 (patch)
treee1c4e07803b33c1a72f26d19c9a6016c9915fb42
parent219f63c4bcbf877a41a70c6fd37ac63bd90b85b6 (diff)
Add a unit test program
-rw-r--r--.gitignore2
-rw-r--r--Makefile7
-rw-r--r--crystal.c4
-rw-r--r--crystal.h3
-rw-r--r--test.c33
5 files changed, 45 insertions, 4 deletions
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 <taw27@cam.ac.uk>
+ *
+ * Triclinator - solve nasty triclinic unit cells
+ *
+ */
+
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <math.h>
+
+#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;
+}