Skip to content

Commit

Permalink
Updated tests (added some, removed one, simplified w/ extends)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdavies4 committed Jan 25, 2013
1 parent 1a7174f commit 6521fe8
Showing 1 changed file with 77 additions and 47 deletions.
124 changes: 77 additions & 47 deletions XogenyTest.mo
Original file line number Diff line number Diff line change
Expand Up @@ -162,22 +162,19 @@ package XogenyTest
annotation(TestCase(action="simulate", result="success"), experiment(StopTime=4));
end CheckSuccess;

model CheckFailure1
"Check to make sure this fails if first point is before start"
Real x = time;
AssertTrajectory check_x(actual=x, expected=[-1,-1; 1,1; 2,2; 3,3]);
model CheckFailure1 "Check for failure when first point is before start"
extends CheckSuccess(check_x(expected=[-1,1; 0,0; 1,1]));
annotation(TestCase(action="simulate", result="failure"), experiment(StopTime=4));
end CheckFailure1;

model CheckFailure2 "Check to make sure values match during simulation"
Real x = time;
AssertTrajectory check_x(actual=x, expected=[0,0; 1,1; 2,2.5; 3,3]);
model CheckFailure2
"Check for failure when values don't match during simulation"
extends CheckSuccess(x=time);
annotation(TestCase(action="simulate", result="failure"), experiment(StopTime=4));
end CheckFailure2;

model CheckFailure3 "Check to make sure all points are checked"
Real x = time;
AssertTrajectory check_x(actual=x, expected=[0,0; 1,1; 2,2; 8,8]);
model CheckFailure3 "Check for failure when all points aren't checked"
extends CheckSuccess(check_x(expected=[0,0; 1,1; 5,25]));
annotation(TestCase(action="simulate", result="failure"), experiment(StopTime=4));
end CheckFailure3;
end Trajectory;
Expand All @@ -189,86 +186,119 @@ package XogenyTest
annotation(TestCase(action="simulate", result="success"), experiment(StopTime=4));
end CheckSuccess;

model CheckFailure1 "Check case of early transition"
Real x = time;
AssertBecomesTrueAt check_event(event=(x>1), at=2);
annotation(TestCase(action="simulate", result="failure"), experiment(StopTime=4));
model CheckFailure1
"Check for failure when expected transition is before simulation start"
extends CheckSuccess(check_event(at=-1));
annotation(TestCase(action=
"simulate", result="failure"), experiment(StopTime=4));
end CheckFailure1;

model CheckFailure2 "Check for case of late transition"
Real x = time;
AssertBecomesTrueAt check_event(event=(x>3), at=2);
annotation(TestCase(action="simulate", result="success"), experiment(StopTime=4));
model CheckFailure2 "Check for failure when transition is early"
extends CheckSuccess(check_event(event=(x>1)));
annotation(TestCase(
action="simulate", result="failure"), experiment(StopTime=4));
end CheckFailure2;
model CheckFailure3 "Check for failure when transition is late"
extends CheckSuccess(check_event(event=(x > 3)));
annotation (TestCase(action="simulate", result="success"), experiment(
StopTime=4));
end CheckFailure3;

model CheckFailure4
"Check for failure when expected transition is after simulation end"
extends CheckSuccess(check_event(at=5)) annotation (TestCase(action=
"simulate", result="failure"), experiment(StopTime=4));
end CheckFailure4;
end BecomesTrueAt;

package Initial "Tests associated with AssertInitial model"
model CheckSuccess
Real x = 2*time+1;
AssertInitial check_x(actual=x, expected=1);
annotation(TestCase(action="simulate", result="success"), experiment(StopTime=
4));
annotation(TestCase(action="simulate", result="success"));
end CheckSuccess;

model CheckFailure1 "Check to see that the initial check is correct"
Real x = 2*time+1;
AssertInitial check_x(actual=x, expected=2);
annotation(TestCase(action="simulate", result="failure"), experiment(StopTime=4));
model CheckFailure1 "Check for failure when initial value is incorrect"
extends CheckSuccess(x=time);
annotation(TestCase(action="simulate", result="failure"));
end CheckFailure1;
end Initial;

