Skip to content

Commit

Permalink
better tests
Browse files Browse the repository at this point in the history
  • Loading branch information
micsthepick committed Feb 27, 2024
1 parent 056e396 commit fe8c0ff
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 41 deletions.
37 changes: 33 additions & 4 deletions testing_defines.eel2
Original file line number Diff line number Diff line change
@@ -1,15 +1,44 @@
// Helper functions to check for positive infinity, negative infinity, and nan
function is_pos_inf(x) (x == 1/0);
function is_neg_inf(x) (x == -1/0);
function is_nan(x) (x != x;);

function assert_equal_exact(expected, actual, message) global() (
(expected !== actual) ? printf("expected: %d, was: %d. %s\n", expected, actual, message)
is_nan(expected) && is_nan(actual) ? 0 :
(is_pos_inf(expected) && is_pos_inf(actual)) || (is_neg_inf(expected) && is_neg_inf(actual)) ? 0 :
expected !== actual ? (
printf("expected: %g, was: %g. %s\n", expected, actual, message)
) : 0;
);

function assert_equal_exact(expected, actual) global() (
assert_equal_exact(expected, actual, "values differ!")
assert_equal_exact(expected, actual, "values differ!")
);

function assert_near_equal(expected, tolerance, actual, message) global() (
is_nan(expected) || is_nan(actual) || is_nan(tolerance) ? 0 :
(is_pos_inf(expected) || is_neg_inf(expected)) && (is_pos_inf(actual) || is_neg_inf(actual)) ? 0 :
abs(expected - actual) > tolerance ? (
printf("expected: %g (±%g), was: %g. %s\n", expected, tolerance, actual, message)
) : 0;
);

function assert_near_equal(expected, tolerance, actual) (
assert_near_equal(expected, tolerance, actual, "values are not equal within tolerance!");
);

function assert_true(boolean, message) global() (
(!boolean) ? printf("expected true, was false. %s\n", message)
(!boolean) ? printf("expected: true, was: false. %s\n", message)
);

function assert_false(boolean, message) global() (
boolean ? printf("expected false, was true. %s\n", message)
boolean ? printf("expected: false, was: true. %s\n", message)
);

function assert_true(boolean) global() (
assert_true(boolean, "");
);

function assert_false(boolean) global() (
assert_false(boolean, "");
);
96 changes: 59 additions & 37 deletions vocalrediso-jamesdsp.eel
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ function setup_stft_state(fft_size, first_time) (
memset(fft_buffer, 0, MAX_FFT_SIZE*2);
memset(output_buffer, 0, buffer_length*2);
memset(input_buffer, 0, buffer_length*2);
buffer_index = 0;
////////////////////////
);

Expand Down Expand Up @@ -302,75 +303,96 @@ buffer_index = (buffer_index + 1)%buffer_length;
//IFTEST ); // function sample_code() (


