Skip to content

Commit

Permalink
Merge pull request #19 from simatic-ax/add_tests
Browse files Browse the repository at this point in the history
Add tests
  • Loading branch information
sjuergen authored Apr 25, 2023
2 parents 0c51dcf + 16b66f9 commit 4a76632
Show file tree
Hide file tree
Showing 6 changed files with 201 additions and 14 deletions.
2 changes: 1 addition & 1 deletion apax.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ scripts:
- apax load
# Dependencies
devDependencies:
"@ax/sdk": 3.0.12
"@ax/sdk": 3.0.18
"@simatic-ax/snippetscollection": 0.0.15
dependencies:
"@simatic-ax/statemachine": 2.1.1
Expand Down
50 changes: 50 additions & 0 deletions test/TestStateGreen.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
USING Simatic.Ax.IO.Output;
USING Simatic.Ax.IO.Input;
USING Simatic.Ax.SimpleControlModules;
USING ApplicationStateFramwerok;
USING AxUnit;

NAMESPACE MyTest

{TestFixture}
CLASS TestStateGreen
VAR PUBLIC
state : StateGreen;
ls : LightStackRdYeGnBl;
qRd : BinOutput;
qYe : BinOutput;
qGn : BinOutput;
qBl : BinOutput;
END_VAR

METHOD PROTECTED Setup
state.LightStack := REF(ls);
ls.QBlue := qBl;
ls.QGreen := qGn;
ls.QRed := qRd;
ls.QYellow := qYe;
END_METHOD

