Test_Modulo Icon
Test_Modulo
This component serves as a test bench for the Modulo_Real_Input block. It uses two step signal sources (u1 and u2) to provide time-varying inputs and verifies the behavior of the modulo operation under dynamic conditions.
u1starts at 10 and steps down by 15 at time = 5 seconds.u2starts at 2 and steps down by 2 at time = 7 seconds.
These signals are connected to the Modulo_Real_Input component to observe how the output (y = u1 % u2) evolves as both inputs change.
The test runs for 10 seconds and checks that the output behaves as expected.
Example behavior: t < 5s: u1 = 10, u2 = 2 → y = 0 5s < t < 7s: u1 = -5, u2 = 2 → y = -1 t > 7s: u1 = -5, u2 = 0 → y = -5 (division by zero avoided)
Usage
PrimitiveComponents.Test_Modulo()
Behavior
\[ \begin{equation} \left[ \begin{array}{c} \mathrm{connect}\left( u1_{+}y(t), modulo_{real\_input_{+}u1(t)} \right) \\ \mathrm{connect}\left( u2_{+}y(t), modulo_{real\_input_{+}u2(t)} \right) \\ \mathtt{modulo\_real\_input.y}\left( t \right) = ifelse\left( \mathtt{modulo\_real\_input.u1}\left( t \right), rem\left( \mathtt{modulo\_real\_input.u1}\left( t \right), \mathtt{modulo\_real\_input.u2}\left( t \right) \right); \mathtt{modulo\_real\_input.u2}\left( t \right) = 0 \right) \\ \mathtt{u1.y}\left( t \right) = ifelse\left( t \geq \mathtt{u1.start\_time}, \mathtt{u1.height} + \mathtt{u1.offset}, \mathtt{u1.offset} \right) \\ \mathtt{u2.y}\left( t \right) = ifelse\left( t \geq \mathtt{u2.start\_time}, \mathtt{u2.height} + \mathtt{u2.offset}, \mathtt{u2.offset} \right) \\ \end{array} \right] \end{equation} \]
Source
"""
This component serves as a test bench for the `Modulo_Real_Input` block.
It uses two step signal sources (`u1` and `u2`) to provide time-varying inputs
and verifies the behavior of the modulo operation under dynamic conditions.
- `u1` starts at 10 and steps down by 15 at time = 5 seconds.
- `u2` starts at 2 and steps down by 2 at time = 7 seconds.
These signals are connected to the `Modulo_Real_Input` component to observe how the output
(`y = u1 % u2`) evolves as both inputs change.
The test runs for 10 seconds and checks that the output behaves as expected.
Example behavior:
t < 5s: u1 = 10, u2 = 2 → y = 0
5s < t < 7s: u1 = -5, u2 = 2 → y = -1
t > 7s: u1 = -5, u2 = 0 → y = -5 (division by zero avoided)
"""
component Test_Modulo
modulo_real_input = PrimitiveComponents.Mathematical.Modulo() {
"Dyad": {
"placement": {
"diagram": {"x1": 440, "x2": 540, "y1": 450, "y2": 550, "sh": 1, "sw": 1, "rot": 0}
}
}
}
u1 = BlockComponents.Step(start_time = 5, offset = 10, height = -15) {
"Dyad": {
"placement": {
"diagram": {"x1": 200, "x2": 300, "y1": 260, "y2": 360, "sh": 0.1, "sw": 0.1, "rot": 0}
}
}
}
u2 = BlockComponents.Step(start_time = 7, height = -2, offset = 2) {
"Dyad": {
"placement": {
"diagram": {"x1": 200, "x2": 300, "y1": 570, "y2": 670, "sh": 1, "sw": 1, "rot": 0}
}
}
}
relations
connect(u1.y, modulo_real_input.u1) {
"Dyad": {"edges": [{"S": 1, "E": 2, "M": [{"x": 379, "y": 310}, {"x": 379, "y": 467}]}]}
}
connect(u2.y, modulo_real_input.u2) {
"Dyad": {"edges": [{"S": 1, "E": 2, "M": [{"x": 369, "y": 620}, {"x": 369, "y": 531}]}]}
}
metadata {
"Dyad": {
"experiments": {"Test_Modulo_Real_Input_": {"stop": 10}},
"tests": {
"case1": {
"stop": 10,
"abstol": 0.00001,
"reltol": 0.00001,
"expect": {"signals": ["modulo_real_input.y"]}
}
}
}
}
end
Flattened Source
"""
This component serves as a test bench for the `Modulo_Real_Input` block.
It uses two step signal sources (`u1` and `u2`) to provide time-varying inputs
and verifies the behavior of the modulo operation under dynamic conditions.
- `u1` starts at 10 and steps down by 15 at time = 5 seconds.
- `u2` starts at 2 and steps down by 2 at time = 7 seconds.
These signals are connected to the `Modulo_Real_Input` component to observe how the output
(`y = u1 % u2`) evolves as both inputs change.
The test runs for 10 seconds and checks that the output behaves as expected.
Example behavior:
t < 5s: u1 = 10, u2 = 2 → y = 0
5s < t < 7s: u1 = -5, u2 = 2 → y = -1
t > 7s: u1 = -5, u2 = 0 → y = -5 (division by zero avoided)
"""
component Test_Modulo
modulo_real_input = PrimitiveComponents.Mathematical.Modulo() {
"Dyad": {
"placement": {
"diagram": {"x1": 440, "x2": 540, "y1": 450, "y2": 550, "sh": 1, "sw": 1, "rot": 0}
}
}
}
u1 = BlockComponents.Step(start_time = 5, offset = 10, height = -15) {
"Dyad": {
"placement": {
"diagram": {"x1": 200, "x2": 300, "y1": 260, "y2": 360, "sh": 0.1, "sw": 0.1, "rot": 0}
}
}
}
u2 = BlockComponents.Step(start_time = 7, height = -2, offset = 2) {
"Dyad": {
"placement": {
"diagram": {"x1": 200, "x2": 300, "y1": 570, "y2": 670, "sh": 1, "sw": 1, "rot": 0}
}
}
}
relations
connect(u1.y, modulo_real_input.u1) {
"Dyad": {"edges": [{"S": 1, "E": 2, "M": [{"x": 379, "y": 310}, {"x": 379, "y": 467}]}]}
}
connect(u2.y, modulo_real_input.u2) {
"Dyad": {"edges": [{"S": 1, "E": 2, "M": [{"x": 369, "y": 620}, {"x": 369, "y": 531}]}]}
}
metadata {
"Dyad": {
"experiments": {"Test_Modulo_Real_Input_": {"stop": 10}},
"tests": {
"case1": {
"stop": 10,
"abstol": 0.00001,
"reltol": 0.00001,
"expect": {"signals": ["modulo_real_input.y"]}
}
}
}
}
endTest Cases
Test Case case1
pltRelated
- Examples
- Experiments
- Analyses