Skip to content

Commit

Permalink
feat: add test for changes to room
Browse files Browse the repository at this point in the history
  • Loading branch information
dennyabrain committed Nov 19, 2024
1 parent d316424 commit d62359b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 74 deletions.
27 changes: 13 additions & 14 deletions lib/viral_spiral/entity/room.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ defmodule ViralSpiral.Entity.Room do
volatality: EngineConfig.volatility()
}

def new() do
engine_config = %EngineConfig{}

%Room{
id: UXID.generate!(prefix: "room", size: :small),
name: name(),
state: :uninitialized,
chaos_counter: engine_config.chaos_counter,
chaos: engine_config.chaos_counter,
volatality: engine_config.volatility
}
end

@doc """
Reserve a room.
Expand Down Expand Up @@ -80,19 +93,6 @@ defmodule ViralSpiral.Entity.Room do
}
end

def new() do
engine_config = %EngineConfig{}

%Room{
id: UXID.generate!(prefix: "room", size: :small),
name: name(),
state: :uninitialized,
chaos_counter: engine_config.chaos_counter,
chaos: engine_config.chaos_counter,
volatality: engine_config.volatility
}
end

def set_state(%Room{} = room, state) when state in @all_states do
%{room | state: state}
end
Expand Down Expand Up @@ -162,7 +162,6 @@ defmodule ViralSpiral.Entity.Room do
end

defimpl ViralSpiral.Entity.Change, for: ViralSpiral.Entity.Room do
alias ViralSpiral.Game.State
alias ViralSpiral.Entity.Room

@doc """
Expand Down
44 changes: 44 additions & 0 deletions test/viral_spiral/entity/room_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
defmodule ViralSpiral.Entity.RoomTest do
alias ViralSpiral.Room.EngineConfig
alias ViralSpiral.Room.ChangeDescriptions
alias ViralSpiral.Entity.Change
alias ViralSpiral.Entity.Room
use ExUnit.Case

describe "deterministic room configs" do
test "communities - yellow, red; affinities - sock, houseboat" do
:rand.seed(:exsss, {1, 8, 12})
room = Room.reserve("hello") |> Room.start(4)

assert room.name == "hello"
assert room.affinities == [:houseboat, :skub]
assert room.communities == [:red, :yellow, :blue]
assert room.chaos == 0
assert room.chaos_counter == 10
end
end

describe "changes" do
setup do
room = %Room{chaos: 4}
%{room: room}
end

test "change chaos countdown", %{room: room} do
new_room = Change.apply_change(room, ChangeDescriptions.change_chaos(5))
assert new_room.chaos == 9
end

test "pass invalid offset in change description", %{room: room} do
assert_raise ArithmeticError, fn ->
Change.apply_change(room, ChangeDescriptions.change_chaos("hi"))
end
end

test "pass opts without required fields", %{room: room} do
assert_raise ArgumentError, fn ->
Change.apply_change(room, invalid: "random")
end
end
end
end
60 changes: 0 additions & 60 deletions test/viral_spiral/room/room_test.exs

This file was deleted.

0 comments on commit d62359b

Please sign in to comment.