diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..907438c --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "lldb", + "request": "launch", + "name": "Debug ST tests", + "program": "bin/axunit-llvm/tests.exe", + "terminal": "console" + } + ] +} \ No newline at end of file diff --git a/README.md b/README.md index 4d4f61e..7a6c5ad 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,85 @@ Simatic.Ax.Collections; ## Linked List +### Class LinkedList +```mermaid +--- +title: LinkedList Class Diagram +--- +classDiagram + ILinkedList <|-- LinkedList + class ILinkedList{ + +Add(item : IListItem) IListItem + +Remove(item : IListItem) BOOL + } + class LinkedList{ + +Tail() : IListItem + +Head() : IListItem + +Count() : INT + } +``` + + +Example: +```iec-st +USING AxUnit.Assert; + +NAMESPACE Simatic.Ax.Collections + + // Example of a concrete customized ListItem + CLASS MinMaxItem + EXTENDS ListItem + VAR PUBLIC + Min : INT; + Max : INT; + END_VAR + END_CLASS + + // Example of a concrete customized ListItem + CLASS RangeItem + EXTENDS ListItem + VAR PUBLIC + FromValue : INT; + ToValue : INT; + END_VAR + END_CLASS + + {TestFixture} + CLASS Example + VAR PRIVATE + _list : LinkedList; + _i1 : MinMaxItem := (Min := 1, Max := 100); + _i2 : MinMaxItem := (Min := 2, Max := 200); + _i3 : RangeItem := (FromValue := 3, ToValue := 300); // declare a wrong, another list item which is not of type MinMaxItem + _item : REF_TO MinMaxItem; + END_VAR + // Add 2 elements of MinMaxItem and one wrong element RangeItem to the list. + // By reading the tail, the assignment attempt (?=) fails, because RangeItem can not be converted to MinMaxItem + + {Test} + METHOD PUBLIC Test_Add_3_Elements_To_Queue_And_Get_Values_from_first_item + _list.Add(item := _i1); // add i1 to head + _list.Add(item := _i2); + _list.Add(item := _i3); // add _i3, a wrong IListItem to the list (Tail) + _item ?= _list.Tail(); // assignment attempt (?=) --> It's NULL if not of type MinMaxItem + Equal(_item <> NULL, TRUE); + IF (_item <> NULL) THEN + Equal(_item^.Min, 1); + Equal(_item^.Max, 100); + END_IF; + _item ?= _list.Head(); // assignment attempt (?=) --> It's NULL if not of type MinMaxItem + Equal(_item = NULL, TRUE); + IF (_item <> NULL) THEN + NotEqual(_item^.Min, 3); + NotEqual(_item^.Max, 300); + END_IF; + Equal(expected := 3, actual := _list.Count()); + END_METHOD + END_CLASS + +END_NAMESPACE +``` + ### LinkedList.Add() : IListItem Method Add a new object IListItem to the end of the list @@ -61,6 +140,8 @@ END_METHOD |Return Value |Bool |Removing item was successful | |item |IListItem |Reference to item to be removed | + + ## Fifo Represents a first-in, first-out (FIFO) collection of IListItem. diff --git a/TESTS.md b/TESTS.md deleted file mode 100644 index 9d0e30b..0000000 --- a/TESTS.md +++ /dev/null @@ -1,10 +0,0 @@ -# Creating a tests project - -## Preconditions - -1. Create a library project -2. Open a shell in the repo directory - -## Steps for test execution - -`apax test` diff --git a/apax-lock.json b/apax-lock.json index 02eb071..739a892 100644 --- a/apax-lock.json +++ b/apax-lock.json @@ -388,5 +388,10 @@ "version": "10.1.1", "resolved": "https://registry.simatic-ax.siemens.io/@ax/third-party-licenses-build-native/-/third-party-licenses-build-native-10.1.1.tgz", "integrity": "sha512-Da+AT0KujH3K9bKf4K4rqPA3Z+a/WDkw9p6328AlrSqgBIUFyUZzOM3eVOwhhjKCnmNAVSmtSp0r7crDFGICTw==" + }, + "@simatic-ax/snippetscollection": { + "version": "0.1.3", + "resolved": "https://npm.pkg.github.com/download/@simatic-ax/snippetscollection/0.1.3/e287ad803a10c04ed92a9b73eb1b735ca267212f", + "integrity": "sha512-YcuBXUs4VeW60LLdJ/p7p2aCXWxhrzHg4YEmMKtDOLPjL7EWbQT+4RUNoE2PANv7VTX/hr9+iLjR5ahfKp2utA==" } } diff --git a/apax.yml b/apax.yml index 5397c6c..b5799b8 100644 --- a/apax.yml +++ b/apax.yml @@ -4,7 +4,6 @@ author: Siemens AG type: lib variables: APAX_BUILD_ARGS: - - '--log Debug' - --debug GITHUB_REG_URL: "https://npm.pkg.github.com" targets: @@ -12,6 +11,7 @@ targets: - 'axunit-llvm' devDependencies: '@ax/sdk': 3.0.18 + '@simatic-ax/snippetscollection': 0.1.3 registries: '@simatic-ax': 'https://npm.pkg.github.com' files: @@ -20,4 +20,4 @@ files: - 'changelog.md' - 'doc/' - 'src/' # ship library with source - # - 'bin/1500/' # ship library with binary + diff --git a/test/List/Example.st b/test/List/Example.st new file mode 100644 index 0000000..a445bb8 --- /dev/null +++ b/test/List/Example.st @@ -0,0 +1,56 @@ +USING AxUnit.Assert; + +NAMESPACE Simatic.Ax.Collections + + // Example of a concrete customized ListItem + CLASS MinMaxItem + EXTENDS ListItem + VAR PUBLIC + Min : INT; + Max : INT; + END_VAR + END_CLASS + + // Example of a concrete customized ListItem + CLASS RangeItem + EXTENDS ListItem + VAR PUBLIC + FromValue : INT; + ToValue : INT; + END_VAR + END_CLASS + + {TestFixture} + CLASS Example + VAR PRIVATE + _list : LinkedList; + _i1 : MinMaxItem := (Min := 1, Max := 100); + _i2 : MinMaxItem := (Min := 2, Max := 200); + _i3 : RangeItem := (FromValue := 3, ToValue := 300); // declare a wrong, another list item which is not of type MinMaxItem + _item : REF_TO MinMaxItem; + END_VAR + // Add 2 elements of MinMaxItem and one wrong element RangeItem to the list. + // By reading the tail, the assignment attempt (?=) fails, because RangeItem can not be converted to MinMaxItem + + {Test} + METHOD PUBLIC Test_Add_3_Elements_To_Queue_And_Get_Values_from_first_item + _list.Add(item := _i1); // add i1 to head + _list.Add(item := _i2); + _list.Add(item := _i3); // add _i3, a wrong IListItem to the list (Tail) + _item ?= _list.Tail(); // assignment attempt (?=) --> It's NULL if not of type MinMaxItem + Equal(_item <> NULL, TRUE); + IF (_item <> NULL) THEN + Equal(_item^.Min, 1); + Equal(_item^.Max, 100); + END_IF; + _item ?= _list.Head(); // assignment attempt (?=) --> It's NULL if not of type MinMaxItem + Equal(_item = NULL, TRUE); + IF (_item <> NULL) THEN + NotEqual(_item^.Min, 3); + NotEqual(_item^.Max, 300); + END_IF; + Equal(expected := 3, actual := _list.Count()); + END_METHOD + END_CLASS + +END_NAMESPACE \ No newline at end of file