defmodule BottomTest do use ExUnit.Case import Tetris.Bottom test "Various Collisions" do bottom = %{{1,1} => {1,1, :blue}} assert collides? bottom, {1,1} refute collides? bottom, {1,2} assert collides? bottom, {1,1, :red} assert collides? bottom, {1,1, :blue} refute collides? bottom, {1,2, :red} assert collides? bottom, [{1,2, :red}, {1,1, :red}] refute collides? bottom, [{3,2, :blue}, {4,4, :red}] end test "test simple merge with bottom" do bottom = %{{1,1} => {1,1, :blue}} actual = merge bottom, [{1,2, :red}, {1,3, :red}] expected = %{ {1,1} => {1, 1, :blue}, {1,2} => {1, 2, :red}, {1,3} => {1, 3, :red} } assert actual == expected end test "compute complete ys" do bottom = new_bottom(20, [{{19, 19}, {19, 19, :red}}]) assert complete_ys(bottom) == [20] end test "collapse single row" do bottom = new_bottom(20, [{{19, 19}, {19, 19, :red}}]) actual = Map.keys(collapse_row(bottom, 20)) refute {19,19} in actual assert {19, 20} in actual assert Enum.count(actual) == 1 #IO.inspect collapse_row(bottom, 20) end test "full collapse with single row" do bottom = new_bottom(20, [{{19, 19}, {19, 19, :red}}]) {actual_count, actual_bottom} = full_collapse(bottom) assert actual_count == 1 assert {19,20} in Map.keys(actual_bottom) end def new_bottom(complete_row, xtras) do (xtras ++ (1..10 |> Enum.map( fn x -> {{x, complete_row}, {x,complete_row, :red}} end))) |> Map.new end end