From fcf7c52509d4661edf0c72de3155f7c2bcc4fc11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Seidel?= Date: Fri, 26 May 2023 00:24:56 +0200 Subject: [PATCH 1/3] add example + doc --- .vscode/launch.json | 15 ++++++++ README.md | 81 ++++++++++++++++++++++++++++++++++++++++++++ TESTS.md | 10 ------ apax-lock.json | 5 +++ apax.yml | 4 +-- test/List/Example.st | 56 ++++++++++++++++++++++++++++++ 6 files changed, 159 insertions(+), 12 deletions(-) create mode 100644 .vscode/launch.json delete mode 100644 TESTS.md create mode 100644 test/List/Example.st 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..c1653e7 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 ListItem + CLASS MinMaxItem + EXTENDS ListItem + VAR PUBLIC + Min : INT; + Max : INT; + END_VAR + END_CLASS + + // Example of another 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 whicg 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..05bf16c --- /dev/null +++ b/test/List/Example.st @@ -0,0 +1,56 @@ +USING AxUnit.Assert; + +NAMESPACE Simatic.Ax.Collections + + // Example of a ListItem + CLASS MinMaxItem + EXTENDS ListItem + VAR PUBLIC + Min : INT; + Max : INT; + END_VAR + END_CLASS + + // Example of another 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 whicg 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 From 44d7f7f75575e83ebb32a6cef2298e886c7bc90c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Seidel?= Date: Fri, 26 May 2023 00:27:03 +0200 Subject: [PATCH 2/3] fix example --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c1653e7..7a6c5ad 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ USING AxUnit.Assert; NAMESPACE Simatic.Ax.Collections - // Example of a ListItem + // Example of a concrete customized ListItem CLASS MinMaxItem EXTENDS ListItem VAR PUBLIC @@ -59,7 +59,7 @@ NAMESPACE Simatic.Ax.Collections END_VAR END_CLASS - // Example of another ListItem + // Example of a concrete customized ListItem CLASS RangeItem EXTENDS ListItem VAR PUBLIC @@ -74,7 +74,7 @@ NAMESPACE Simatic.Ax.Collections _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 whicg is not of type MinMaxItem + _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. From 834c8c3b97dc7c9d727ed50bd366ae6946e124ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Seidel?= Date: Fri, 26 May 2023 00:28:03 +0200 Subject: [PATCH 3/3] doc to example --- test/List/Example.st | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/List/Example.st b/test/List/Example.st index 05bf16c..a445bb8 100644 --- a/test/List/Example.st +++ b/test/List/Example.st @@ -2,7 +2,7 @@ USING AxUnit.Assert; NAMESPACE Simatic.Ax.Collections - // Example of a ListItem + // Example of a concrete customized ListItem CLASS MinMaxItem EXTENDS ListItem VAR PUBLIC @@ -11,7 +11,7 @@ NAMESPACE Simatic.Ax.Collections END_VAR END_CLASS - // Example of another ListItem + // Example of a concrete customized ListItem CLASS RangeItem EXTENDS ListItem VAR PUBLIC @@ -26,7 +26,7 @@ NAMESPACE Simatic.Ax.Collections _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 whicg is not of type MinMaxItem + _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. @@ -53,4 +53,4 @@ NAMESPACE Simatic.Ax.Collections END_METHOD END_CLASS -END_NAMESPACE +END_NAMESPACE \ No newline at end of file