Table of Contents

Class MeasurementSet

Namespace
MetricsAssertions
Assembly
MetricsAssertions.dll

An immutable, queryable set of captured measurements - the core unit assertions are written against. Produced by an InstrumentCapture or MeterCapture and narrowed with Tagged(string, object?) / ForInstrument(string). Exposes counter-style aggregates (Total), histogram-style aggregates (Sum/Min/Max/ Average), the raw Values and All measurements, and a deterministic ToSnapshotString() projection for snapshot-style baselines.

public sealed class MeasurementSet
Inheritance
MeasurementSet
Inherited Members
Extension Methods

Constructors

MeasurementSet(IEnumerable<CapturedMeasurement>)

Creates a set over the supplied measurements (defensively copied).

public MeasurementSet(IEnumerable<CapturedMeasurement> measurements)

Parameters

measurements IEnumerable<CapturedMeasurement>

The measurements in the set.

Properties

All

Gets every measurement in the set, in capture order.

public IReadOnlyList<CapturedMeasurement> All { get; }

Property Value

IReadOnlyList<CapturedMeasurement>

Average

Gets the mean of all values (0 when empty).

public double Average { get; }

Property Value

double

Count

Gets the number of measurements in the set.

public int Count { get; }

Property Value

int

Empty

An empty set.

public static MeasurementSet Empty { get; }

Property Value

MeasurementSet

IsEmpty

Gets whether the set contains no measurements.

public bool IsEmpty { get; }

Property Value

bool

LastValue

Gets the most recently captured value, or null when the set is empty.

public double? LastValue { get; }

Property Value

double?

Max

Gets the largest value (0 when empty).

public double Max { get; }

Property Value

double

Min

Gets the smallest value (0 when empty).

public double Min { get; }

Property Value

double

Sum

Gets the sum of all values (0 when empty).

public double Sum { get; }

Property Value

double

Total

Gets the net total of all values as a long (a counter / up-down-counter total).

public long Total { get; }

Property Value

long

Remarks

The sum is rounded to the nearest long using banker's rounding (round half to even), so a Counter<double> whose values sum to a fractional total is evaluated as an integer. For an exact fractional total compare Sum directly, or use the histogram aggregate HasSampleSum(expected, tolerance) on the measurement set.

Values

Gets the individual measured values, in capture order.

public IReadOnlyList<double> Values { get; }

Property Value

IReadOnlyList<double>

Methods

AllValuesInRange(double, double)

Returns whether all values lie within the inclusive range [min, max].

public bool AllValuesInRange(double min, double max)

Parameters

min double

The inclusive lower bound.

max double

The inclusive upper bound.

Returns

bool

Describe()

Renders every measurement on its own line (instrument, value, tags, timestamp) in capture order for failure diagnostics, or a placeholder when the set is empty. Unlike ToSnapshotString() (sorted, for stable baselines), this preserves capture order and carries timestamps.

public string Describe()

Returns

string

EveryMeasurementCarriesTag(string)

Returns whether every measurement in the set carries a tag with the given key.

public bool EveryMeasurementCarriesTag(string key)

Parameters

key string

The tag key that must be present on every measurement.

Returns

bool

ForInstrument(string)

Returns the subset emitted by the named instrument.

public MeasurementSet ForInstrument(string instrumentName)

Parameters

instrumentName string

The instrument name to filter by.

Returns

MeasurementSet

SamplesEqual(IReadOnlyList<double>, double)

Returns whether the values equal expected in order, each within tolerance (absolute).

public bool SamplesEqual(IReadOnlyList<double> expected, double tolerance)

Parameters

expected IReadOnlyList<double>

The expected samples, in order.

tolerance double

The allowed absolute difference per sample.

Returns

bool

Exceptions

ArgumentOutOfRangeException

tolerance is negative or non-finite.

SamplesEqual(params double[])

Returns whether the values equal expected in order.

public bool SamplesEqual(params double[] expected)

Parameters

expected double[]

The expected samples, in order.

Returns

bool

SamplesEquivalentTo(IReadOnlyList<double>, double)

Returns whether the values equal expected regardless of order, each within tolerance (absolute). Both sequences are sorted and compared element by element, so equal counts and pairwise-within-tolerance values match.

public bool SamplesEquivalentTo(IReadOnlyList<double> expected, double tolerance)

Parameters

expected IReadOnlyList<double>

The expected samples, in any order.

tolerance double

The allowed absolute difference per sample.

Returns

bool

Exceptions

ArgumentOutOfRangeException

tolerance is negative or non-finite.

SamplesEquivalentTo(params double[])

Returns whether the values equal expected regardless of order.

public bool SamplesEquivalentTo(params double[] expected)

Parameters

expected double[]

The expected samples, in any order.

Returns

bool

Tagged(string, object?)

Returns the subset whose measurements carry a tag key equal to value.

public MeasurementSet Tagged(string key, object? value)

Parameters

key string

The tag key to match.

value object

The tag value to match (string-compared invariantly).

Returns

MeasurementSet

Tagged(params (string Key, object? Value)[])

Returns the subset whose measurements carry all of the supplied tags.

public MeasurementSet Tagged(params (string Key, object? Value)[] tags)

Parameters

tags (string Key, object Value)[]

The tags that must all be present and equal.

Returns

MeasurementSet

ToSnapshotString()

Returns a deterministic, human-readable projection of the set (one line per measurement, sorted by instrument, value, then tags) suitable for snapshot-style baselines via a snapshot assertion library.

public string ToSnapshotString()

Returns

string