LIBRARY
Math.Tests.Add3
Test the functionality of the Add3 block by connecting constant and time-varying inputs.
This test harness connects three constant sources (with values 1, 2, and 3) to an Add3 component and verifies that the output equals the sum of the inputs (6). The test case simulates for 5 seconds and checks the final value of the output. A second Add3 block is driven by three sine waves that sweep negative and positive values so the sum varies over time.
Usage
BlockComponents.Math.Tests.Add3()
Behavior
Source
dyad
"""
Test the functionality of the Add3 block by connecting constant and time-varying inputs.
This test harness connects three constant sources (with values 1, 2, and 3) to an Add3 component and verifies
that the output equals the sum of the inputs (6). The test case simulates for 5 seconds and checks the final
value of the output. A second Add3 block is driven by three sine waves that sweep negative and positive values
so the sum varies over time.
"""
test component Add3
"Constant source with value 1"
c1 = BlockComponents.Sources.Constant(k = 1) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 400, "y1": 0, "x2": 500, "y2": 100, "rot": 0}
},
"tags": []
}
}
"Constant source with value 2"
c2 = BlockComponents.Sources.Constant(k = 2) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 400, "y1": 190, "x2": 500, "y2": 290, "rot": 0}
},
"tags": []
}
}
"Constant source with value 3"
c3 = BlockComponents.Sources.Constant(k = 3) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 400, "y1": 400, "x2": 500, "y2": 500, "rot": 0}
},
"tags": []
}
}
"Component that adds three inputs"
add3 = BlockComponents.Math.Add3() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 640, "y1": 190, "x2": 740, "y2": 290, "rot": 0}
},
"tags": []
}
}
"Sine source for the first input of the second block"
sine1 = BlockComponents.Sources.Sine(amplitude = 2, frequency = 1) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 400, "y1": 570, "x2": 500, "y2": 670, "rot": 0}
},
"tags": []
}
}
"Sine source for the second input of the second block"
sine2 = BlockComponents.Sources.Sine(amplitude = 3, frequency = 1) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 400, "y1": 760, "x2": 500, "y2": 860, "rot": 0}
},
"tags": []
}
}
"Sine source for the third input of the second block"
sine3 = BlockComponents.Sources.Sine(amplitude = 1, frequency = 1) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 400, "y1": 970, "x2": 500, "y2": 1070, "rot": 0}
},
"tags": []
}
}
"Second Add3 block driven by the sine sources"
add3_2 = BlockComponents.Math.Add3() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 640, "y1": 760, "x2": 740, "y2": 860, "rot": 0}
},
"tags": []
}
}
relations
connect(add3.u1, c1.y) {
"Dyad": {
"edges": [{"S": 1, "M": [{"x": 590, "y": 210}, {"x": 590, "y": 50}], "E": 2}],
"renderStyle": "standard"
}
}
connect(add3.u2, c2.y) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
connect(add3.u3, c3.y) {
"Dyad": {
"edges": [{"S": 1, "M": [{"x": 600, "y": 270}, {"x": 600, "y": 450}], "E": 2}],
"renderStyle": "standard"
}
}
connect(add3_2.u1, sine1.y) {
"Dyad": {
"edges": [{"S": 1, "M": [{"x": 580, "y": 780}, {"x": 580, "y": 620}], "E": 2}],
"renderStyle": "standard"
}
}
connect(add3_2.u2, sine2.y) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
connect(add3_2.u3, sine3.y) {
"Dyad": {
"edges": [{"S": 1, "M": [{"x": 580, "y": 840}, {"x": 580, "y": 1020}], "E": 2}],
"renderStyle": "standard"
}
}
metadata {
"Dyad": {
"icons": {"default": "dyad://BlockComponents/Example.svg"},
"tests": {
"case1": {
"stop": 5,
"expect": {"signals": ["add3.y", "add3_2.y", "sine1.y", "sine2.y", "sine3.y"]}
}
}
}
}
endFlattened Source
dyad
"""
Test the functionality of the Add3 block by connecting constant and time-varying inputs.
This test harness connects three constant sources (with values 1, 2, and 3) to an Add3 component and verifies
that the output equals the sum of the inputs (6). The test case simulates for 5 seconds and checks the final
value of the output. A second Add3 block is driven by three sine waves that sweep negative and positive values
so the sum varies over time.
"""
test component Add3
"Constant source with value 1"
c1 = BlockComponents.Sources.Constant(k = 1) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 400, "y1": 0, "x2": 500, "y2": 100, "rot": 0}
},
"tags": []
}
}
"Constant source with value 2"
c2 = BlockComponents.Sources.Constant(k = 2) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 400, "y1": 190, "x2": 500, "y2": 290, "rot": 0}
},
"tags": []
}
}
"Constant source with value 3"
c3 = BlockComponents.Sources.Constant(k = 3) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 400, "y1": 400, "x2": 500, "y2": 500, "rot": 0}
},
"tags": []
}
}
"Component that adds three inputs"
add3 = BlockComponents.Math.Add3() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 640, "y1": 190, "x2": 740, "y2": 290, "rot": 0}
},
"tags": []
}
}
"Sine source for the first input of the second block"
sine1 = BlockComponents.Sources.Sine(amplitude = 2, frequency = 1) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 400, "y1": 570, "x2": 500, "y2": 670, "rot": 0}
},
"tags": []
}
}
"Sine source for the second input of the second block"
sine2 = BlockComponents.Sources.Sine(amplitude = 3, frequency = 1) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 400, "y1": 760, "x2": 500, "y2": 860, "rot": 0}
},
"tags": []
}
}
"Sine source for the third input of the second block"
sine3 = BlockComponents.Sources.Sine(amplitude = 1, frequency = 1) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 400, "y1": 970, "x2": 500, "y2": 1070, "rot": 0}
},
"tags": []
}
}
"Second Add3 block driven by the sine sources"
add3_2 = BlockComponents.Math.Add3() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 640, "y1": 760, "x2": 740, "y2": 860, "rot": 0}
},
"tags": []
}
}
relations
connect(add3.u1, c1.y) {
"Dyad": {
"edges": [{"S": 1, "M": [{"x": 590, "y": 210}, {"x": 590, "y": 50}], "E": 2}],
"renderStyle": "standard"
}
}
connect(add3.u2, c2.y) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
connect(add3.u3, c3.y) {
"Dyad": {
"edges": [{"S": 1, "M": [{"x": 600, "y": 270}, {"x": 600, "y": 450}], "E": 2}],
"renderStyle": "standard"
}
}
connect(add3_2.u1, sine1.y) {
"Dyad": {
"edges": [{"S": 1, "M": [{"x": 580, "y": 780}, {"x": 580, "y": 620}], "E": 2}],
"renderStyle": "standard"
}
}
connect(add3_2.u2, sine2.y) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
connect(add3_2.u3, sine3.y) {
"Dyad": {
"edges": [{"S": 1, "M": [{"x": 580, "y": 840}, {"x": 580, "y": 1020}], "E": 2}],
"renderStyle": "standard"
}
}
metadata {
"Dyad": {
"icons": {"default": "dyad://BlockComponents/Example.svg"},
"tests": {
"case1": {
"stop": 5,
"expect": {"signals": ["add3.y", "add3_2.y", "sine1.y", "sine2.y", "sine3.y"]}
}
}
}
}
endTest Cases
Test Case case1
julia
pltjulia
pltjulia
pltjulia
pltjulia
plt