-
Notifications
You must be signed in to change notification settings - Fork 0
/
testLQTerm.m
53 lines (45 loc) · 1.37 KB
/
testLQTerm.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
function tests = testLQTerm
tests = functiontests(localfunctions);
end
function testCreate(tc)
t = LQTerm(1);
verifyEqual(tc, t.c, 1);
verifyEmpty(tc, t.v1);
verifyEmpty(tc, t.v2);
end
function testMultConstant(tc)
t = LQTerm(2) .* 3;
verifyEqual(tc, t.c, 6);
verifyTrue(tc, isConstant(t));
t = (2 .* Variable) .* 3;
verifyEqual(tc, t.c, 6);
verifyTrue(tc, isLinear(t));
t = (2 .* Variable .* Variable) .* 3;
verifyEqual(tc, t.c, 6);
verifyTrue(tc, isQuadratic(t));
end
function testMultLinear(tc)
t = (2 .* Variable) .* (3 .* Variable);
verifyEqual(tc, t.c, 6);
verifyTrue(tc, isQuadratic(t));
end
function testMultQuadratic(tc)
q = Variable .* Variable;
verifyError(tc, @(x) q .* Variable, ...
'SIMPL:LQTerm:nonlinear');
verifyError(tc, @(x) q .* q, ...
'SIMPL:LQTerm:nonlinear');
end
function testToString(tc)
verifyMatches(tc,toString(LQTerm(1)),'1');
verifyMatches(tc,toString(LQTerm(-1)),'-1');
v = Variable('v');
verifyMatches(tc,toString(LQTerm(v)),'v');
verifyMatches(tc,toString(1.*v),'v');
verifyMatches(tc,toString(-1.*v),'-v');
verifyMatches(tc,toString(2.*v),'2*v');
verifyTrue(tc, strcmp(toString(-2.*v),'-2*v'));
verifyMatches(tc,toString(v.*v),'v\^2');
x = Variable('x');
verifyMatches(tc,toString(v.*x),'v\*x');
end