From 844f29f5b8b7229e8983b4a2dfc9a21ed8931811 Mon Sep 17 00:00:00 2001 From: Katja Date: Fri, 11 Nov 2011 16:00:56 +0000 Subject: add libdir 'testtools' with test abstractions to externals - abstraction 'unit-test-frame~.pd' - abstraction 'unit-test-frame.pd' - example patches svn path=/trunk/externals/testtools/; revision=15724 --- unit-test-frame.pd | 568 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 568 insertions(+) create mode 100644 unit-test-frame.pd (limited to 'unit-test-frame.pd') diff --git a/unit-test-frame.pd b/unit-test-frame.pd new file mode 100644 index 0000000..9cd29ba --- /dev/null +++ b/unit-test-frame.pd @@ -0,0 +1,568 @@ +#N canvas 435 37 710 662 10; +#X obj 620 302 bng 50 250 50 0 empty empty list 5 25 0 14 -203904 -262144 +-1; +#X obj 315 301 bng 50 250 50 0 empty empty list 5 25 0 14 -203904 -262144 +-1; +#X obj 100 300 bng 50 250 50 0 empty empty list 5 25 0 14 -203904 -262144 +-1; +#X obj 621 239 bng 50 250 50 0 empty empty ? 15 25 0 30 -260097 -262144 +-1; +#X obj 474 302 hsl 130 50 0 127 0 0 \$0-dummysend \$0-stddev-label +STDDEV-ZERO 4 35 0 10 -203904 -203904 -1 0 1; +#X floatatom 477 309 18 0 0 0 - #0-stddev -; +#X obj 256 301 bng 50 250 50 0 empty empty test 5 25 0 14 -260097 -262144 +-1; +#X obj 40 300 bng 50 250 50 0 empty empty write 4 25 0 14 -260097 -262144 +-1; +#X obj 43 239 hsl 195 50 0 112 0 0 \$0-dummysend \$0-dummyreceive empty +-2 -8 0 10 -203904 -203904 -203904 0 1; +#X symbolatom 45 247 25 0 0 0 - #0-refname #0-dummysend; +#X text 44 267 reference; +#N canvas 607 182 376 522 std.deviation 0; +#X obj 80 127 until; +#X obj 95 155 + 1; +#X obj 80 180 f; +#X obj 80 99 t f b; +#X msg 122 163 0; +#X obj 107 310 +; +#X floatatom 107 337 8 0 0 0 - - -; +#X obj 92 361 f; +#X text 153 163 clear sums; +#X obj 52 234 == 511; +#X obj 52 258 sel 1; +#X obj 80 203 t f f; +#X obj 107 261 t f f; +#X obj 107 286 *; +#X obj 92 386 / 512; +#X obj 92 410 sqrt; +#X obj 92 439 outlet; +#X text 137 441 stddev; +#X obj 186 439 s \$0-stddev; +#X obj 107 233 tabread \$0-difference; +#X obj 191 58 + 1; +#X obj 80 75 f 512; +#X floatatom 202 10 5 0 0 0 - - -; +#X obj 263 -16 r \$0-test-delay; +#X obj 263 30 + 10; +#X floatatom 272 8 5 0 0 0 - - -; +#X obj 80 47 delay 10; +#X obj 191 -16 r \$0-index; +#X obj 80 -16 r \$0-test-prepare; +#X connect 0 0 2 0; +#X connect 1 0 2 1; +#X connect 2 0 1 0; +#X connect 2 0 11 0; +#X connect 3 0 0 0; +#X connect 3 1 4 0; +#X connect 4 0 2 1; +#X connect 4 0 5 1; +#X connect 5 0 6 0; +#X connect 6 0 5 1; +#X connect 6 0 7 1; +#X connect 7 0 14 0; +#X connect 9 0 10 0; +#X connect 10 0 7 0; +#X connect 11 0 9 0; +#X connect 11 1 19 0; +#X connect 12 0 13 0; +#X connect 12 1 13 1; +#X connect 13 0 5 0; +#X connect 14 0 15 0; +#X connect 15 0 16 0; +#X connect 15 0 18 0; +#X connect 19 0 12 0; +#X connect 20 0 14 1; +#X connect 20 0 21 1; +#X connect 21 0 3 0; +#X connect 23 0 24 0; +#X connect 23 0 25 0; +#X connect 24 0 26 1; +#X connect 26 0 21 0; +#X connect 27 0 9 1; +#X connect 27 0 20 0; +#X connect 27 0 22 0; +#X connect 28 0 26 0; +#X restore 327 123 pd std.deviation; +#N canvas 905 83 262 193 refname+ID 0; +#X obj 26 47 inlet; +#X obj 71 96 f \$0; +#X obj 26 120 pack s f; +#X obj 26 74 t a b; +#X obj 26 152 s \$0-refname+ID; +#X connect 0 0 3 0; +#X connect 1 0 2 1; +#X connect 2 0 4 0; +#X connect 3 0 2 0; +#X connect 3 1 1 0; +#X restore 56 129 pd refname+ID; +#X obj 39 177 s \$0-refname; +#X obj 39 153 symbol; +#X obj 39 23 inlet; +#N canvas 67 138 412 506 load-reference 0; +#X obj 36 27 inlet; +#X obj 36 203 soundfiler; +#X obj 81 112 f \$0; +#X obj 36 136 pack s f; +#X obj 36 94 t a b; +#X obj 36 461 s \$0-do-test; +#X msg 36 173 read ./\$1.wav \$2-reference; +#X obj 75 375 pack s s s s s s; +#X obj 168 297 r \$0-refname; +#X obj 75 432 stdout; +#X obj 36 235 sel 512; +#X obj 36 60 spigot 1; +#X msg 81 27 0; +#X text 119 29 at load \, try to read reference file and do test; +#X msg 75 271 REFERENCE-FILE-ERROR reference file not found:; +#X msg 168 324 \$1.wav; +#X obj 168 349 symbol; +#X obj 75 402 list trim; +#X obj 127 432 print unit-test; +#X connect 0 0 11 0; +#X connect 1 0 10 0; +#X connect 2 0 3 1; +#X connect 3 0 6 0; +#X connect 4 0 3 0; +#X connect 4 1 2 0; +#X connect 6 0 1 0; +#X connect 7 0 17 0; +#X connect 8 0 15 0; +#X connect 10 0 5 0; +#X connect 10 1 14 0; +#X connect 11 0 4 0; +#X connect 11 0 12 0; +#X connect 12 0 11 1; +#X connect 14 0 7 0; +#X connect 15 0 16 0; +#X connect 16 0 7 5; +#X connect 17 0 9 0; +#X connect 17 0 18 0; +#X restore 74 105 pd load-reference; +#X obj 328 27 inlet; +#X obj 630 22 inlet; +#X obj 238 628 outlet; +#X obj 286 628 outlet; +#X obj 335 629 outlet; +#X obj 238 555 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 +-1 -1; +#X msg 288 508 const 0; +#X obj 288 531 s \$0-system-under-test; +#X obj 39 49 unpack s f; +#X obj 96 78 s \$0-test-delay; +#N canvas 568 53 379 248 table 0; +#X obj 45 199 tabwrite \$0-system-under-test; +#X obj 216 70 f; +#X obj 245 70 + 1; +#X obj 45 53 t f b; +#X msg 231 45 0; +#X obj 45 22 inlet; +#X obj 62 172 tabwrite \$0-difference; +#X obj 77 119 tabread \$0-reference; +#X obj 77 87 t f f; +#X obj 231 21 r \$0-test-prepare; +#X obj 237 135 s \$0-index; +#X obj 62 145 -; +#X obj 237 108 moses 512; +#X connect 1 0 2 0; +#X connect 1 0 8 0; +#X connect 1 0 0 1; +#X connect 1 0 12 0; +#X connect 2 0 1 1; +#X connect 3 0 0 0; +#X connect 3 0 11 0; +#X connect 3 1 1 0; +#X connect 4 0 1 1; +#X connect 5 0 3 0; +#X connect 7 0 11 1; +#X connect 8 0 7 0; +#X connect 8 1 6 1; +#X connect 9 0 4 0; +#X connect 11 0 6 0; +#X connect 12 0 10 0; +#X restore 328 85 pd table; +#X obj 238 509 t b b b; +#N canvas 0 22 256 269 view-system 0; +#X obj 39 39 inlet; +#X msg 39 75 arrayviewlistnew; +#X obj 39 174 s \$0-system-under-test; +#X obj 67 118 r \$0-test-prepare; +#X msg 67 144 arrayviewclose; +#X connect 0 0 1 0; +#X connect 1 0 2 0; +#X connect 3 0 4 0; +#X connect 4 0 2 0; +#X restore 351 507 pd view-system; +#N canvas 695 50 264 263 view-difference 0; +#X obj 39 39 inlet; +#X obj 39 180 s \$0-difference; +#X msg 39 75 arrayviewlistnew; +#X obj 57 108 r \$0-test-prepare; +#X msg 57 135 arrayviewclose; +#X connect 0 0 2 0; +#X connect 2 0 1 0; +#X connect 3 0 4 0; +#X connect 4 0 1 0; +#X restore 584 520 pd view-difference; +#N canvas 453 143 231 283 view-reference 0; +#X obj 27 31 inlet; +#X msg 27 59 arrayviewlistnew; +#X obj 27 144 s \$0-reference; +#X obj 42 88 r \$0-test-prepare; +#X msg 42 114 arrayviewclose; +#X connect 0 0 1 0; +#X connect 1 0 2 0; +#X connect 3 0 4 0; +#X connect 4 0 2 0; +#X restore 100 507 pd view-reference; +#N canvas 704 28 384 625 write-reference 0; +#X obj 51 344 soundfiler; +#X obj 51 287 list; +#X obj 50 16 inlet; +#X floatatom 82 378 5 0 0 0 - - -; +#X obj 72 257 r \$0-refname+ID; +#X text 90 16 bang; +#X obj 51 124 r \$0-do-write-reference; +#X obj 143 152 r \$0-abort-write-reference; +#X obj 51 379 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1 +-1; +#X obj 51 583 s \$0-do-test; +#X obj 72 153 delay 500; +#X obj 257 20 r \$0-refname; +#X msg 257 46 \$1.wav; +#X obj 257 72 symbol; +#X obj 257 99 s \$0-ref-wav-name; +#N canvas 682 430 395 255 write-reference-popup\$0 0; +#X obj 88 174 bng 60 400 50 0 \$0-do-write-reference empty continue +2 28 0 12 -260097 -262144 -1; +#X obj 234 174 bng 60 300 50 0 \$0-abort-write-reference empty abort +8 28 0 12 -204786 -262144 -1; +#X obj 91 67 hsl 200 80 0 127 0 0 \$0-dummysend \$0-dummyreceive empty +-2 -8 0 10 -262144 -262144 -1 0 1; +#X symbolatom 95 85 30 0 0 0 - #0-refname #0-dummysend; +#X symbolatom 95 125 30 0 0 0 - #0-ref-wav-name #0-dummysend; +#X text 93 67 reference name:; +#X text 93 108 file name:; +#X text 24 11 This action will overwrite your reference .wav file with +the content of \$0-signal-under-test. The action can not be undone! +; +#X restore 51 95 pd write-reference-popup\$0; +#X obj 50 68 s pd-write-reference-popup\$0; +#X msg 50 43 vis 1; +#X obj 72 230 s pd-write-reference-popup\$0; +#X msg 72 205 vis 0; +#X obj 143 180 delay 200; +#X msg 51 315 write -wave -bytes 4 \$1 \$2-system-under-test; +#N canvas 528 482 203 281 index0-511 0; +#X obj 41 49 inlet; +#X obj 41 224 outlet; +#X obj 41 139 until; +#X msg 41 107 512; +#X obj 41 169 f; +#X obj 72 169 + 1; +#X obj 41 79 t b b; +#X msg 80 139 0; +#X connect 0 0 6 0; +#X connect 2 0 4 0; +#X connect 3 0 2 0; +#X connect 4 0 5 0; +#X connect 4 0 1 0; +#X connect 5 0 4 1; +#X connect 6 0 3 0; +#X connect 6 1 7 0; +#X connect 7 0 4 1; +#X restore 51 411 pd index0-511; +#X obj 70 476 tabread \$0-system-under-test; +#X obj 70 511 tabwrite \$0-reference; +#X obj 51 535 == 511; +#X obj 51 443 t f f f; +#X obj 51 559 sel 1; +#X connect 0 0 3 0; +#X connect 0 0 8 0; +#X connect 1 0 21 0; +#X connect 2 0 17 0; +#X connect 4 0 1 1; +#X connect 6 0 1 0; +#X connect 6 0 10 0; +#X connect 7 0 20 0; +#X connect 8 0 22 0; +#X connect 10 0 19 0; +#X connect 11 0 12 0; +#X connect 12 0 13 0; +#X connect 13 0 14 0; +#X connect 17 0 16 0; +#X connect 19 0 18 0; +#X connect 20 0 19 0; +#X connect 21 0 0 0; +#X connect 22 0 26 0; +#X connect 23 0 24 0; +#X connect 25 0 27 0; +#X connect 26 0 25 0; +#X connect 26 1 23 0; +#X connect 26 2 24 1; +#X connect 27 0 9 0; +#X restore 40 208 pd write-reference; +#N canvas 739 28 261 427 test-result-messages 0; +#X obj 32 23 inlet; +#X obj 59 310 stdout; +#X obj 32 84 sel 0; +#X obj 89 166 r \$0-refname; +#X obj 89 193 symbol; +#X obj 32 56 moses 1e-05; +#X obj 32 277 t b a; +#X msg 32 336 UNIT-TEST-DONE; +#X obj 32 373 stdout; +#X obj 32 221 pack s f s; +#X obj 112 309 print unit-test; +#X obj 85 373 print unit-test; +#X obj 32 249 list trim; +#X msg 59 113 STDDEV-SMALL \$1; +#X msg 32 141 STDDEV-ZERO 0; +#X msg 95 84 STDDEV-LARGE \$1; +#N canvas 49 312 252 304 stddev-label 0; +#X obj 40 29 inlet; +#X obj 40 92 sel 0; +#X obj 40 64 moses 1e-05; +#X msg 103 92 STDDEV-LARGE; +#X msg 67 121 STDDEV-SMALL; +#X msg 40 149 STDDEV-ZERO; +#X msg 40 221 label \$1; +#X obj 40 191 symbol; +#X obj 40 250 s \$0-stddev-label; +#X connect 0 0 2 0; +#X connect 1 0 5 0; +#X connect 1 1 4 0; +#X connect 2 0 1 0; +#X connect 2 1 3 0; +#X connect 3 0 7 0; +#X connect 4 0 7 0; +#X connect 5 0 7 0; +#X connect 6 0 8 0; +#X connect 7 0 6 0; +#X restore 126 50 pd stddev-label; +#X connect 0 0 5 0; +#X connect 0 0 16 0; +#X connect 2 0 14 0; +#X connect 2 1 13 0; +#X connect 3 0 4 0; +#X connect 4 0 9 2; +#X connect 5 0 2 0; +#X connect 5 1 15 0; +#X connect 6 0 7 0; +#X connect 6 1 1 0; +#X connect 6 1 10 0; +#X connect 7 0 8 0; +#X connect 7 0 11 0; +#X connect 9 0 12 0; +#X connect 12 0 6 0; +#X connect 13 0 9 0; +#X connect 14 0 9 0; +#X connect 15 0 9 0; +#X restore 327 164 pd test-result-messages; +#X floatatom 203 247 5 0 0 0 - #0-test-delay -; +#X text 201 269 delay; +#N canvas 628 152 504 542 list-drip 0; +#X obj 68 94 t a a; +#X obj 68 251 spigot; +#X obj 101 159 bang; +#X obj 101 185 1; +#X obj 207 160 route bang; +#X obj 170 160 bang; +#X obj 170 186 0; +#X obj 101 124 list split 2; +#X obj 134 348 list split; +#X obj 191 297 list length; +#X obj 191 319 >> 1; +#X obj 68 280 t a a a a; +#X obj 68 439 list split; +#X obj 125 391 list length; +#X obj 125 416 >> 1; +#X obj 41 29 inlet; +#X obj 264 186 outlet; +#X text 83 29 Copyright 2009 by Mathieu Bouchard; +#X obj 41 63 t b a; +#X obj 328 80 outlet; +#X text 383 82 signal end of list; +#X text 35 502 made compatible with [list-drip]: fbar 2009; +#X connect 0 0 1 0; +#X connect 0 1 7 0; +#X connect 1 0 11 0; +#X connect 2 0 3 0; +#X connect 3 0 1 1; +#X connect 4 1 16 0; +#X connect 5 0 6 0; +#X connect 6 0 1 1; +#X connect 7 0 2 0; +#X connect 7 2 4 0; +#X connect 7 2 5 0; +#X connect 8 0 0 0; +#X connect 9 0 10 0; +#X connect 10 0 8 1; +#X connect 11 0 12 0; +#X connect 11 1 13 0; +#X connect 11 2 8 0; +#X connect 11 3 9 0; +#X connect 12 1 0 0; +#X connect 13 0 14 0; +#X connect 14 0 12 1; +#X connect 15 0 18 0; +#X connect 18 0 19 0; +#X connect 18 1 0 0; +#X restore 328 52 pd list-drip; +#X obj 257 555 s \$0-test-prepare; +#X obj 256 208 r \$0-do-test; +#N canvas 716 407 203 281 index0-511 0; +#X obj 41 49 inlet; +#X obj 41 224 outlet; +#X obj 41 139 until; +#X msg 41 107 512; +#X obj 41 169 f; +#X obj 72 169 + 1; +#X obj 41 79 t b b; +#X msg 80 139 0; +#X connect 0 0 6 0; +#X connect 2 0 4 0; +#X connect 3 0 2 0; +#X connect 4 0 5 0; +#X connect 4 0 1 0; +#X connect 5 0 4 1; +#X connect 6 0 3 0; +#X connect 6 1 7 0; +#X connect 7 0 4 1; +#X restore 335 605 pd index0-511; +#X obj 43 371 hsl 195 100 0 127 0 0 empty empty empty -2 -8 0 10 -203904 +-203904 -1 0 1; +#N canvas 0 22 450 300 (subpatch) 0; +#X array \$0-reference 512 float 0; +#X coords 0 1 511 -1 200 100 1; +#X restore 40 371 graph; +#X obj 473 371 hsl 195 100 0 127 0 0 empty empty empty -2 -8 0 10 -203904 +-203904 -1 0 1; +#N canvas 0 22 450 300 (subpatch) 0; +#X array \$0-difference 512 float 0; +#X coords 0 1 511 -1 200 100 1; +#X restore 470 371 graph; +#X obj 258 371 hsl 195 100 0 127 0 0 empty empty empty -2 -8 0 10 -203904 +-203904 -1 0 1; +#N canvas 0 22 450 300 (subpatch) 0; +#X array \$0-system-under-test 512 float 0; +#X coords 0 1 511 -1 200 100 1; +#X restore 255 371 graph; +#X obj 256 239 bng 50 250 50 0 \$0-dummysend \$0-dummyreceive empty +17 7 0 10 -203904 -204786 -203904; +#X obj 256 239 bng 50 1000 50 0 \$0-dummysend \$0-dummyreceive done +7 25 0 14 -203904 -1 -203904; +#X text 588 21 dummy; +#X text 73 23 reference name + delay; +#X text 367 25 floats & lists; +#X text 40 481 test-bang out; +#X text 589 481 test-bang out; +#X text 405 481 index 0 - 511 out; +#X obj 467 237 cnv 15 100 20 empty empty [unit-test-frame] 2 12 0 14 +-262144 -66577 0; +#X msg 540 520 vis 1; +#X obj 540 548 s pd-info-unit-test\$0; +#N canvas 473 125 566 541 info-unit-test\$0 0; +#X text 144 474 STDDEV-ZERO 0; +#X text 144 516 STDDEV-LARGE ; +#X text 144 494 STDDEV-SMALL ; +#X text 296 495 when standard deviation < 1e-05; +#X text 296 516 when standard deviation >= 1e-05; +#X text 296 474 when standard deviation = 0; +#X text 129 46 ------------------------------------------------------------ +; +#X text 127 378 ------------------------------------------------------------ +; +#X text 126 538 ------------------------------------------------------------ +; +#X text 131 808 Katja Vetter & Fred Jan Kraan \, October 2011; +#X text 127 556 The reference file must be in the same directory as +the test. If it is not found when the patch is loaded \, an error is +reported to the Pd window and stdout:; +#X text 122 821 ------------------------------------------------------------ +; +#X text 129 67 1: Test arguments must be sent as a list into the first +inlet:; +#X text 149 606 REFERENCE-FILE-ERROR reference file not found: +; +#X text 128 398 The test is automatically executed when the patch is +loaded \, and can also be started with button 'test'. Difference between +signal under test and reference is graphed \, and standard deviation +is computed. A test result message is sent to the Pd window and stdout: +; +#X text 124 779 ------------------------------------------------------------ +; +#X text 26 19 arguments; +#X obj 29 39 loadbang; +#X obj 32 407 bng 50 250 50 0 empty empty test 5 25 0 14 -260097 -262144 +-1; +#X obj 38 555 bng 50 250 50 0 empty empty write 4 25 0 14 -260097 -262144 +-1; +#X text 124 714 ------------------------------------------------------------ +; +#X obj 29 94 loadbang; +#X text 130 98 - reference name \, matching the name of the test patch +; +#X text 130 22 how to use [unit-test-frame.pd] in unit test patches +; +#X msg 29 66 sqrt 0; +#X msg 29 121 pipe 100; +#X text 130 116 - delaytime between test trigger and test snapshot. +; +#X text 129 137 2: Messages from the object(s) under test must be sent +into the second inlet. Floats and lists are both accepted. When testing +an external object \, consider instantiating it with namespace \, like +[zexy/wrap].; +#X text 127 631 A reference file can be created from the content of +\$0-signal-under-test \, using a Pd which is known to work well (the +latest release). Use button 'write'. The file will have 512 samples +in 32 bit .wav format. Even though the test output is not a signal +\, this is a good format to write.; +#X text 124 733 [unit-test-frame.pd] uses only vanilla Pd classes. +For testing external classes \, consider using namespaces like in [zexy/wrap]. +; +#X text 130 203 Use a bang from one of [unit-test-frame.pd] outlets +to trigger the object(s) when the test starts. Or use the index 0 - +511 outlet to generate a series of output values.; +#X text 131 255 Normalization of the object output (within interval +0 to 1 or -1 to 1) is useful. It gives a good graph and a meaningful +stddev. Also note that large numbers are unprecise. Example: the difference +between 1e+12 in single precision and 1e+12 in double precision is +27968! Try this on:; +#X text 149 345 http://www.h-schmidt.net/FloatApplet/IEEE754.html; +#X connect 17 0 24 0; +#X connect 21 0 25 0; +#X restore 555 165 pd info-unit-test\$0; +#X obj 428 531 s \$0-difference; +#X obj 384 629 outlet; +#X obj 238 577 t b b b b; +#X text 209 481 test-bang out; +#X connect 0 0 30 0; +#X connect 1 0 29 0; +#X connect 2 0 31 0; +#X connect 3 0 55 0; +#X connect 6 0 28 0; +#X connect 7 0 32 0; +#X connect 11 0 33 0; +#X connect 11 0 47 0; +#X connect 14 0 13 0; +#X connect 15 0 25 0; +#X connect 17 0 36 0; +#X connect 22 0 60 0; +#X connect 23 0 24 0; +#X connect 23 0 58 0; +#X connect 25 0 14 0; +#X connect 25 0 12 0; +#X connect 25 0 16 0; +#X connect 25 1 26 0; +#X connect 28 0 22 0; +#X connect 28 1 37 0; +#X connect 28 2 23 0; +#X connect 36 0 27 0; +#X connect 38 0 6 0; +#X connect 39 0 21 0; +#X connect 55 0 56 0; +#X connect 60 0 19 0; +#X connect 60 1 20 0; +#X connect 60 2 39 0; +#X connect 60 3 59 0; +#X coords 0 -1 1 1 650 270 2 30 230; -- cgit v1.2.1