mirror of
https://github.com/adrianschlatter/threadlib.git
synced 2025-08-02 19:47:51 +02:00
Unit tests for Rrot
Makefile for unit testing
This commit is contained in:
4
tests/Makefile
Normal file
4
tests/Makefile
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
.PHONY: test
|
||||||
|
test:
|
||||||
|
cat ../THREAD_TABLE.scad | awk -f test_table.awk
|
||||||
|
|
@@ -25,8 +25,10 @@ function slope(x, y) {
|
|||||||
|
|
||||||
function test_horizontal() {
|
function test_horizontal() {
|
||||||
# test whether v0 and v1 as well as v2 and v3 have the same radius
|
# 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";
|
print designator " FAIL: not horizontal";
|
||||||
|
PASS = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BEGIN {
|
BEGIN {
|
||||||
@@ -35,20 +37,52 @@ BEGIN {
|
|||||||
pi = atan2(0, -1);
|
pi = atan2(0, -1);
|
||||||
deg = pi / 180;
|
deg = pi / 180;
|
||||||
dphi = 0.001;
|
dphi = 0.001;
|
||||||
|
|
||||||
|
PASS = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
{ # first match-all rule: set state to untested
|
{ # first match-all rule: set state to untested
|
||||||
tested = 0;
|
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/ {
|
/M[0-9.x-]+-ext/ {
|
||||||
# ext M threads have +/-60 deg slopes, horizontal crest / valley
|
# ext M threads have +/-60 deg slopes, horizontal crest / valley
|
||||||
parse();
|
parse();
|
||||||
m1 = slope(v0, v3) / deg;
|
m1 = slope(v0, v3) / deg;
|
||||||
m2 = slope(v2, v1) / deg;
|
m2 = slope(v2, v1) / deg;
|
||||||
if (m1 > 60 + dphi || m1 < 60 - dphi \
|
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";
|
print designator " FAIL: " m1 ", " m2 " deg";
|
||||||
|
PASS = 0;
|
||||||
|
};
|
||||||
test_horizontal();
|
test_horizontal();
|
||||||
tested = 1;
|
tested = 1;
|
||||||
}
|
}
|
||||||
@@ -59,8 +93,10 @@ BEGIN {
|
|||||||
m1 = slope(v3, v0) / deg;
|
m1 = slope(v3, v0) / deg;
|
||||||
m2 = slope(v1, v2) / deg;
|
m2 = slope(v1, v2) / deg;
|
||||||
if (m1 > -60 + dphi || m1 < -60 - dphi \
|
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";
|
print designator " FAIL: " m1 ", " m2 " deg";
|
||||||
|
PASS = 0;
|
||||||
|
}
|
||||||
test_horizontal();
|
test_horizontal();
|
||||||
tested = 1;
|
tested = 1;
|
||||||
}
|
}
|
||||||
@@ -71,8 +107,10 @@ BEGIN {
|
|||||||
m1 = slope(v0, v3) / deg;
|
m1 = slope(v0, v3) / deg;
|
||||||
m2 = slope(v2, v1) / deg;
|
m2 = slope(v2, v1) / deg;
|
||||||
if (m1 > 62.5 + dphi || m1 < 62.5 - dphi \
|
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";
|
print designator " FAIL: " m1 ", " m2 " deg";
|
||||||
|
PASS = 0;
|
||||||
|
}
|
||||||
test_horizontal();
|
test_horizontal();
|
||||||
tested = 1;
|
tested = 1;
|
||||||
}
|
}
|
||||||
@@ -83,8 +121,10 @@ BEGIN {
|
|||||||
m1 = slope(v3, v0) / deg;
|
m1 = slope(v3, v0) / deg;
|
||||||
m2 = slope(v1, v2) / deg;
|
m2 = slope(v1, v2) / deg;
|
||||||
if (m1 > -62.5 + dphi || m1 < -62.5 - dphi \
|
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";
|
print designator " FAIL: " m1 ", " m2 " deg";
|
||||||
|
PASS = 0;
|
||||||
|
}
|
||||||
test_horizontal();
|
test_horizontal();
|
||||||
tested = 1;
|
tested = 1;
|
||||||
}
|
}
|
||||||
@@ -96,8 +136,10 @@ BEGIN {
|
|||||||
m1 = slope(v0, v3) / deg;
|
m1 = slope(v0, v3) / deg;
|
||||||
m2 = slope(v2, v1) / deg;
|
m2 = slope(v2, v1) / deg;
|
||||||
if (m1 > 70 + dphi || m1 < 70 - dphi \
|
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";
|
print designator " FAIL: " m1 ", " m2 " deg";
|
||||||
|
PASS = 0;
|
||||||
|
}
|
||||||
test_horizontal();
|
test_horizontal();
|
||||||
tested = 1;
|
tested = 1;
|
||||||
}
|
}
|
||||||
@@ -109,8 +151,10 @@ BEGIN {
|
|||||||
m1 = slope(v3, v0) / deg;
|
m1 = slope(v3, v0) / deg;
|
||||||
m2 = slope(v1, v2) / deg;
|
m2 = slope(v1, v2) / deg;
|
||||||
if (m1 > -70 + dphi || m1 < -70 - dphi \
|
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";
|
print designator " FAIL: " m1 ", " m2 " deg";
|
||||||
|
PASS = 0;
|
||||||
|
}
|
||||||
test_horizontal();
|
test_horizontal();
|
||||||
tested = 1;
|
tested = 1;
|
||||||
}
|
}
|
||||||
@@ -121,6 +165,12 @@ BEGIN {
|
|||||||
if (tested == 0) {
|
if (tested == 0) {
|
||||||
parse();
|
parse();
|
||||||
print designator " FAIL: not tested";
|
print designator " FAIL: not tested";
|
||||||
|
PASS = 0;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
END {
|
||||||
|
if (PASS == 1) print "TESTS SUCCESSFUL"
|
||||||
|
else print "TESTS FAIL";
|
||||||
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user