LIBRARY
Math.Tests.RealToInteger
Rounds constant and time-varying Real inputs to the nearest Integer.
Connects a constant source with value 2.7 to a RealToInteger block and verifies that the output rounds to 3. A second RealToInteger block is driven by a sine wave (amplitude 3) so the rounded integer output steps through several values over time.
Usage
BlockComponents.Math.Tests.RealToInteger()
Behavior
Source
dyad
"""
Rounds constant and time-varying Real inputs to the nearest Integer.
Connects a constant source with value 2.7 to a RealToInteger block and verifies
that the output rounds to 3. A second RealToInteger block is driven by a sine
wave (amplitude 3) so the rounded integer output steps through several values
over time.
"""
test component RealToInteger
"Constant source providing the Real input"
c1 = BlockComponents.Sources.Constant(k = 2.7) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 20, "y1": 20, "x2": 120, "y2": 120, "rot": 0}
},
"tags": []
}
}
"RealToInteger block under test"
r2i = BlockComponents.Math.RealToInteger() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 170, "y1": 20, "x2": 270, "y2": 120, "rot": 0}
},
"tags": []
}
}
"Sine source sweeping negative and positive values"
sine = BlockComponents.Sources.Sine(amplitude = 3, frequency = 1) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 20, "y1": 140, "x2": 120, "y2": 240, "rot": 0}
},
"tags": []
}
}
"Second RealToInteger block driven by the sine source"
r2i_2 = BlockComponents.Math.RealToInteger() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 160, "y1": 140, "x2": 260, "y2": 240, "rot": 0}
},
"tags": []
}
}
relations
connect(c1.y, r2i.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"}}
metadata {
"Dyad": {
"icons": {"default": "dyad://BlockComponents/Example.svg"},
"tests": {"case1": {"stop": 1, "expect": {"signals": ["r2i.y", "r2i_2.y", "sine.y"]}}}
}
}
endFlattened Source
dyad
"""
Rounds constant and time-varying Real inputs to the nearest Integer.
Connects a constant source with value 2.7 to a RealToInteger block and verifies
that the output rounds to 3. A second RealToInteger block is driven by a sine
wave (amplitude 3) so the rounded integer output steps through several values
over time.
"""
test component RealToInteger
"Constant source providing the Real input"
c1 = BlockComponents.Sources.Constant(k = 2.7) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 20, "y1": 20, "x2": 120, "y2": 120, "rot": 0}
},
"tags": []
}
}
"RealToInteger block under test"
r2i = BlockComponents.Math.RealToInteger() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 170, "y1": 20, "x2": 270, "y2": 120, "rot": 0}
},
"tags": []
}
}
"Sine source sweeping negative and positive values"
sine = BlockComponents.Sources.Sine(amplitude = 3, frequency = 1) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 20, "y1": 140, "x2": 120, "y2": 240, "rot": 0}
},
"tags": []
}
}
"Second RealToInteger block driven by the sine source"
r2i_2 = BlockComponents.Math.RealToInteger() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 160, "y1": 140, "x2": 260, "y2": 240, "rot": 0}
},
"tags": []
}
}
relations
connect(c1.y, r2i.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"}}
metadata {
"Dyad": {
"icons": {"default": "dyad://BlockComponents/Example.svg"},
"tests": {"case1": {"stop": 1, "expect": {"signals": ["r2i.y", "r2i_2.y", "sine.y"]}}}
}
}
endTest Cases
Test Case case1
julia
pltjulia
pltjulia
pltRelated
Examples
Experiments
Analyses
Tests