diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 0000000..eccfa59 --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,4 @@ +.PHONY: test +test: + cat ../THREAD_TABLE.scad | awk -f test_table.awk + diff --git a/tests/test_table.awk b/tests/test_table.awk index 5fa289f..0af95a1 100644 --- a/tests/test_table.awk +++ b/tests/test_table.awk @@ -25,8 +25,10 @@ function slope(x, y) { function test_horizontal() { # test whether v0 and v1 as well as v2 and v3 have the same radius - if (v0[1] != v1[1] || v2[1] != v3[1]) + if (v0[1] != v1[1] || v2[1] != v3[1]) { print designator " FAIL: not horizontal"; + PASS = 0; + } } BEGIN { @@ -35,20 +37,52 @@ BEGIN { pi = atan2(0, -1); deg = pi / 180; dphi = 0.001; + + PASS = 1; } { # first match-all rule: set state to untested tested = 0; } +/"[^,]+-ext/ { + # external threads have positive Rrot + parse(); + if (Rrot < 0) { + print designator " FAIL: negative radius of rotation"; + PASS = 0; + } + # test overlapp between thread and support + if (Rrot > Dsupport / 2) { + print designator " FAIL: Rsupport < Rrot"; + PASS = 0; + } +} + +/"[^,]+-int/ { + # internal threads have negative Rrot + parse(); + if (Rrot > 0) { + print designator " FAIL: positive radius of rotation"; + PASS = 0; + } + # test overlapp between thread and support + if (-Rrot < Dsupport / 2) { + print designator " FAIL: Rsupport > Rrot"; + PASS = 0; + } +} + /M[0-9.x-]+-ext/ { # ext M threads have +/-60 deg slopes, horizontal crest / valley parse(); m1 = slope(v0, v3) / deg; m2 = slope(v2, v1) / deg; if (m1 > 60 + dphi || m1 < 60 - dphi \ - || m2 < -60 - dphi || m2 > -60 + dphi) + || m2 < -60 - dphi || m2 > -60 + dphi) { print designator " FAIL: " m1 ", " m2 " deg"; + PASS = 0; + }; test_horizontal(); tested = 1; } @@ -59,8 +93,10 @@ BEGIN { m1 = slope(v3, v0) / deg; m2 = slope(v1, v2) / deg; if (m1 > -60 + dphi || m1 < -60 - dphi \ - || m2 < 60 - dphi || m2 > 60 + dphi) + || m2 < 60 - dphi || m2 > 60 + dphi) { print designator " FAIL: " m1 ", " m2 " deg"; + PASS = 0; + } test_horizontal(); tested = 1; } @@ -71,8 +107,10 @@ BEGIN { m1 = slope(v0, v3) / deg; m2 = slope(v2, v1) / deg; if (m1 > 62.5 + dphi || m1 < 62.5 - dphi \ - || m2 < -62.5 - dphi || m2 > -62.5 + dphi) + || m2 < -62.5 - dphi || m2 > -62.5 + dphi) { print designator " FAIL: " m1 ", " m2 " deg"; + PASS = 0; + } test_horizontal(); tested = 1; } @@ -83,8 +121,10 @@ BEGIN { m1 = slope(v3, v0) / deg; m2 = slope(v1, v2) / deg; if (m1 > -62.5 + dphi || m1 < -62.5 - dphi \ - || m2 < 62.5 - dphi || m2 > 62.5 + dphi) + || m2 < 62.5 - dphi || m2 > 62.5 + dphi) { print designator " FAIL: " m1 ", " m2 " deg"; + PASS = 0; + } test_horizontal(); tested = 1; } @@ -96,8 +136,10 @@ BEGIN { m1 = slope(v0, v3) / deg; m2 = slope(v2, v1) / deg; if (m1 > 70 + dphi || m1 < 70 - dphi \ - || m2 < -80 - dphi || m2 > -80 + dphi) + || m2 < -80 - dphi || m2 > -80 + dphi) { print designator " FAIL: " m1 ", " m2 " deg"; + PASS = 0; + } test_horizontal(); tested = 1; } @@ -109,8 +151,10 @@ BEGIN { m1 = slope(v3, v0) / deg; m2 = slope(v1, v2) / deg; if (m1 > -70 + dphi || m1 < -70 - dphi \ - || m2 < 80 - dphi || m2 > 80 + dphi) + || m2 < 80 - dphi || m2 > 80 + dphi) { print designator " FAIL: " m1 ", " m2 " deg"; + PASS = 0; + } test_horizontal(); tested = 1; } @@ -121,6 +165,12 @@ BEGIN { if (tested == 0) { parse(); print designator " FAIL: not tested"; + PASS = 0; }; } +END { + if (PASS == 1) print "TESTS SUCCESSFUL" + else print "TESTS FAIL"; +} +