ExDataCheck.ExpectationResult (ExDataCheck v0.2.1)

View Source

Represents the result of executing a single expectation against a dataset.

An ExpectationResult contains:

  • success: Boolean indicating if the expectation was met
  • expectation: Human-readable description of what was expected
  • observed: Map containing observed values, failing values, and examples
  • metadata: Additional context from the expectation

Examples

iex> result = ExDataCheck.ExpectationResult.new(
...>   true,
...>   "column age values between 0 and 120",
...>   %{total_values: 100, failing_values: 0}
...> )
iex> result.success
true
iex> ExDataCheck.ExpectationResult.success?(result)
true

iex> result = ExDataCheck.ExpectationResult.new(
...>   false,
...>   "column age values between 0 and 120",
...>   %{total_values: 100, failing_values: 2, failing_examples: [150, 200]}
...> )
iex> result.success
false
iex> ExDataCheck.ExpectationResult.failed?(result)
true

Observed Data Structure

The observed field typically contains:

  • total_values: Total number of values checked
  • failing_values: Number of values that failed the expectation
  • failing_examples: Sample of failing values (usually first 5)
  • Additional metrics specific to the expectation type

Summary

Types

Observed data from expectation validation.

t()

Functions

Returns true if the expectation failed.

Creates a new ExpectationResult.

Returns true if the expectation was met.

Types

observed()

@type observed() :: map()

Observed data from expectation validation.

Common fields:

  • :total_values - Total values validated
  • :failing_values - Count of failing values
  • :failing_examples - Sample of failing values
  • :passing_values - Count of passing values (optional)
  • Type-specific metrics (mean, median, etc.)

t()

@type t() :: %ExDataCheck.ExpectationResult{
  expectation: String.t(),
  metadata: map(),
  observed: observed(),
  success: boolean()
}

Functions

failed?(expectation_result)

@spec failed?(t()) :: boolean()

Returns true if the expectation failed.

Examples

iex> result = ExDataCheck.ExpectationResult.new(true, "test", %{})
iex> ExDataCheck.ExpectationResult.failed?(result)
false

iex> result = ExDataCheck.ExpectationResult.new(false, "test", %{})
iex> ExDataCheck.ExpectationResult.failed?(result)
true

new(success, expectation, observed, metadata \\ %{})

@spec new(boolean(), String.t(), observed(), map()) :: t()

Creates a new ExpectationResult.

Parameters

  • success - Boolean indicating if the expectation was met
  • expectation - Human-readable description of the expectation
  • observed - Map of observed values and metrics
  • metadata - Optional metadata from the expectation (defaults to empty map)

Examples

iex> ExDataCheck.ExpectationResult.new(
...>   true,
...>   "column age values between 0 and 120",
...>   %{total_values: 100, failing_values: 0}
...> )
%ExDataCheck.ExpectationResult{
  success: true,
  expectation: "column age values between 0 and 120",
  observed: %{total_values: 100, failing_values: 0},
  metadata: %{}
}

iex> ExDataCheck.ExpectationResult.new(
...>   false,
...>   "column age not null",
...>   %{total_values: 100, null_count: 5},
...>   %{column: :age}
...> )
%ExDataCheck.ExpectationResult{
  success: false,
  expectation: "column age not null",
  observed: %{total_values: 100, null_count: 5},
  metadata: %{column: :age}
}

success?(expectation_result)

@spec success?(t()) :: boolean()

Returns true if the expectation was met.

Examples

iex> result = ExDataCheck.ExpectationResult.new(true, "test", %{})
iex> ExDataCheck.ExpectationResult.success?(result)
true

iex> result = ExDataCheck.ExpectationResult.new(false, "test", %{})
iex> ExDataCheck.ExpectationResult.success?(result)
false