---
url: /dyad/dev/stdlib/BlockComponents/tests/Math.Tests.IntegerToBoolean.md
description: >-
  Dyad Math.Tests.IntegerToBoolean docs.  Converts constant and time-varying
  Integer signals to Boolean by threshold.
---

# `Math.Tests.IntegerToBoolean` {#Math.Tests.IntegerToBoolean}

Converts constant and time-varying Integer signals to Boolean by threshold.

Chains Constant(2.0) → RealToInteger → IntegerToBoolean(threshold=1) and verifies that the output is true (1) since 2 >= 1. A second chain feeds a sine wave (amplitude 3) through RealToInteger into IntegerToBoolean(threshold=1) so the Integer signal moves across the threshold and the Boolean output toggles.

## Usage {#Usage}

`BlockComponents.Math.Tests.IntegerToBoolean()`

## Behavior {#Behavior}

$$ \begin{align}
0 &= \mathrm{connect}\left( c1\_{+}y, r2i\_{+}u \right) \\
0 &= \mathrm{connect}\left( r2i\_{+}y, i2b\_{+}u \right) \\
0 &= \mathrm{connect}\left( sine\_{+}y, r2i\_{2\_{+}u} \right) \\
0 &= \mathrm{connect}\left( r2i\_{2\_{+}y}, i2b\_{2\_{+}u} \right) \\
\mathtt{c1.y}\left( t \right) &= \mathtt{c1.k} \\
\mathtt{r2i.y}\left( t \right) &= round_int\left( \mathtt{r2i.u}\left( t \right) \right) \\
\mathtt{i2b.y}\left( t \right) &= \mathtt{i2b.u}\left( t \right) \geq \mathtt{i2b.threshold} \\
\mathtt{sine.y}\left( t \right) &= ifelse\left( \mathtt{sine.continuous}, ifelse\left( t \geq \mathtt{sine.start_time}, \sin\left( \mathtt{sine.phase} + 6.2832 ~ \mathtt{sine.frequency} ~ \left(  - \mathtt{sine.shift_time} + t \right) \right), \sin\left( \mathtt{sine.phase} + 6.2832 ~ \mathtt{sine.frequency} ~ \left(  - \mathtt{sine.shift_time} + \mathtt{sine.start_time} \right) \right) \right) ~ \mathtt{sine.amplitude}, ifelse\left( t \geq \mathtt{sine.start_time}, \sin\left( \mathtt{sine.phase} + 6.2832 ~ \mathtt{sine.frequency} ~ \left(  - \mathtt{sine.shift_time} + t \right) \right) ~ \mathtt{sine.amplitude}, 0 \right) \right) + \mathtt{sine.offset} \\
\mathtt{r2i_2.y}\left( t \right) &= round_int\left( \mathtt{r2i_2.u}\left( t \right) \right) \\
\mathtt{i2b_2.y}\left( t \right) &= \mathtt{i2b_2.u}\left( t \right) \geq \mathtt{i2b_2.threshold}
\end{align}
$$

## Source {#Source}

