---
url: /dyad/stable/stdlib/BlockComponents/tests/Math.Tests.ContinuousMean.md
description: >-
  Dyad Math.Tests.ContinuousMean docs.  Test for ContinuousMean block: mean of a
  constant and mean of a sine.
---

# `Math.Tests.ContinuousMean` {#Math.Tests.ContinuousMean}

Test for ContinuousMean block: mean of a constant and mean of a sine.

## Usage {#Usage}

`BlockComponents.Math.Tests.ContinuousMean()`

## Behavior {#Behavior}

$$ \begin{align}
0 &= \mathrm{connect}\left( const\_{src\_{+}y}, mean\_{const\_{+}u} \right) \\
0 &= \mathrm{connect}\left( sine\_{src\_{+}y}, mean\_{sine\_{+}u} \right) \\
\mathtt{const_src.y}\left( t \right) &= \mathtt{const_src.k} \\
\frac{\mathrm{d}\mathtt{mean_const.t_0}\left( t \right)}{\mathrm{d}t} &= 0 \\
\mathtt{mean_const.actualStartTime}\left( t \right) &= max\left( \mathtt{mean_const.t_0}\left( t \right), \mathtt{mean_const.startTime} \right) \\
\frac{\mathrm{d}\mathtt{mean_const.mu}\left( t \right)}{\mathrm{d}t} &= ifelse\left( t \geq \mathtt{mean_const.actualStartTime}\left( t \right), \mathtt{mean_const.u}\left( t \right), 0 \right) \\
\mathtt{mean_const.y}\left( t \right) &= ifelse\left( \mathtt{mean_const.actualStartTime}\left( t \right) + \mathtt{mean_const.t_eps} < t, \frac{\mathtt{mean_const.mu}\left( t \right)}{ - \mathtt{mean_const.actualStartTime}\left( t \right) + t}, \mathtt{mean_const.u}\left( t \right) \right) \\
\mathtt{sine_src.y}\left( t \right) &= ifelse\left( \mathtt{sine_src.continuous}, ifelse\left( t \geq \mathtt{sine_src.start_time}, \sin\left( \mathtt{sine_src.phase} + 6.2832 ~ \mathtt{sine_src.frequency} ~ \left(  - \mathtt{sine_src.shift_time} + t \right) \right), \sin\left( \mathtt{sine_src.phase} + 6.2832 ~ \mathtt{sine_src.frequency} ~ \left(  - \mathtt{sine_src.shift_time} + \mathtt{sine_src.start_time} \right) \right) \right) ~ \mathtt{sine_src.amplitude}, ifelse\left( t \geq \mathtt{sine_src.start_time}, \sin\left( \mathtt{sine_src.phase} + 6.2832 ~ \mathtt{sine_src.frequency} ~ \left(  - \mathtt{sine_src.shift_time} + t \right) \right) ~ \mathtt{sine_src.amplitude}, 0 \right) \right) + \mathtt{sine_src.offset} \\
\frac{\mathrm{d}\mathtt{mean_sine.t_0}\left( t \right)}{\mathrm{d}t} &= 0 \\
\mathtt{mean_sine.actualStartTime}\left( t \right) &= max\left( \mathtt{mean_sine.t_0}\left( t \right), \mathtt{mean_sine.startTime} \right) \\
\frac{\mathrm{d}\mathtt{mean_sine.mu}\left( t \right)}{\mathrm{d}t} &= ifelse\left( t \geq \mathtt{mean_sine.actualStartTime}\left( t \right), \mathtt{mean_sine.u}\left( t \right), 0 \right) \\
\mathtt{mean_sine.y}\left( t \right) &= ifelse\left( \mathtt{mean_sine.actualStartTime}\left( t \right) + \mathtt{mean_sine.t_eps} < t, \frac{\mathtt{mean_sine.mu}\left( t \right)}{ - \mathtt{mean_sine.actualStartTime}\left( t \right) + t}, \mathtt{mean_sine.u}\left( t \right) \right)
\end{align}
$$

## Source {#Source}

```dyad
"Test for ContinuousMean block: mean of a constant and mean of a sine."
test component ContinuousMean
  "Mean of a constant signal should equal the constant"
  const_src = BlockComponents.Sources.Constant(k = 3.0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 20, "x2": 120, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  mean_const = BlockComponents.Math.ContinuousMean() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 170, "y1": 20, "x2": 270, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  "Mean of a sine signal should converge to zero over full periods"
  sine_src = BlockComponents.Sources.Sine(amplitude = 2.0, frequency = 1.0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 140, "x2": 120, "y2": 240, "rot": 0}
      },
      "tags": []
    }
  }
  mean_sine = BlockComponents.Math.ContinuousMean() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 160, "y1": 140, "x2": 260, "y2": 240, "rot": 0}
      },
      "tags": []
    }
  }
relations
  connect(const_src.y, mean_const.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(sine_src.y, mean_sine.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
metadata {
  "Dyad": {
    "icons": {"default": "dyad://BlockComponents/Example.svg"},
    "tests": {
      "case1": {
        "stop": 10,
        "expect": {"signals": ["const_src.y", "mean_const.y", "sine_src.y", "mean_sine.y"]}
      }
    }
  }
}
end
```

```dyad
"Test for ContinuousMean block: mean of a constant and mean of a sine."
test component ContinuousMean
  "Mean of a constant signal should equal the constant"
  const_src = BlockComponents.Sources.Constant(k = 3.0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 20, "x2": 120, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  mean_const = BlockComponents.Math.ContinuousMean() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 170, "y1": 20, "x2": 270, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  "Mean of a sine signal should converge to zero over full periods"
  sine_src = BlockComponents.Sources.Sine(amplitude = 2.0, frequency = 1.0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 140, "x2": 120, "y2": 240, "rot": 0}
      },
      "tags": []
    }
  }
  mean_sine = BlockComponents.Math.ContinuousMean() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 160, "y1": 140, "x2": 260, "y2": 240, "rot": 0}
      },
      "tags": []
    }
  }
relations
  connect(const_src.y, mean_const.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(sine_src.y, mean_sine.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
metadata {
  "Dyad": {
    "icons": {"default": "dyad://BlockComponents/Example.svg"},
    "tests": {
      "case1": {
        "stop": 10,
        "expect": {"signals": ["const_src.y", "mean_const.y", "sine_src.y", "mean_sine.y"]}
      }
    }
  }
}
end
```

## Test Cases {#Test-Cases}

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

```julia
plt
```

![](ooqhckv.svg)

```julia
plt
```

![](koozzqb.svg)

```julia
plt
```

![](qgfeyxu.svg)

```julia
plt
```

![](poxukkr.svg)

## Related {#Related}

* Examples

* Experiments

* Analyses

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

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

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

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