Skip to content
LIBRARY
Math.Tests.IntegerToReal.md

Math.Tests.IntegerToReal ​

Converts constant and time-varying Integer signals back to Real.

Chains Constant(5.0) → RealToInteger → IntegerToReal and verifies that the final Real output is 5. A second chain feeds a sine wave (amplitude 5) through RealToInteger into IntegerToReal so the Real output steps through the rounded integer values over time.

Usage ​

BlockComponents.Math.Tests.IntegerToReal()

Behavior ​

Source ​

dyad
"""
Converts constant and time-varying Integer signals back to Real.

Chains Constant(5.0) → RealToInteger → IntegerToReal and verifies that the
final Real output is 5. A second chain feeds a sine wave (amplitude 5) through
RealToInteger into IntegerToReal so the Real output steps through the rounded
integer values over time.
"""
test component IntegerToReal
  "Constant source providing the Real input"
  c1 = BlockComponents.Sources.Constant(k = 5) {
    "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": []
    }
  }
  "IntegerToReal block under test"
  i2r = BlockComponents.Math.IntegerToReal() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 310, "y1": 20, "x2": 410, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  "Sine source sweeping negative and positive values"
  sine = BlockComponents.Sources.Sine(amplitude = 5, 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 IntegerToReal block driven by the sine chain"
  i2r_2 = BlockComponents.Math.IntegerToReal() {
    "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, i2r.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, i2r_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": ["i2r.y", "i2r_2.y", "sine.y"]}}}
  }
}
end
Flattened Source
dyad
"""
Converts constant and time-varying Integer signals back to Real.

Chains Constant(5.0) → RealToInteger → IntegerToReal and verifies that the
final Real output is 5. A second chain feeds a sine wave (amplitude 5) through
RealToInteger into IntegerToReal so the Real output steps through the rounded
integer values over time.
"""
test component IntegerToReal
  "Constant source providing the Real input"
  c1 = BlockComponents.Sources.Constant(k = 5) {
    "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": []
    }
  }
  "IntegerToReal block under test"
  i2r = BlockComponents.Math.IntegerToReal() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 310, "y1": 20, "x2": 410, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  "Sine source sweeping negative and positive values"
  sine = BlockComponents.Sources.Sine(amplitude = 5, 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 IntegerToReal block driven by the sine chain"
  i2r_2 = BlockComponents.Math.IntegerToReal() {
    "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, i2r.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, i2r_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": ["i2r.y", "i2r_2.y", "sine.y"]}}}
  }
}
end


Test Cases ​

Test Case case1 ​

julia
plt

julia
plt

julia
plt