///- --package .

activity (test)

test activity: prelude
///- --test static --symbol

:< testing
:== counts =
    {
        server_potions : i32
        own_potions : i32
        own_other : i32
        retreats : i32
        gated_walks : i32
        allowed : option i32
        dropped : option i32
    }

:= foreign_potions (c : counts) : i32 = c::server_potions - c::own_potions

:= own_actions (c : counts) : i32 = c::own_potions + c::own_other + c::retreats + c::gated_walks

:= foreign_actions (c : counts) : option i32 =
    ?= c::allowed, c::dropped ?|
    | Some allowed, Some dropped => Some (allowed + dropped - own_actions c)
    | _ => None

:= checked_counts (server : i32) : counts =
    {
        server_potions = server
        own_potions = 5
        own_other = 9
        retreats = 2
        gated_walks = 1
        allowed = Some 15
        dropped = Some 2
    }

foreign_activity_follows_the_arena_check (test)

test foreign_activity_follows_the_arena_check: passed
///- --test --symbol
///> c
///> lua
///> gleam

:= ~server = 6i32
:= c = checked_counts server
foreign_potions c |> _assert_eq 1i32
own_actions c |> _assert_eq 17i32
.c (c)
__assert_eq { expected = 1 }
__assert_eq { expected = 17 }
.gleam (gleam)
__assert_eq { expected = 1 }
__assert_eq { expected = 17 }
lua: unavailable on this machine (`spiral lua --lua-path /tmp/spiral_cells/1793692008893-3/main.lua` was not found)

foreign_actions_need_both_parity_counters (test)

test foreign_actions_need_both_parity_counters: passed
///- --test --symbol
///> c
///> lua
///> gleam

:= ~server = 6i32
:= c = checked_counts server
foreign_actions c |> _assert_eq (Some 0i32)
foreign_actions { c ?| allowed = None } |> _assert_eq None
.c (c)
__assert_eq { expected = Some(0) }
__assert_eq { expected = None }
.gleam (gleam)
__assert_eq { expected = Some(0) }
__assert_eq { expected = None }
lua: unavailable on this machine (`spiral lua --lua-path /tmp/spiral_cells/1793692008929-35/main.lua` was not found)