---
url: /dyad/dev/stdlib/BlockComponents/tests/Math.Tests.Add.md
description: Dyad Math.Tests.Add docs.  Adds constant and time-varying inputs.
---

# `Math.Tests.Add` {#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 {#Usage}

`BlockComponents.Math.Tests.Add()`

## Behavior {#Behavior}

$$ \begin{align}
0 &= \mathrm{connect}\left( c1\_{+}y, add\_{+}u1 \right) \\
0 &= \mathrm{connect}\left( c2\_{+}y, add\_{+}u2 \right) \\
0 &= \mathrm{connect}\left( sine1\_{+}y, add\_{2\_{+}u1} \right) \\
0 &= \mathrm{connect}\left( sine2\_{+}y, add\_{2\_{+}u2} \right) \\
\mathtt{c1.y}\left( t \right) &= \mathtt{c1.k} \\
\mathtt{c2.y}\left( t \right) &= \mathtt{c2.k} \\
\mathtt{add.y}\left( t \right) &= \mathtt{add.k1} ~ \mathtt{add.u1}\left( t \right) + \mathtt{add.k2} ~ \mathtt{add.u2}\left( t \right) \\
\mathtt{sine1.y}\left( t \right) &= ifelse\left( \mathtt{sine1.continuous}, ifelse\left( t \geq \mathtt{sine1.start_time}, \sin\left( \mathtt{sine1.phase} + 6.2832 ~ \mathtt{sine1.frequency} ~ \left(  - \mathtt{sine1.shift_time} + t \right) \right), \sin\left( \mathtt{sine1.phase} + 6.2832 ~ \mathtt{sine1.frequency} ~ \left(  - \mathtt{sine1.shift_time} + \mathtt{sine1.start_time} \right) \right) \right) ~ \mathtt{sine1.amplitude}, ifelse\left( t \geq \mathtt{sine1.start_time}, \sin\left( \mathtt{sine1.phase} + 6.2832 ~ \mathtt{sine1.frequency} ~ \left(  - \mathtt{sine1.shift_time} + t \right) \right) ~ \mathtt{sine1.amplitude}, 0 \right) \right) + \mathtt{sine1.offset} \\
\mathtt{sine2.y}\left( t \right) &= ifelse\left( \mathtt{sine2.continuous}, ifelse\left( t \geq \mathtt{sine2.start_time}, \sin\left( \mathtt{sine2.phase} + 6.2832 ~ \mathtt{sine2.frequency} ~ \left(  - \mathtt{sine2.shift_time} + t \right) \right), \sin\left( \mathtt{sine2.phase} + 6.2832 ~ \mathtt{sine2.frequency} ~ \left(  - \mathtt{sine2.shift_time} + \mathtt{sine2.start_time} \right) \right) \right) ~ \mathtt{sine2.amplitude}, ifelse\left( t \geq \mathtt{sine2.start_time}, \sin\left( \mathtt{sine2.phase} + 6.2832 ~ \mathtt{sine2.frequency} ~ \left(  - \mathtt{sine2.shift_time} + t \right) \right) ~ \mathtt{sine2.amplitude}, 0 \right) \right) + \mathtt{sine2.offset} \\
\mathtt{add_2.y}\left( t \right) &= \mathtt{add_2.k1} ~ \mathtt{add_2.u1}\left( t \right) + \mathtt{add_2.k2} ~ \mathtt{add_2.u2}\left( t \right)
\end{align}
$$

## Source {#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"]}}
    }
  }
}
end
```

```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"]}}
    }
  }
}
end
```

## Test Cases {#Test-Cases}

### Test Case `case1` {#Test-Case-case1}

```julia
plt
```

![](dzviyxt.svg)

```julia
plt
```

![](oiitiac.svg)

```julia
plt
```

![](lxwjvdz.svg)

```julia
plt
```

![](qzljhac.svg)

## Related {#Related}

* Examples

* Experiments

* Analyses

* Tests
  * [`Add`](Math.Tests.Add.md)

  * [`Add`](Math.Tests.Add.md)

  * [`Constant`](Math.Tests.Add.md)

  * [`Sine`](Math.Tests.Add.md)
