Machete.IntegerMatcher (Machete v0.3.11)

View Source

Defines a matcher that matches integer values

Summary

Types

Describes the arguments that can be passed to this matcher

t()

Describes an instance of this matcher

Functions

Matches against integer values

Types

opts()

@type opts() :: [
  positive: boolean(),
  strictly_positive: boolean(),
  negative: boolean(),
  strictly_negative: boolean(),
  nonzero: boolean(),
  min: integer(),
  max: integer(),
  roughly: integer(),
  epsilon: integer() | {integer(), integer()}
]

Describes the arguments that can be passed to this matcher

t()

@opaque t()

Describes an instance of this matcher

Functions

integer(opts \\ [])

@spec integer(opts()) :: t()

Matches against integer values

Takes the following arguments:

  • positive: When true, requires the matched integer be positive or zero
  • strictly_positive: When true, requires the matched integer be positive and nonzero
  • negative: When true, requires the matched integer be negative or zero
  • strictly_negative: When true, requires the matched integer be negative and nonzero
  • nonzero: When true, requires the matched integer be nonzero
  • min: Requires the matched integer be greater than or equal to the specified value
  • max: Requires the matched integer be less than or equal to the specified value
  • roughly: Requires the matched integer be within epsilon of the specified value
  • epsilon: The bound(s) to use when determining how close the matched integer needs to be to roughly. Can be specified as a single integer that is used for both lower and upper bounds, or a tuple consisting of distinct lower and upper bounds. If not specified, and if roughly is not zero, defaults to 5% of the value of roughly.

Examples:

iex> assert 1 ~> integer()
true

iex> assert 1 ~> integer(positive: true)
true

iex> assert 0 ~> integer(positive: true)
true

iex> assert -1 ~> integer(positive: false)
true

iex> refute 0 ~> integer(positive: false)
false

iex> assert 1 ~> integer(strictly_positive: true)
true

iex> refute 0 ~> integer(strictly_positive: true)
false

iex> assert -1 ~> integer(strictly_positive: false)
true

iex> assert 0 ~> integer(strictly_positive: false)
true

iex> assert -1 ~> integer(negative: true)
true

iex> assert 0 ~> integer(negative: true)
true

iex> assert 1 ~> integer(negative: false)
true

iex> refute 0 ~> integer(negative: false)
false

iex> assert -1 ~> integer(strictly_negative: true)
true

iex> refute 0 ~> integer(strictly_negative: true)
false

iex> assert 1 ~> integer(strictly_negative: false)
true

iex> assert 0 ~> integer(strictly_negative: false)
true

iex> assert 1 ~> integer(nonzero: true)
true

iex> assert 0 ~> integer(nonzero: false)
true

iex> assert 2 ~> integer(min: 2)
true

iex> assert 2 ~> integer(max: 2)
true

iex> assert 95 ~> integer(roughly: 100)
true

iex> assert -95 ~> integer(roughly: -100)
true

iex> assert 90 ~> integer(roughly: 100, epsilon: 10)
true

iex> assert -90 ~> integer(roughly: -100, epsilon: 10)
true

iex> assert 105 ~> integer(roughly: 100, epsilon: {10, 5})
true

iex> assert -110 ~> integer(roughly: -100, epsilon: {10, 5})
true

iex> refute 94 ~> integer(roughly: 100)
false

iex> refute 89 ~> integer(roughly: 100, epsilon: 10)
false

iex> refute 106 ~> integer(roughly: 100, epsilon: {10, 5})
false