```dyad
"""
Converts constant and time-varying Integer signals to Boolean by threshold.

Chains Constant(2.0) → RealToInteger → IntegerToBoolean(threshold=1) and
verifies that the output is true (1) since 2 >= 1. A second chain feeds a sine
wave (amplitude 3) through RealToInteger into IntegerToBoolean(threshold=1) so
the Integer signal moves across the threshold and the Boolean output toggles.
"""
test component IntegerToBoolean
  "Constant source providing a value that rounds to 2"
  c1 = BlockComponents.Sources.Constant(k = 2.0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 20, "x2": 120, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  "RealToInteger adapter to produce Integer signal"
  r2i = BlockComponents.Math.RealToInteger() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 160, "y1": 20, "x2": 260, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  "IntegerToBoolean block under test"
  i2b = BlockComponents.Math.IntegerToBoolean(threshold = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 310, "y1": 20, "x2": 410, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  "Sine source sweeping across the threshold"
  sine = BlockComponents.Sources.Sine(amplitude = 3, frequency = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 140, "x2": 120, "y2": 240, "rot": 0}
      },
      "tags": []
    }
  }
  "RealToInteger adapter for the second chain"
  r2i_2 = BlockComponents.Math.RealToInteger() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 160, "y1": 140, "x2": 260, "y2": 240, "rot": 0}
      },
      "tags": []
    }
  }
  "Second IntegerToBoolean block driven by the sine chain"
  i2b_2 = BlockComponents.Math.IntegerToBoolean(threshold = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 300, "y1": 140, "x2": 400, "y2": 240, "rot": 0}
      },
      "tags": []
    }
  }
relations
  connect(c1.y, r2i.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(r2i.y, i2b.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(sine.y, r2i_2.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(r2i_2.y, i2b_2.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
metadata {
  "Dyad": {
    "icons": {"default": "dyad://BlockComponents/Example.svg"},
    "tests": {
      "case1": {"stop": 1, "expect": {"signals": ["i2b.y", "i2b_2.y", "r2i_2.y", "sine.y"]}}
    }
  }
}
end
```

```dyad
"""
Converts constant and time-varying Integer signals to Boolean by threshold.

Chains Constant(2.0) → RealToInteger → IntegerToBoolean(threshold=1) and
verifies that the output is true (1) since 2 >= 1. A second chain feeds a sine
wave (amplitude 3) through RealToInteger into IntegerToBoolean(threshold=1) so
the Integer signal moves across the threshold and the Boolean output toggles.
"""
test component IntegerToBoolean
  "Constant source providing a value that rounds to 2"
  c1 = BlockComponents.Sources.Constant(k = 2.0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 20, "x2": 120, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  "RealToInteger adapter to produce Integer signal"
  r2i = BlockComponents.Math.RealToInteger() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 160, "y1": 20, "x2": 260, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  "IntegerToBoolean block under test"
  i2b = BlockComponents.Math.IntegerToBoolean(threshold = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 310, "y1": 20, "x2": 410, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  "Sine source sweeping across the threshold"
  sine = BlockComponents.Sources.Sine(amplitude = 3, frequency = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 140, "x2": 120, "y2": 240, "rot": 0}
      },
      "tags": []
    }
  }
  "RealToInteger adapter for the second chain"
  r2i_2 = BlockComponents.Math.RealToInteger() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 160, "y1": 140, "x2": 260, "y2": 240, "rot": 0}
      },
      "tags": []
    }
  }
  "Second IntegerToBoolean block driven by the sine chain"
  i2b_2 = BlockComponents.Math.IntegerToBoolean(threshold = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 300, "y1": 140, "x2": 400, "y2": 240, "rot": 0}
      },
      "tags": []
    }
  }
relations
  connect(c1.y, r2i.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(r2i.y, i2b.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(sine.y, r2i_2.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(r2i_2.y, i2b_2.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
metadata {
  "Dyad": {
    "icons": {"default": "dyad://BlockComponents/Example.svg"},
    "tests": {
      "case1": {"stop": 1, "expect": {"signals": ["i2b.y", "i2b_2.y", "r2i_2.y", "sine.y"]}}
    }
  }
}
end
```

## Test Cases {#Test-Cases}

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

```julia
plt
```

![](tamrvsa.svg)

```julia
plt
```

![](gchxyzp.svg)

```julia
plt
```

![](sbrhnkc.svg)

```julia
plt
```

![](utrnfzi.svg)

## Related {#Related}

* Examples

* Experiments

* Analyses

* Tests
  * [`Constant`](Math.Tests.IntegerToBoolean.md)

  * [`IntegerToBoolean`](Math.Tests.IntegerToBoolean.md)

  * [`IntegerToBoolean`](Math.Tests.IntegerToBoolean.md)

  * [`RealToInteger`](Math.Tests.IntegerToBoolean.md)

  * [`Sine`](Math.Tests.IntegerToBoolean.md)
