Unexpected CLASSVAR in my unit test

This is my first time writing a unit-test in SC. I have a function which I want to test. When Evaluating the test class, it somehow doesn’t like my classvar decleration, and I have no idea why!

(
~makeQ = {
	var vals = List.new;
	var q = 1;
	var tmp;
	while {
		q.fuzzyEqual(0) <= 0.999
	} {
		tmp = ~get_val_in_rng.(q, [ 0.5, 0.25, 0.125, 0.0625 ]);
		tmp.postln;
		vals.add(tmp);
		q = q - tmp;
	};
	vals
}
)

and here is my test class:

(
TestQ : UnitTest {
	
	classvar units;
	
	*initClass {
		units = Array.fill(10, {var q = ~makeQ.(); q.postln});
	}
	setUp {
		"Setting up test...".postln;
	}
	test_run {
		units.do {
			arg unit;
			this.assertEquals(unit.sum, 1);
		}
	}
};
)

SC interpreter says:

ERROR: Command line parse failed
→ nil
ERROR: syntax error, unexpected CLASSVAR, expecting ‘}’
in interpreted text
line 4 char 9:
classvar units;
^^^^^^^^

Any helps are much appreciated!

Is your test class in the Extensions?
SC doesn’t allow defining classes after the interpreter boots. Also, the external ( ) are not needed in the class definition file.

1 Like