threadlib/tests/test_table.awk
Adrian Schlatter 827723d1b1 Eliminate threads.xlsx
Replaces threads.xlsx by one .csv file and one awk script per thread
type. The script calculates threadlib specs from the data in the .csv
file. Finally and as before, autogenerate.awk generates the OpenSCAD
code (i.e. THREAD_TABLE.scad).

A new Makefile automates this process: make does what is needed. It
also provides a target 'test' to run the (existing) tests.

To add a new thread type:

- provide newthread.csv
- provide newthread.awk
- modify Makefile to generate your new threads
- add appropriate tests

Additionally:

- fixed bug in Rrot when DRmax is too large.
- reduced number of significant figures to a resolution of 0.1 um
  (while not extremely generous for the very finest threads, it
  should be enough by far for any 3D-prints).
- increased test limit for thread angle deviations (necessary due to
  reduced number of significant figures)
- added test counter: 'make test' now prints number of tests run +
  number of threads tested.
- For unknown reasons (MacOS awk?) final match-all rule in
  test_table.awk does not match with double-quotes. Work-around: Match
  without double-quotes.
2019-05-05 22:29:09 +02:00

189 lines
3.9 KiB
Awk

function parse() {
gsub(/[]\[" ]/, "");
designator = $1;
pitch = $2;
Rrot = $3;
Dsupport = $4;
v0[1] = $5;
v0[0] = $6;
v1[1] = $7;
v1[0] = $8;
v2[1] = $9;
v2[0] = $10;
v3[1] = $11;
v3[0] = $12;
}
function slope(x, y) {
# return the slope from vector x to vector y
return atan2(y[1] - x[1], y[0] - x[0])
}
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]) {
print designator " FAIL: not horizontal";
PASS = 0;
}
}
BEGIN {
# define useful constants
FS = ",";
pi = atan2(0, -1);
deg = pi / 180;
dphi = 0.1;
PASS = 1;
NR_OF_TESTS = 0;
NR_OF_THREADS = 0;
}
{ # 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;
}
NR_OF_TESTS += 2;
}
/"[^,]+-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;
}
NR_OF_TESTS += 2;
}
/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) {
print designator " FAIL: " m1 ", " m2 " deg";
PASS = 0;
};
test_horizontal();
tested = 1;
NR_OF_TESTS += 2;
}
/M[0-9.x-]+-int/ {
# int M threads have +/-60 deg slopes, horizontal crest / valley
parse();
m1 = slope(v3, v0) / deg;
m2 = slope(v1, v2) / deg;
if (m1 > -60 + dphi || m1 < -60 - dphi \
|| m2 < 60 - dphi || m2 > 60 + dphi) {
print designator " FAIL: " m1 ", " m2 " deg";
PASS = 0;
}
test_horizontal();
tested = 1;
NR_OF_TESTS += 2;
}
/G.+-ext/ {
# ext M threads have +/-62.5 deg slopes, horizontal crest / valley
parse();
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) {
print designator " FAIL: " m1 ", " m2 " deg";
PASS = 0;
}
test_horizontal();
tested = 1;
NR_OF_TESTS += 2;
}
/G.+-int/ {
# int G threads have +/-62.5 deg slopes, horizontal crest / valley
parse();
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) {
print designator " FAIL: " m1 ", " m2 " deg";
PASS = 0;
}
test_horizontal();
tested = 1;
NR_OF_TESTS += 2;
}
/PCO.+-ext/ {
# PCO-1881 threads have slopes of -80 deg (on the load side) and 70 deg
# (on the other side) + horizontal crest / valley
parse();
m1 = slope(v0, v3) / deg;
m2 = slope(v2, v1) / deg;
if (m1 > 70 + dphi || m1 < 70 - dphi \
|| m2 < -80 - dphi || m2 > -80 + dphi) {
print designator " FAIL: " m1 ", " m2 " deg";
PASS = 0;
}
test_horizontal();
tested = 1;
NR_OF_TESTS += 2;
}
/PCO.+-int/ {
# PCO-1881 threads have slopes of 80 deg (on the load side) and -70 deg
# (on the other side) + horizontal crest / valley
parse();
m1 = slope(v3, v0) / deg;
m2 = slope(v1, v2) / deg;
if (m1 > -70 + dphi || m1 < -70 - dphi \
|| m2 < 80 - dphi || m2 > 80 + dphi) {
print designator " FAIL: " m1 ", " m2 " deg";
PASS = 0;
}
test_horizontal();
tested = 1;
NR_OF_TESTS += 2;
}
/[^,]+-(int|ext)/ {
# final match-all (designators) rule: test wether all lines have been
# tested
if (tested == 0) {
parse();
print designator " FAIL: not tested";
PASS = 0;
};
NR_OF_THREADS += 1;
}
END {
print "Ran " NR_OF_TESTS " tests on " NR_OF_THREADS " threads";
if (PASS == 1) print "TESTS SUCCESSFUL"
else print "TESTS FAIL";
}