{Test}
METHOD PUBLIC OnEntry_SwitchOnGreenLamp
THIS.Setup();
state.OnEntry();
Assert.Equal(actual := ls.GetState(Colors#Red), expected := FALSE);
Assert.Equal(actual := ls.GetState(Colors#Yellow), expected := FALSE);
Assert.Equal(actual := ls.GetState(Colors#Green), expected := TRUE);
Assert.Equal(actual := ls.GetState(Colors#Blue), expected := FALSE);
END_METHOD

{Test}
METHOD PUBLIC OnEntry_SwitchOffGreenLamp
THIS.OnEntry_SwitchOnGreenLamp();
state.OnExit();
Assert.Equal(actual := ls.GetState(Colors#Red), expected := FALSE);
Assert.Equal(actual := ls.GetState(Colors#Yellow), expected := FALSE);
Assert.Equal(actual := ls.GetState(Colors#Green), expected := FALSE);
Assert.Equal(actual := ls.GetState(Colors#Blue), expected := FALSE);
END_METHOD
END_CLASS

END_NAMESPACE

50 changes: 50 additions & 0 deletions test/TestStateRed.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
USING Simatic.Ax.IO.Output;
USING Simatic.Ax.IO.Input;
USING Simatic.Ax.SimpleControlModules;
USING ApplicationStateFramwerok;
USING AxUnit;

NAMESPACE MyTest

{TestFixture}
CLASS TestStateRed
VAR PUBLIC
state : StateRed;
ls : LightStackRdYeGnBl;
qRd : BinOutput;
qYe : BinOutput;
qGn : BinOutput;
qBl : BinOutput;
END_VAR

METHOD PROTECTED Setup
state.LightStack := REF(ls);
ls.QBlue := qBl;
ls.QGreen := qGn;
ls.QRed := qRd;
ls.QYellow := qYe;
END_METHOD

{Test}
METHOD PUBLIC OnEntry_SwitchOnGreenLamp
THIS.Setup();
state.OnEntry();
Assert.Equal(actual := ls.GetState(Colors#Red), expected := TRUE);
Assert.Equal(actual := ls.GetState(Colors#Yellow), expected := FALSE);
Assert.Equal(actual := ls.GetState(Colors#Green), expected := FALSE);
Assert.Equal(actual := ls.GetState(Colors#Blue), expected := FALSE);
END_METHOD

{Test}
METHOD PUBLIC OnEntry_SwitchOffGreenLamp
THIS.OnEntry_SwitchOnGreenLamp();
state.OnExit();
Assert.Equal(actual := ls.GetState(Colors#Red), expected := FALSE);
Assert.Equal(actual := ls.GetState(Colors#Yellow), expected := FALSE);
Assert.Equal(actual := ls.GetState(Colors#Green), expected := FALSE);
Assert.Equal(actual := ls.GetState(Colors#Blue), expected := FALSE);
END_METHOD
END_CLASS

END_NAMESPACE

50 changes: 50 additions & 0 deletions test/TestStateRedYellow.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
USING Simatic.Ax.IO.Output;
USING Simatic.Ax.IO.Input;
USING Simatic.Ax.SimpleControlModules;
USING ApplicationStateFramwerok;
USING AxUnit;

NAMESPACE MyTest

{TestFixture}
CLASS TestStateRedYellow
VAR PUBLIC
state : StateRedYellow;
ls : LightStackRdYeGnBl;
qRd : BinOutput;
qYe : BinOutput;
qGn : BinOutput;
qBl : BinOutput;
END_VAR

METHOD PROTECTED Setup
state.LightStack := REF(ls);
ls.QBlue := qBl;
ls.QGreen := qGn;
ls.QRed := qRd;
ls.QYellow := qYe;
END_METHOD

{Test}
METHOD PUBLIC OnEntry_SwitchOnGreenLamp
THIS.Setup();
state.OnEntry();
Assert.Equal(actual := ls.GetState(Colors#Red), expected := TRUE);
Assert.Equal(actual := ls.GetState(Colors#Yellow), expected := TRUE);
Assert.Equal(actual := ls.GetState(Colors#Green), expected := FALSE);
Assert.Equal(actual := ls.GetState(Colors#Blue), expected := FALSE);
END_METHOD

{Test}
METHOD PUBLIC OnEntry_SwitchOffGreenLamp
THIS.OnEntry_SwitchOnGreenLamp();
state.OnExit();
Assert.Equal(actual := ls.GetState(Colors#Red), expected := FALSE);
Assert.Equal(actual := ls.GetState(Colors#Yellow), expected := FALSE);
Assert.Equal(actual := ls.GetState(Colors#Green), expected := FALSE);
Assert.Equal(actual := ls.GetState(Colors#Blue), expected := FALSE);
END_METHOD
END_CLASS

END_NAMESPACE

50 changes: 50 additions & 0 deletions test/TestStateYellow.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
USING Simatic.Ax.IO.Output;
USING Simatic.Ax.IO.Input;
USING Simatic.Ax.SimpleControlModules;
USING ApplicationStateFramwerok;
USING AxUnit;

NAMESPACE MyTest

{TestFixture}
CLASS TestStateYellow
VAR PUBLIC
state : StateYellow;
ls : LightStackRdYeGnBl;
qRd : BinOutput;
qYe : BinOutput;
qGn : BinOutput;
qBl : BinOutput;
END_VAR

METHOD PROTECTED Setup
state.LightStack := REF(ls);
ls.QBlue := qBl;
ls.QGreen := qGn;
ls.QRed := qRd;
ls.QYellow := qYe;
END_METHOD

{Test}
METHOD PUBLIC OnEntry_SwitchOnGreenLamp
THIS.Setup();
state.OnEntry();
Assert.Equal(actual := ls.GetState(Colors#Red), expected := FALSE);
Assert.Equal(actual := ls.GetState(Colors#Yellow), expected := TRUE);
Assert.Equal(actual := ls.GetState(Colors#Green), expected := FALSE);
Assert.Equal(actual := ls.GetState(Colors#Blue), expected := FALSE);
END_METHOD

{Test}
METHOD PUBLIC OnEntry_SwitchOffGreenLamp
THIS.OnEntry_SwitchOnGreenLamp();
state.OnExit();
Assert.Equal(actual := ls.GetState(Colors#Red), expected := FALSE);
Assert.Equal(actual := ls.GetState(Colors#Yellow), expected := FALSE);
Assert.Equal(actual := ls.GetState(Colors#Green), expected := FALSE);
Assert.Equal(actual := ls.GetState(Colors#Blue), expected := FALSE);
END_METHOD
END_CLASS

END_NAMESPACE

13 changes: 0 additions & 13 deletions test/test.st

This file was deleted.

0 comments on commit 4a76632

Please sign in to comment.