Julian Noble
2 years ago
3 changed files with 43 additions and 5 deletions
@ -1,6 +1,25 @@
|
||||
defmodule Tetris do |
||||
alias Tetris.{Bottom, Brick, Points} |
||||
|
||||
def hello do |
||||
:world |
||||
def prepare(brick) do |
||||
brick |
||||
|> Brick.prepare |
||||
|> Points.move_to_location(brick.location) |
||||
|
||||
end |
||||
|
||||
def try_move(brick, bottom, f) do |
||||
new_brick = f.(brick) |
||||
|
||||
if Bottom.collides?(bottom, prepare(new_brick)) do |
||||
brick |
||||
else |
||||
new_brick |
||||
end |
||||
end |
||||
|
||||
def try_left(brick, bottom), do: try_move(brick,bottom, &Brick.left/1) |
||||
def try_right(brick, bottom), do: try_move(brick,bottom, &Brick.right/1) |
||||
def try_spin(brick, bottom), do: try_move(brick,bottom, &Brick.spin_90/1) |
||||
|
||||
end |
||||
|
@ -1,7 +1,26 @@
|
||||
defmodule TetrisTest do |
||||
use ExUnit.Case |
||||
import Tetris |
||||
alias Tetris.{Brick} |
||||
|
||||
test "greets the world" do |
||||
assert Tetris.hello() == :world |
||||
test "try to move right, success" do |
||||
brick = Brick.new(%{location: {5,1}}) |
||||
bottom = %{} |
||||
|
||||
expected = brick |> Brick.right |
||||
actual = try_right(brick, bottom) |
||||
|
||||
assert actual == expected |
||||
end |
||||
|
||||
test "try to move right, failure returns original brick " do |
||||
brick = Brick.new(%{location: {8,1}}) |
||||
bottom = %{} |
||||
|
||||
actual = try_right(brick, bottom) |
||||
|
||||
assert actual == brick |
||||
end |
||||
|
||||
|
||||
end |
||||
|
Loading…
Reference in new issue