Skip to content
LIBRARY
Sources.Tests.IntegerConstant.md

Sources.Tests.IntegerConstant

Test that validates the IntegerConstant source.

A constant Integer source is converted to Real via IntegerToReal so the constant output can be snapshotted as a trajectory. Two cases cover a positive and a negative constant:

  • case1: k = 5, so toReal.y = 5.0 for the whole simulation.

  • case2: k = -3, so toReal.y = -3.0 for the whole simulation.

Usage

BlockComponents.Sources.Tests.IntegerConstant()

Behavior

Source

dyad
"""
Test that validates the IntegerConstant source.

A constant Integer source is converted to Real via `IntegerToReal` so the
constant output can be snapshotted as a trajectory. Two cases cover a positive
and a negative constant:
- `case1`: `k = 5`, so `toReal.y = 5.0` for the whole simulation.
- `case2`: `k = -3`, so `toReal.y = -3.0` for the whole simulation.
"""
test component IntegerConstant
  "Constant Integer source"
  source = BlockComponents.Sources.IntegerConstant(k = 5) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 20, "x2": 120, "y2": 120, "rot": 0}
      }
    }
  }
  "Converts the Integer output to Real"
  toReal = BlockComponents.Math.IntegerToReal() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 155, "y1": 20, "x2": 255, "y2": 120, "rot": 0}
      }
    }
  }
relations
  "Connects the constant Integer output to the converter"
  connect(source.y, toReal.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
metadata {
  "Dyad": {
    "icons": {"default": "dyad://BlockComponents/Example.svg"},
    "tests": {
      "case1": {"stop": 1, "expect": {"signals": ["toReal.y"]}},
      "case2": {"stop": 1, "params": {"source.k": -3}, "expect": {"signals": ["toReal.y"]}}
    }
  }
}
end
Flattened Source
dyad
"""
Test that validates the IntegerConstant source.

A constant Integer source is converted to Real via `IntegerToReal` so the
constant output can be snapshotted as a trajectory. Two cases cover a positive
and a negative constant:
- `case1`: `k = 5`, so `toReal.y = 5.0` for the whole simulation.
- `case2`: `k = -3`, so `toReal.y = -3.0` for the whole simulation.
"""
test component IntegerConstant
  "Constant Integer source"
  source = BlockComponents.Sources.IntegerConstant(k = 5) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 20, "x2": 120, "y2": 120, "rot": 0}
      }
    }
  }
  "Converts the Integer output to Real"
  toReal = BlockComponents.Math.IntegerToReal() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 155, "y1": 20, "x2": 255, "y2": 120, "rot": 0}
      }
    }
  }
relations
  "Connects the constant Integer output to the converter"
  connect(source.y, toReal.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
metadata {
  "Dyad": {
    "icons": {"default": "dyad://BlockComponents/Example.svg"},
    "tests": {
      "case1": {"stop": 1, "expect": {"signals": ["toReal.y"]}},
      "case2": {"stop": 1, "params": {"source.k": -3}, "expect": {"signals": ["toReal.y"]}}
    }
  }
}
end


Test Cases

Test Case case1

julia
plt

Test Case case2

julia
plt