/*IFTEST{* // main test block
//DEBUGPRINT("SETUP: dry=100 wet=100\n");
///*IFTEST{* // main test block

// helpers
function sum_first_pdc_samples(s0val, s1val) (
setup_stft_state(fft_size, 1);
spl0sum = 0;
spl1sum = 0;
loop(pdc_delay,
spl0=s0val;
spl1=s1val;
sample_code();
spl0sum += abs(spl0);
spl1sum += abs(spl1);
);
);

//DEBUGPRINT("SETUP: fft range is [0, srate] dry=100 wet=100\n");
slider1 = slider2 = 100;
slider5 = 0;
slider6 = srate;
slider_code();

//DEBUGPRINT("Test 1:SAMPLE_0_0_TEST\n");
// spl0=0 spl1=1 for buffer_length*2 samples
setup_stft_state(fft_size, 1);
spl0sum = 0;
spl1sum = 0;
loop(10,
//DEBUGPRINT("SAMPLE_0_0_TEST\n");
// spl0=0 spl1=0 for buffer_length*2 samples
sum_first_pdc_samples(0, 0);
assert_equal_exact(0, spl0sum, "spl0sum for init");
assert_equal_exact(0, spl1sum, "spl1sum for init");

loop(100,
spl0=0;
spl1=0;
sample_code();
spl0sum += abs(spl0);
spl1sum += abs(spl1);
);
assert_near_equal(0, 0.001, spl0sum, "SAMPLE_0_0_TEST: spl0sum was not as expected");
assert_near_equal(0, 0.001, spl1sum, "SAMPLE_0_0_TEST: spl1sum was not as expected");
//DEBUGPRINT("spl0sum=%g, spl1sum=%g\n", spl0sum, spl1sum);

//DEBUGPRINT("SAMPLE_0_0_TEST\n");
//DEBUGPRINT("SAMPLE_1_0_TEST\n");
// spl0=1 spl1=0 for buffer_length*2 samples
setup_stft_state(fft_size, 1);
spl0sum = 0;
spl1sum = 0;
loop(10,
sum_first_pdc_samples(1, 0);
assert_equal_exact(0, spl0sum, "spl0sum for init");
assert_equal_exact(0, spl1sum, "spl1sum for init");

loop(100,
spl0=1;
spl1=0;
sample_code();
spl0sum += 1000000*abs(spl1);
spl1sum += 1000000*abs(spl0);
spl0sum += abs(spl0);
spl1sum += abs(spl1);
);
assert_near_equal(100, 0.001, spl0sum, "SAMPLE_1_0_TEST: spl0sum was not as expected");
assert_near_equal(0, 0.001, spl1sum, "SAMPLE_1_0_TEST: spl1sum was not as expected");
//DEBUGPRINT("spl0sum=%g, spl1sum=%g\n", spl0sum, spl1sum);


//DEBUGPRINT("SAMPLE_0_1_TEST\n");
// spl0=0 spl1=1 for buffer_length*2 samples
setup_stft_state(fft_size, 1);
spl0sum = 0;
spl1sum = 0;
loop(buffer_length*8,
sum_first_pdc_samples(0, 1);
assert_equal_exact(0, spl0sum, "spl0sum for init");
assert_equal_exact(0, spl1sum, "spl1sum for init");

loop(100,
spl0=0;
spl1=1;
sample_code();
spl0sum += 1000000*abs(spl0);
spl1sum += 1000000*abs(spl1);
spl0sum += abs(spl0);
spl1sum += abs(spl1);
);
assert_near_equal(0, 0.001, spl0sum, "SAMPLE_0_1_TEST: spl0sum was not as expected");
assert_near_equal(100, 0.001, spl1sum, "SAMPLE_0_1_TEST: spl1sum was not as expected");
//DEBUGPRINT("spl0sum=%g, spl1sum=%g\n", spl0sum, spl1sum);

//DEBUGPRINT("SAMPLE_1_1_TEST\n");
// spl0=1 spl1=0 for buffer_length*2 samples
setup_stft_state(fft_size, 1);
/*IFTEST{*
spl0sum = 0;
spl1sum = 0;
loop(buffer_length*8,
spl0=0;
// spl0=1 spl1=1 for buffer_length*2 samples
sum_first_pdc_samples(1, 1);
assert_equal_exact(0, spl0sum, "spl0sum for init");
assert_equal_exact(0, spl1sum, "spl1sum for init");

loop(100,
spl0=1;
spl1=1;
sample_code();
spl0sum += 1000000*abs(spl1);
spl1sum += 1000000*abs(spl0);
spl0sum += abs(spl0);
spl1sum += abs(spl1);
);
assert_near_equal(200, 0.001, spl0sum, "SAMPLE_1_1_TEST: spl0sum was not as expected");
assert_near_equal(200, 0.001, spl1sum, "SAMPLE_1_1_TEST: spl1sum was not as expected");
//DEBUGPRINT("spl0sum=%g, spl1sum=%g\n", spl0sum, spl1sum);

//DEBUGPRINT("Testing Completed Without Crashing!\n");

function exit(code) (
code|0;
);

atexit("exit(-1)");

*}IFTEST*/ // main test block

0 comments on commit fe8c0ff

Please sign in to comment.