---
url: /dyad/stable/stdlib/BlockComponents/tests/Sources.Tests.BooleanConstant.md
description: >-
  Dyad Sources.Tests.BooleanConstant docs.  Test that validates the
  BooleanConstant source for both output values.
---

# `Sources.Tests.BooleanConstant` {#Sources.Tests.BooleanConstant}

Test that validates the BooleanConstant source for both output values.

Two constant Boolean sources — `k = true` and `k = false` — are each converted to Real via `BooleanToReal` so the constant outputs can be snapshotted as trajectories. Expected: `toReal_true.y = 1.0` and `toReal_false.y = 0.0` for the whole simulation.

## Usage {#Usage}

`BlockComponents.Sources.Tests.BooleanConstant()`

## Behavior {#Behavior}

$$ \begin{align}
0 &= \mathrm{connect}\left( source\_{true\_{+}y}, toReal\_{true\_{+}u} \right) \\
0 &= \mathrm{connect}\left( source\_{false\_{+}y}, toReal\_{false\_{+}u} \right) \\
\mathtt{source_true.y}\left( t \right) &= \mathtt{source_true.k} \\
\mathtt{toReal_true.y}\left( t \right) &= ifelse\left( \mathtt{toReal_true.u}\left( t \right), \mathtt{toReal_true.realTrue}, \mathtt{toReal_true.realFalse} \right) \\
\mathtt{source_false.y}\left( t \right) &= \mathtt{source_false.k} \\
\mathtt{toReal_false.y}\left( t \right) &= ifelse\left( \mathtt{toReal_false.u}\left( t \right), \mathtt{toReal_false.realTrue}, \mathtt{toReal_false.realFalse} \right)
\end{align}
$$

## Source {#Source}

```dyad
"""
Test that validates the BooleanConstant source for both output values.

Two constant Boolean sources — `k = true` and `k = false` — are each converted to
Real via `BooleanToReal` so the constant outputs can be snapshotted as
trajectories. Expected: `toReal_true.y = 1.0` and `toReal_false.y = 0.0` for the
whole simulation.
"""
test component BooleanConstant
  "Constant Boolean source (k = true)"
  source_true = BlockComponents.Sources.BooleanConstant(k = true) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 20, "x2": 120, "y2": 120, "rot": 0}
      }
    }
  }
  "Converts the true Boolean output to Real"
  toReal_true = BlockComponents.Math.BooleanToReal() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 300, "y1": 20, "x2": 400, "y2": 120, "rot": 0}
      }
    }
  }
  "Constant Boolean source (k = false)"
  source_false = BlockComponents.Sources.BooleanConstant(k = false) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 220, "x2": 120, "y2": 320, "rot": 0}
      }
    }
  }
  "Converts the false Boolean output to Real"
  toReal_false = BlockComponents.Math.BooleanToReal() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 300, "y1": 220, "x2": 400, "y2": 320, "rot": 0}
      }
    }
  }
relations
  connect(source_true.y, toReal_true.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(source_false.y, toReal_false.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_true.y", "toReal_false.y"]}}
    }
  }
}
end
```

```dyad
"""
Test that validates the BooleanConstant source for both output values.

Two constant Boolean sources — `k = true` and `k = false` — are each converted to
Real via `BooleanToReal` so the constant outputs can be snapshotted as
trajectories. Expected: `toReal_true.y = 1.0` and `toReal_false.y = 0.0` for the
whole simulation.
"""
test component BooleanConstant
  "Constant Boolean source (k = true)"
  source_true = BlockComponents.Sources.BooleanConstant(k = true) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 20, "x2": 120, "y2": 120, "rot": 0}
      }
    }
  }
  "Converts the true Boolean output to Real"
  toReal_true = BlockComponents.Math.BooleanToReal() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 300, "y1": 20, "x2": 400, "y2": 120, "rot": 0}
      }
    }
  }
  "Constant Boolean source (k = false)"
  source_false = BlockComponents.Sources.BooleanConstant(k = false) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 220, "x2": 120, "y2": 320, "rot": 0}
      }
    }
  }
  "Converts the false Boolean output to Real"
  toReal_false = BlockComponents.Math.BooleanToReal() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 300, "y1": 220, "x2": 400, "y2": 320, "rot": 0}
      }
    }
  }
relations
  connect(source_true.y, toReal_true.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(source_false.y, toReal_false.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_true.y", "toReal_false.y"]}}
    }
  }
}
end
```

## Test Cases {#Test-Cases}

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

```julia
plt
```

![](lgmtcsc.svg)

```julia
plt
```

![](teoezdb.svg)

## Related {#Related}

* Examples

* Experiments

* Analyses

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

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

  * [`BooleanToReal`](Sources.Tests.BooleanConstant.md)
