# `Supertester.Assertions`
[🔗](https://github.com/nshkrdotcom/supertester/blob/v0.6.0/lib/supertester/assertions.ex#L1)

Custom assertions for OTP patterns and system behavior.

This module provides specialized assertions that understand OTP patterns,
making tests more expressive and providing better error messages.

## Usage

    import Supertester.Assertions

    test "my test" do
      assert_process_alive(server_pid)
      assert_genserver_responsive(server_pid)
    end

# `pid_set`

```elixir
@type pid_set() :: %{optional(pid()) =&gt; true}
```

# `assert_all_children_alive`

```elixir
@spec assert_all_children_alive(Supervisor.supervisor()) :: :ok
```

Asserts that all children of a supervisor are alive.

## Parameters

- `supervisor` - The supervisor pid or name

## Example

    assert_all_children_alive(supervisor)

# `assert_child_count`

```elixir
@spec assert_child_count(Supervisor.supervisor(), non_neg_integer()) :: :ok
```

Asserts that a supervisor has the expected number of children.

## Parameters

- `supervisor` - The supervisor pid or name
- `expected_count` - The expected number of children

## Example

    assert_child_count(supervisor, 3)

# `assert_genserver_handles_message`

```elixir
@spec assert_genserver_handles_message(GenServer.server(), term(), term()) :: :ok
```

Asserts that a GenServer handles a message correctly.

## Parameters

- `server` - The GenServer pid or name
- `message` - The message to send
- `expected_response` - The expected response

## Example

    assert_genserver_handles_message(server, :get_counter, {:ok, 5})

# `assert_genserver_responsive`

```elixir
@spec assert_genserver_responsive(GenServer.server()) :: :ok
```

Asserts that a GenServer is responsive.

## Parameters

- `server` - The GenServer pid or name

## Example

    assert_genserver_responsive(server)

# `assert_genserver_state`

```elixir
@spec assert_genserver_state(GenServer.server(), term() | (term() -&gt; boolean())) ::
  :ok
```

Asserts that a GenServer has the expected state.

## Parameters

- `server` - The GenServer pid or name
- `expected_state` - The expected state or a function to test the state

## Example

    assert_genserver_state(server, %{counter: 5})
    assert_genserver_state(server, fn state -> state.counter > 0 end)

# `assert_memory_usage_stable`

```elixir
@spec assert_memory_usage_stable((-&gt; any()), float()) :: :ok
```

Asserts that memory usage remains stable during an operation.

## Parameters

- `operation_fun` - Function to execute
- `tolerance` - Memory tolerance as a percentage (default: 0.1)

## Example

    assert_memory_usage_stable(fn -> 
      Enum.each(1..1000, fn _ -> GenServer.call(server, :increment) end)
    end, 0.05)

# `assert_no_process_leaks`

```elixir
@spec assert_no_process_leaks((-&gt; any())) :: :ok
```

Asserts that no processes are leaked during an operation.

## Parameters

- `operation_fun` - Function to execute

## Example

    assert_no_process_leaks(fn ->
      {:ok, server} = GenServer.start_link(MyServer, [])
      GenServer.stop(server)
    end)

# `assert_performance_within_bounds`

```elixir
@spec assert_performance_within_bounds(map(), map()) :: :ok
```

Asserts that performance is within expected bounds.

## Parameters

- `benchmark_result` - Result from performance testing
- `expectations` - Map of performance expectations

## Example

    expectations = %{max_time: 1000, max_memory: 1_000_000}
    assert_performance_within_bounds(result, expectations)

# `assert_process_alive`

```elixir
@spec assert_process_alive(pid()) :: :ok
```

Asserts that a process is alive.

## Parameters

- `pid` - The process ID to check

## Example

    assert_process_alive(server_pid)

# `assert_process_dead`

```elixir
@spec assert_process_dead(pid()) :: :ok
```

Asserts that a process is dead.

## Parameters

- `pid` - The process ID to check

## Example

    assert_process_dead(old_pid)

# `assert_process_restarted`

```elixir
@spec assert_process_restarted(atom(), pid()) :: :ok
```

Asserts that a process has been restarted.

## Parameters

- `process_name` - The registered name of the process
- `original_pid` - The original PID before restart

## Example

    original_pid = GenServer.whereis(MyServer)
    GenServer.stop(MyServer)
    assert_process_restarted(MyServer, original_pid)

# `assert_supervisor_strategy`

```elixir
@spec assert_supervisor_strategy(Supervisor.supervisor(), atom()) :: :ok
```

Asserts that a supervisor is accessible and running.

This function validates the runtime supervisor strategy by inspecting the
supervisor state through OTP system introspection APIs.

## Parameters

- `supervisor` - The supervisor pid or name
- `expected_strategy` - The expected strategy (:one_for_one, :one_for_all, :rest_for_one, :simple_one_for_one)

## Example

    assert_supervisor_strategy(supervisor, :one_for_one)

---

*Consult [api-reference.md](api-reference.md) for complete listing*
