---
url: /dyad/stable/stdlib/BlockComponents/tests/Sources.Tests.IntegerConstant.md
description: >-
  Dyad Sources.Tests.IntegerConstant docs.  Test that validates the
  IntegerConstant source.
---

# `Sources.Tests.IntegerConstant` {#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 {#Usage}

`BlockComponents.Sources.Tests.IntegerConstant()`

## Behavior {#Behavior}

$$ \begin{align}
0 &= \mathrm{connect}\left( source\_{+}y, toReal\_{+}u \right) \\
\mathtt{source.y}\left( t \right) &= \mathtt{source.k} \\
\mathtt{toReal.y}\left( t \right) &= \mathtt{toReal.u}\left( t \right)
\end{align}
$$

## Source {#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
```

```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-Cases}

### Test Case `case1` {#Test-Case-case1}

```julia
plt
```

![](bbmhozh.svg)

### Test Case `case2` {#Test-Case-case2}

```julia
plt
```

![](tyfwoei.svg)

## Related {#Related}

* Examples

* Experiments

* Analyses

* Tests
  * [`IntegerConstant`](Sources.Tests.IntegerConstant.md)

  * [`IntegerConstant`](Sources.Tests.IntegerConstant.md)

  * [`IntegerToReal`](Sources.Tests.IntegerConstant.md)
