LIBRARY
Math.Tests.Add
Adds constant and time-varying inputs.
This component demonstrates basic component composition by connecting two constant sources (with values 1 and 2) to an adder block. The output of the adder (add.y) equals the sum of the two inputs (3). A second adder is driven by two sine waves that sweep negative and positive values so the sum varies over time.
Usage
BlockComponents.Math.Tests.Add()
Behavior
Source
dyad
"""
Adds constant and time-varying inputs.
This component demonstrates basic component composition by connecting two constant sources
(with values 1 and 2) to an adder block. The output of the adder (add.y) equals the sum of
the two inputs (3). A second adder is driven by two sine waves that sweep negative and
positive values so the sum varies over time.
"""
test component Add
"Constant source with value 1"
c1 = BlockComponents.Sources.Constant(k = 1) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 290, "y1": 370, "x2": 390, "y2": 470, "rot": 0}
}
}
}
"Constant source with value 2"
c2 = BlockComponents.Sources.Constant(k = 2) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 300, "y1": 550, "x2": 400, "y2": 650, "rot": 0}
}
}
}
"Adder that sums its two inputs"
add = BlockComponents.Math.Add() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 590, "y1": 450, "x2": 690, "y2": 550, "rot": 0}
}
}
}
"Sine source for the first input of the second adder"
sine1 = BlockComponents.Sources.Sine(amplitude = 2, frequency = 1) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 290, "y1": 760, "x2": 390, "y2": 860, "rot": 0}
}
}
}
"Sine source for the second input of the second adder"
sine2 = BlockComponents.Sources.Sine(amplitude = 3, frequency = 1) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 300, "y1": 940, "x2": 400, "y2": 1040, "rot": 0}
}
}
}
"Second adder driven by the sine sources"
add_2 = BlockComponents.Math.Add() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 590, "y1": 840, "x2": 690, "y2": 940, "rot": 0}
}
}
}
relations
"Connects the output of constant 1 to the first input of the adder"
connect(add.u1, c1.y) {
"Dyad": {
"edges": [{"S": 1, "M": [{"x": 500, "y": 470}, {"x": 500, "y": 420}], "E": 2}],
"renderStyle": "standard"
}
}
"Connects the output of constant 2 to the second input of the adder"
connect(add.u2, c2.y) {
"Dyad": {
"edges": [{"S": 1, "M": [{"x": 500, "y": 530}, {"x": 500, "y": 600}], "E": 2}],
"renderStyle": "standard"
}
}
connect(add_2.u1, sine1.y) {
"Dyad": {
"edges": [{"S": 1, "M": [{"x": 500, "y": 860}, {"x": 500, "y": 810}], "E": 2}],
"renderStyle": "standard"
}
}
connect(add_2.u2, sine2.y) {
"Dyad": {
"edges": [{"S": 1, "M": [{"x": 500, "y": 920}, {"x": 500, "y": 990}], "E": 2}],
"renderStyle": "standard"
}
}
metadata {
"Dyad": {
"icons": {"default": "dyad://BlockComponents/Example.svg"},
"tests": {
"case1": {"stop": 5, "expect": {"signals": ["add.y", "add_2.y", "sine1.y", "sine2.y"]}}
}
}
}
endFlattened Source
dyad
"""
Adds constant and time-varying inputs.
This component demonstrates basic component composition by connecting two constant sources
(with values 1 and 2) to an adder block. The output of the adder (add.y) equals the sum of
the two inputs (3). A second adder is driven by two sine waves that sweep negative and
positive values so the sum varies over time.
"""
test component Add
"Constant source with value 1"
c1 = BlockComponents.Sources.Constant(k = 1) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 290, "y1": 370, "x2": 390, "y2": 470, "rot": 0}
}
}
}
"Constant source with value 2"
c2 = BlockComponents.Sources.Constant(k = 2) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 300, "y1": 550, "x2": 400, "y2": 650, "rot": 0}
}
}
}
"Adder that sums its two inputs"
add = BlockComponents.Math.Add() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 590, "y1": 450, "x2": 690, "y2": 550, "rot": 0}
}
}
}
"Sine source for the first input of the second adder"
sine1 = BlockComponents.Sources.Sine(amplitude = 2, frequency = 1) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 290, "y1": 760, "x2": 390, "y2": 860, "rot": 0}
}
}
}
"Sine source for the second input of the second adder"
sine2 = BlockComponents.Sources.Sine(amplitude = 3, frequency = 1) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 300, "y1": 940, "x2": 400, "y2": 1040, "rot": 0}
}
}
}
"Second adder driven by the sine sources"
add_2 = BlockComponents.Math.Add() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 590, "y1": 840, "x2": 690, "y2": 940, "rot": 0}
}
}
}
relations
"Connects the output of constant 1 to the first input of the adder"
connect(add.u1, c1.y) {
"Dyad": {
"edges": [{"S": 1, "M": [{"x": 500, "y": 470}, {"x": 500, "y": 420}], "E": 2}],
"renderStyle": "standard"
}
}
"Connects the output of constant 2 to the second input of the adder"
connect(add.u2, c2.y) {
"Dyad": {
"edges": [{"S": 1, "M": [{"x": 500, "y": 530}, {"x": 500, "y": 600}], "E": 2}],
"renderStyle": "standard"
}
}
connect(add_2.u1, sine1.y) {
"Dyad": {
"edges": [{"S": 1, "M": [{"x": 500, "y": 860}, {"x": 500, "y": 810}], "E": 2}],
"renderStyle": "standard"
}
}
connect(add_2.u2, sine2.y) {
"Dyad": {
"edges": [{"S": 1, "M": [{"x": 500, "y": 920}, {"x": 500, "y": 990}], "E": 2}],
"renderStyle": "standard"
}
}
metadata {
"Dyad": {
"icons": {"default": "dyad://BlockComponents/Example.svg"},
"tests": {
"case1": {"stop": 5, "expect": {"signals": ["add.y", "add_2.y", "sine1.y", "sine2.y"]}}
}
}
}
endTest Cases
Test Case case1
julia
pltjulia
pltjulia
pltjulia
plt