Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4 show iec st instead of smalltalk #7

Merged
merged 3 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
81 changes: 81 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
10 changes: 0 additions & 10 deletions TESTS.md

This file was deleted.

5 changes: 5 additions & 0 deletions apax-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -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=="
}
}
4 changes: 2 additions & 2 deletions apax.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ author: Siemens AG
type: lib
variables:
APAX_BUILD_ARGS:
- '--log Debug'
- --debug
GITHUB_REG_URL: "https://npm.pkg.github.com"
targets:
- '1500'
- 'axunit-llvm'
devDependencies:
'@ax/sdk': 3.0.18
'@simatic-ax/snippetscollection': 0.1.3
registries:
'@simatic-ax': 'https://npm.pkg.github.com'
files:
Expand All @@ -20,4 +20,4 @@ files:
- 'changelog.md'
- 'doc/'
- 'src/' # ship library with source
# - 'bin/1500/' # ship library with binary

56 changes: 56 additions & 0 deletions test/List/Example.st
Original file line number Diff line number Diff line change
@@ -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