# `Juggernaut.Compare`
[🔗](https://github.com/holsee/juggernaut/blob/v0.4.0/lib/juggernaut/compare.ex#L1)

Compares two sides mutant by mutant (`mix juggernaut.compare`, design notes §3): two
recorded runs, or an imported report (`Juggernaut.Import.MTE`, the baseline A) and a run
(B).

Pairing: two runs pair by canonical mutant key. A report's ids are run-local, so a
report pairs by location: first by file, start, end, operator family and replacement
(whitespace ignored, and the tool's own name, `mutare` or `juggernaut`, read as one),
then, for what is left, by file, start, end and family where exactly one mutant on each
side remains. Then, where the tools place a mutant differently (B7), the near passes:
the same family on the same line, as many on each side, paired in column order (a
convention column one apart, pattern_wildcard at the clause start or at each
variable); then the one mutant of a family left in a file on each side, at most three
lines apart (a pipe's call_removal). `near` counts these. The rest is listed as
unpaired on each side.

Statuses are compared as scored: with `timeouts: :survived` (the configuration's
`timeouts`, design notes §16) a timeout kill, on either side and from a run or a report,
is scored as survived; with `:killed` (the default) it is a kill. Each entry keeps its
recorded status and kill kind and gains a `scored` status.

A status change is a pair whose scored statuses differ. The blocking class is a pair
scored killed in A and not killed in B, whatever B's status (survived, a timeout scored
as survived, not covered, pending, ignored, equivalent, a compile or harness error), on
core code (core on either side): the baseline caught it, the new side did not, and a
side that never ran the mutant has not caught it. It is listed first.

Scores, from the scored statuses, are given under both formulas: Stryker's (killed /
(killed + survived + no coverage), which Juggernaut uses) and Mutare's (no coverage left
out). Times: the wall and phase clocks each run measured, and the per-mutant durations
of the pairs both sides ran (not reused), as recorded.

Test lanes (E1): each entry keeps its kill's `test_lane` (`nil` for an imported report
but one Juggernaut exported, whose `juggernaut.test_lane` is read). Each side counts its
kills, as scored, that only an integration test made (`integration_only`), and
`lane_changes` lists the pairs killed on both sides whose lanes differ, both known: a
mutant a unit test killed in A and only an integration test in B (`to: :integration`)
is a unit test that no longer catches it, though the gate still counts it killed.

# `entry`

```elixir
@type entry() :: %{
  id: String.t(),
  key: String.t() | nil,
  file: String.t(),
  line: pos_integer(),
  column: pos_integer(),
  end: {pos_integer(), pos_integer()},
  operator: String.t(),
  variant: String.t() | nil,
  replacement: String.t(),
  status: Juggernaut.Result.status(),
  kill_kind: Juggernaut.Result.kill_kind() | nil,
  test_lane: Juggernaut.Result.test_lane() | nil,
  duration_ms: non_neg_integer(),
  reused?: boolean(),
  core?: boolean(),
  doubt?: boolean()
}
```

One mutant on one side. `compare/3` adds `scored`, its status as scored.

# `side`

```elixir
@type side() :: %{
  kind: :run | :report,
  label: String.t(),
  entries: [entry()],
  phases: [{String.t(), non_neg_integer()}],
  wall_ms: non_neg_integer() | nil
}
```

One side: a run or an imported report.

# `t`

```elixir
@type t() :: map()
```

# `compare`

```elixir
@spec compare(side(), side(), [{:timeouts, :killed | :survived}]) :: t()
```

Compares side `a` (the baseline) with side `b`. `opts`: `timeouts` (`:killed`, the
default, or `:survived`), how timeout kills are scored on both sides.

# `side`

```elixir
@spec side(Juggernaut.Run.t()) :: side()
```

The comparison side of a run.

---

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