package Final "Tests associated with AssertFinal model"
model CheckSuccess
Real x = 2*time+1;
AssertFinal check_x(actual=x, expected=5);
annotation(TestCase(action="simulate", result="success"), experiment(StopTime=
4));
AssertFinal check_x(actual=x, expected=9);
annotation(TestCase(action="simulate", result="success"), experiment(StopTime=4));
end CheckSuccess;

model CheckFailure1 "Check to see that the initial check is correct"
Real x = 2*time+1;
AssertFinal check_x(actual=x, expected=4);
model CheckFailure1 "Check for failure when final value is incorrect"
extends CheckSuccess(x=time);
annotation(TestCase(action="simulate", result="failure"), experiment(StopTime=4));
end CheckFailure1;
end Final;

package Average "Test the average value between two points in time."
package Average "Tests associated with AssertAverage model"
constant Real pi=3.141592653589793238462643383279502884197169399;

model CheckSuccess "Check for successful value of average"
Real x = sin(2*time);
AssertAverageBetween check_x(average=0,start=0,finish=pi,signal=x,eps=1e-4);
annotation(TestCase(action="simulate", result="success"), experiment(StopTime=
8));
AssertAverageBetween check_x(
average=0,
start=0,
finish=2*pi,
signal=x,
eps=1e-4);
annotation(TestCase(action="simulate", result="success"), experiment(StopTime=8));
end CheckSuccess;

model CheckSuccess2 "Check for a longer interval"
Real x = sin(2*time);
AssertAverageBetween check_x(average=0,start=0,finish=2*pi,signal=x,eps=1e-4);
annotation(TestCase(action="simulate", result="success"), experiment(StopTime=
8));
end CheckSuccess2;

model CheckFailure1
"Check for failure when starting in the middle of the interval"
Real x = sin(2*time);
AssertAverageBetween check_x(average=0,start=-pi,finish=pi,signal=x,eps=1e-4);
extends CheckSuccess(check_x(start=-pi,finish=pi));
annotation(TestCase(action="simulate", result="failure"), experiment(StopTime=8));
end CheckFailure1;

model CheckFailure2
"Check for failure when simulation ends before interval"
Real x = sin(2*time);
AssertAverageBetween check_x(average=0,start=0,finish=3*pi,signal=x,eps=1e-4);
extends CheckSuccess(check_x(start=pi,finish=3*pi));
annotation(TestCase(action="simulate", result="failure"), experiment(StopTime=8));
end CheckFailure2;

model CheckFailure3 "Check for failure when values don't agree"
Real x = sin(2*time);
AssertAverageBetween check_x(average=0,start=0,finish=7*pi/8,signal=x,eps=1e-4);
extends CheckSuccess(check_x(finish=7*pi/8));
annotation(TestCase(action="simulate", result="failure"), experiment(StopTime=8));
end CheckFailure3;
end Average;
package ValueAt "Tests associated with AssertValueAt model"
model CheckSuccess
Real x=2*time + 1;
AssertValueAt check_x(
actual=x,
expected=5,
at=2);
annotation(TestCase(action="simulate", result="success"), experiment(
StopTime=4));
end CheckSuccess;

model CheckFailure1
"Check for failure when value is specified before simulation start"
extends CheckSuccess(check_x(at=-1));
annotation (TestCase(action="simulate", result="failure"), experiment(
StopTime=4));
end CheckFailure1;

model CheckFailure2 "Check for failure when value is incorrect"
extends CheckSuccess(x=time);
annotation (TestCase(action="simulate", result="failure"), experiment(
StopTime=4));
end CheckFailure2;

model CheckFailure3
"Check for failure when value is specified after simulation end"
extends CheckSuccess(check_x(at=5));
annotation (TestCase(action="simulate", result="failure"), experiment(
StopTime=4));
end CheckFailure3;
end ValueAt;
end Tests;

package Features
Expand Down

0 comments on commit 6521fe8

Please sign in to comment.