ouroboros-network-testing-0.1.0.0: Common modules used for testing in ouroboros-network and ouroboros-consensus

Ouroboros.Network.Testing.Data.Signal

Synopsis

# Events

data Events a Source #

A time-ordered trace of discrete events that occur at specific times.

This corresponds for example to a trace of events or observations from a simulation.

#### Instances

Instances details

# Signals

data Signal a Source #

A signal is a time-varying value. It has a value at all times. It changes value at discrete times, i.e. it is not continuous.

#### Instances

Instances details
 Source # Instance detailsDefined in Ouroboros.Network.Testing.Data.Signal Methodsfmap ∷ (a → b) → Signal a → Signal b Source #(<\$) ∷ a → Signal b → Signal a Source # Source # Instance detailsDefined in Ouroboros.Network.Testing.Data.Signal Methodspure ∷ a → Signal a Source #(<*>) ∷ Signal (a → b) → Signal a → Signal b Source #liftA2 ∷ (a → b → c) → Signal a → Signal b → Signal c Source #(*>) ∷ Signal a → Signal b → Signal b Source #(<*) ∷ Signal a → Signal b → Signal a Source # Show a ⇒ Show (Signal a) Source # Instance detailsDefined in Ouroboros.Network.Testing.Data.Signal MethodsshowList ∷ [Signal a] → ShowS Source #

## Construction and conversion

fromChangeEvents ∷ a → Events a → Signal a Source #

Construct a Signal from an initial value and a time series of events that represent new values of the signal.

This only makes sense for events that sample a single time-varying value.

Convert a Signal into a time series of events when the signal value changes.

Construct a Signal that represents a time series of discrete events. The signal is Just the event value at the time of the event, and is Nothing at all other times.

Note that this signal "instantaneously" takes the event value and reverts to Nothing before time moves on. Therefore this kind of signal is not "stable" in the sense of stableSignal.

## QuickCheck

signalProperty ∷ ∀ a. Int → (a → String) → (a → Bool) → Signal a → Property Source #

Check a property over a Signal. The property should be true at all times.

On failure it shows the n most recent signal values.

# Simple signal transformations

truncateAt ∷ Time → Signal a → Signal a Source #

A signal can change value more than once at a single point of time.

Sometimes we are interested only in the final "stable" value of the signal before time moves on. This function discards the other values, keeping only the final value at each time.

nubEq a ⇒ Signal a → Signal a Source #

Sometimes the way a signal is constructed leads to duplicate signal values which can slow down signal processing. This tidies up the signal by eliminating the duplicates. This does not change the meaning (provided the Eq instance is true equality).

nubBy ∷ (a → a → Bool) → Signal a → Signal a Source #

# Temporal operations

lingerDiffTime → (a → Bool) → Signal a → Signal Bool Source #

A linger signal remains True for the given time after the underlying signal is True.

Arguments

 ∷ ∀ a. DiffTime timeout duration → (a → Bool) the arming function → Signal a → Signal Bool

Make a timeout signal, based on observing an underlying signal.

The timeout signal takes the value True when the timeout has occurred, and False otherwise.

The timeout is controlled by an "arming" function on the underlying signal. The arming function should return True when the timeout should be started, and it returns the time to wait before the timeout fires. The arming function should return False when the timeout should be cancelled or not started.

The output signal becomes True when the arming function has been continuously active (i.e. returning True) for the given duration.

Arguments

 ∷ (a → Bool) Start → (a → Bool) Stop → Signal a → Signal Bool

difference ∷ (a → a → b) → Signal a → Signal (Maybe b) Source #

scanl ∷ (b → a → b) → b → Signal a → Signal b Source #

# Set-based temporal operations

Arguments

 ∷ ∀ a b. Ord b ⇒ DiffTime → (a → Set b) The timeout arming set signal → Signal a → Signal (Set b)

Make a signal that says if a given event longed at least a certain time (timeout), based on observing an underlying signal.

The underlying signal is scrutinised with the provided "timeout arming" function that tells us if the signal value is interesting to track. If it is, we arm it with a timeout and see, if until the timeout goes off there's no other event to arm. If any activity occurs again before the previous timeout, then the timeout is reset with the new event and the other one is discarded.

Arguments

 ∷ ∀ a b. Ord b ⇒ DiffTime → (a → Set b) The activity set signal → Signal a → Signal (Set b)

Make a signal that keeps track of recent activity, based on observing an underlying signal.

The underlying signal is scrutinised with the provided "activity interest" function that tells us if the signal value is activity of interest to track. If it is, the given key is entered into the result signal set for the given time duration. If the same activity occurs again before the duration expires then the expiry will be extended to the new deadline (it is not cumulative). The key will be removed from the result signal set when it expires.

Arguments

 ∷ ∀ a b. Ord b ⇒ (a → Set b) Start set signal → (a → Set b) Stop set signal → (a → Bool) Stop all signal → Signal a → Signal (Set b)