---
url: /dyad/stable/stdlib/DiscreteComponents/tests/Examples.TestPeriodicClock.md
description: >-
  Dyad Examples.TestPeriodicClock docs.  Test component that validates the
  PeriodicClock component.
---

# `Examples.TestPeriodicClock` {#Examples.TestPeriodicClock}

Test component that validates the PeriodicClock component.

This component specifically tests the "provoker" / output formulation of the periodic clock. If it works correctly, this component should instantiate and run without error, sampling once per `dt` seconds.

## Usage {#Usage}

`DiscreteComponents.Examples.TestPeriodicClock()`

## Parameters: {#Parameters:}

| Name | Description | Units | Default value |
| ----:| -----------:| -----:| -------------:|
| `dt` |             |     – |           0.1 |

## Behavior {#Behavior}

$$ \begin{align}
0 &= \mathrm{connect}\left( sine\_{+}y, samplevalue\_{+}u \right) \\
0 &= \mathrm{connect}\left( samplevalue\_{+}y, periodicclockprovoker\_{+}y \right) \\
\mathtt{sine.y}\left( t \right) &= ifelse\left( \mathtt{sine.continuous}, ifelse\left( t \geq \mathtt{sine.start_time}, \sin\left( \mathtt{sine.phase} + 6.2832 ~ \mathtt{sine.frequency} ~ \left(  - \mathtt{sine.shift_time} + t \right) \right), \sin\left( \mathtt{sine.phase} + 6.2832 ~ \mathtt{sine.frequency} ~ \left(  - \mathtt{sine.shift_time} + \mathtt{sine.start_time} \right) \right) \right) ~ \mathtt{sine.amplitude}, ifelse\left( t \geq \mathtt{sine.start_time}, \sin\left( \mathtt{sine.phase} + 6.2832 ~ \mathtt{sine.frequency} ~ \left(  - \mathtt{sine.shift_time} + t \right) \right) ~ \mathtt{sine.amplitude}, 0 \right) \right) + \mathtt{sine.offset} \\
\mathtt{samplevalue.y}\left( t \right) &= Sample(InferredClock.InferredDiscrete(0))\left( \mathtt{samplevalue.u}\left( t \right) \right)
\end{align}
$$

## Source {#Source}

```dyad
"""
Test component that validates the PeriodicClock component.

This component specifically tests the "provoker" / output formulation of the periodic clock.
If it works correctly, this component should instantiate and run without error, sampling once per `dt` seconds.
"""
test component TestPeriodicClock
  sine = BlockComponents.Sources.Sine(frequency = 1, amplitude = 1.0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 140, "x2": 120, "y2": 240, "rot": 0}
      },
      "tags": []
    }
  }
  samplevalue = DiscreteComponents.Sampler() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 180, "y1": 140, "x2": 280, "y2": 240, "rot": 0}
      },
      "tags": []
    }
  }
  periodicclockprovoker = DiscreteComponents.PeriodicClock(dt = dt) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 410, "y1": 50, "x2": 510, "y2": 150, "rot": 0}
      },
      "tags": []
    }
  }
  structural parameter dt::Real = 0.1
relations
  connect(samplevalue.u, sine.y) {"Dyad": {"renderStyle": "standard", "edges": [{"S": 1, "E": 2, "M": []}]}}
  connect(periodicclockprovoker.y, samplevalue.y) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 350, "y": 100}, {"x": 350, "y": 190}], "E": 2}],
      "renderStyle": "standard"
    }
  }
metadata {
  "Dyad": {"tests": {"case1": {"stop": 10, "expect": {"signals": ["samplevalue.y"]}}}}
}
end
```

```dyad
"""
Test component that validates the PeriodicClock component.

This component specifically tests the "provoker" / output formulation of the periodic clock.
If it works correctly, this component should instantiate and run without error, sampling once per `dt` seconds.
"""
test component TestPeriodicClock
  sine = BlockComponents.Sources.Sine(frequency = 1, amplitude = 1.0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 140, "x2": 120, "y2": 240, "rot": 0}
      },
      "tags": []
    }
  }
  samplevalue = DiscreteComponents.Sampler() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 180, "y1": 140, "x2": 280, "y2": 240, "rot": 0}
      },
      "tags": []
    }
  }
  periodicclockprovoker = DiscreteComponents.PeriodicClock(dt = dt) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 410, "y1": 50, "x2": 510, "y2": 150, "rot": 0}
      },
      "tags": []
    }
  }
  structural parameter dt::Real = 0.1
relations
  connect(samplevalue.u, sine.y) {"Dyad": {"renderStyle": "standard", "edges": [{"S": 1, "E": 2, "M": []}]}}
  connect(periodicclockprovoker.y, samplevalue.y) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 350, "y": 100}, {"x": 350, "y": 190}], "E": 2}],
      "renderStyle": "standard"
    }
  }
metadata {
  "Dyad": {"tests": {"case1": {"stop": 10, "expect": {"signals": ["samplevalue.y"]}}}}
}
end
```

## Test Cases {#Test-Cases}

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

```julia
plt
```

![](utvyyng.svg)

## Related {#Related}

* Examples

* Experiments

* Analyses

* Tests
  * [`PeriodicClock`](Examples.TestPeriodicClock.md)

  * [`Sampler`](Examples.TestPeriodicClock.md)

  * [`Sine`](Examples.TestPeriodicClock.md)
