Commit 26ace300 authored by Jonathan Wilkes's avatar Jonathan Wilkes
Browse files

make [log] a binop and add tests

parent 8a840a2f
......@@ -620,19 +620,30 @@ static void sqrt_float(t_object *x, t_float f)
outlet_float(x->ob_outlet, r);
}
static t_class *log_class; /* ----------- log --------------- */
/* --------------------- log ------------------------------- */
static void *log_new(void)
static t_class *binop1_log_class;
static void *binop1_log_new(t_floatarg f)
{
t_object *x = (t_object *)pd_new(log_class);
outlet_new(x, &s_float);
return (x);
return (binop1_new(binop1_log_class, f));
}
static void log_float(t_object *x, t_float f)
static void binop1_log_bang(t_binop *x)
{
t_float r = (f > 0 ? LOG(f) : -1000);
outlet_float(x->ob_outlet, r);
t_float r;
if (x->x_f1 <= 0)
r = -1000;
else if (x->x_f2 <= 0)
r = LOG(x->x_f1);
else r = LOG(x->x_f1)/LOG(x->x_f2);
outlet_float(x->x_obj.ob_outlet, r);
}
static void binop1_log_float(t_binop *x, t_float f)
{
x->x_f1 = f;
binop1_log_bang(x);
}
static t_class *exp_class; /* ----------- exp --------------- */
......@@ -775,6 +786,12 @@ void x_arithmetic_setup(void)
class_addbang(binop1_min_class, binop1_min_bang);
class_addfloat(binop1_min_class, (t_method)binop1_min_float);
binop1_log_class = class_new(gensym("log"),
(t_newmethod)binop1_log_new, 0,
sizeof(t_binop), 0, A_DEFFLOAT, 0);
class_addbang(binop1_log_class, binop1_log_bang);
class_addfloat(binop1_log_class, (t_method)binop1_log_float);
/* ------------------ binop2 ----------------------- */
binop2_ee_class = class_new(gensym("=="), (t_newmethod)binop2_ee_new, 0,
......@@ -895,10 +912,6 @@ void x_arithmetic_setup(void)
sizeof(t_object), 0, 0);
class_addfloat(sqrt_class, (t_method)sqrt_float);
log_class = class_new(gensym("log"), log_new, 0,
sizeof(t_object), 0, 0);
class_addfloat(log_class, (t_method)log_float);
exp_class = class_new(gensym("exp"), exp_new, 0,
sizeof(t_object), 0, 0);
class_addfloat(exp_class, (t_method)exp_float);
......
#N canvas 372 60 749 617 12;
#X obj 345 301 r \$0-result;
#X obj 345 326 route 0;
#X obj 453 470 print failure;
#X obj 430 336 tgl 28 0 empty empty Print_All_Results 31 11 0 12 -262144
-1 -1 1 1;
#N canvas 265 60 749 617 12;
#X obj 365 291 r \$0-result;
#X obj 365 316 route 0;
#X obj 473 460 print failure;
#X obj 450 326 tgl 28 0 empty empty Print_All_Results 31 11 0 12 -262144
-1 -1 0 1;
#X obj 159 149 bng 31 250 50 0 empty empty Run_all 39 13 0 12 -262144
-1 -1;
#X obj 56 25 r init;
#X obj 345 191 route dollarzero;
#X obj 345 411 t b a;
#X obj 345 541 s pd;
#X obj 365 401 t b a;
#X obj 365 531 s pd;
#X obj 56 120 trigger bang bang anything;
#X msg 56 145 gui;
#X obj 56 170 pdinfo;
#X obj 56 195 sel 0;
#X obj 56 245 s pd;
#X msg 345 516 quit 1;
#X msg 365 506 quit 1;
#X msg 56 220 quit;
#X obj 145 191 rtest msg_dollarzero;
#X obj 145 246 rtest msg_dollarzero_semi;
#X obj 145 302 rtest msg_click;
#X obj 345 216 rtest binbuf_dollarzero;
#X msg 345 440 gui;
#X obj 345 465 pdinfo;
#X obj 345 490 sel 0;
#X msg 365 430 gui;
#X obj 365 455 pdinfo;
#X obj 365 480 sel 0;
#X text 117 25 <- we start Pd with the -send "init etc." flag. This
will automatically start the tests and allow us to send a comma-separated
list of messages which will be evaluated by Pd without a target. This
......@@ -34,10 +34,11 @@ is handy for some binbuf tests.;
#X text 536 150 <- we have to escape the arg;
#X text 556 190 escape it in a comment.;
#X text 556 170 in bash but we can't;
#X obj 391 374 spigot;
#X obj 407 440 route 1;
#X obj 407 495 print success;
#X obj 411 364 spigot;
#X obj 427 430 route 1;
#X obj 427 485 print success;
#X obj 145 353 rtest pow_0.49_compatibility;
#X obj 145 404 rtest log_0.49_compatibility;
#X connect 0 0 1 0;
#X connect 1 0 7 0;
#X connect 1 1 29 0;
......@@ -64,3 +65,4 @@ is handy for some binbuf tests.;
#X connect 29 0 7 0;
#X connect 30 0 31 0;
#X connect 30 1 2 0;
#X connect 32 0 33 0;
#N canvas 618 89 534 502 12;
#X obj 46 21 inlet;
#X obj 46 263 r \$0-test;
#X obj 46 290 list split 3;
#X obj 46 315 unpack 0 0 0;
#X obj 46 378 ==;
#X obj 46 407 list append;
#X obj 46 432 outlet;
#X obj 46 46 t b b;
#X obj 78 152 send pd;
#X msg 78 127 compatibility 0.49;
#X obj 46 347 log;
#X text 99 21 Code coverage test for compatibility with the 0.49 Vanilla
log behavior. We use the "compatibility" message to set compatibility
to 0.49. Our testing framework makes sure to set compatibility back
to the recent version. We might want to generalize this test for more
tilde unit tests later...;
#X msg 46 180 \; \$0-test 0 2 -1000 bash variable of zero or less to
-1000 \; \$0-test 8 2 3 standard positive variable and base \; \$0-test
1 0 0 natural log;
#X connect 0 0 7 0;
#X connect 1 0 2 0;
#X connect 2 0 3 0;
#X connect 2 1 5 1;
#X connect 3 0 10 0;
#X connect 3 1 10 1;
#X connect 3 2 4 1;
#X connect 4 0 5 0;
#X connect 5 0 6 0;
#X connect 7 0 12 0;
#X connect 7 1 9 0;
#X connect 9 0 8 0;
#X connect 10 0 4 0;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment