Skip to content

Commit

Permalink
Refactor test
Browse files Browse the repository at this point in the history
  • Loading branch information
camelpunch committed Nov 2, 2024
1 parent 6c3faef commit 678e7eb
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions test/mudbrick/drawing_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,12 @@ defmodule Mudbrick.DrawingTest do
import Path

assert [] =
output(fn ->
operations(fn ->
new()
end)
|> operations()
end

test "can fill a rectangle" do
test "can render a rectangle" do
import Path

assert [
Expand All @@ -85,11 +84,10 @@ defmodule Mudbrick.DrawingTest do
"0 0 50 75 re",
"S"
] =
output(fn ->
operations(fn ->
new()
|> rectangle(lower_left: {0, 0}, dimensions: {50, 75})
end)
|> operations()
end

test "can draw one path" do
Expand All @@ -102,11 +100,10 @@ defmodule Mudbrick.DrawingTest do
"460 750 l",
"S"
] =
output(fn ->
operations(fn ->
new()
|> straight_line(from: {0, 650}, to: {460, 750})
end)
|> operations()
end

test "can choose line width" do
Expand All @@ -119,11 +116,10 @@ defmodule Mudbrick.DrawingTest do
"460 750 l",
"S"
] =
output(fn ->
operations(fn ->
new()
|> straight_line(from: {0, 650}, to: {460, 750}, line_width: 4.0)
end)
|> operations()
end

test "can choose colour" do
Expand All @@ -136,11 +132,10 @@ defmodule Mudbrick.DrawingTest do
"460 750 l",
"S"
] =
output(fn ->
operations(fn ->
new()
|> straight_line(from: {0, 650}, to: {460, 750}, colour: {0, 1, 0})
end)
|> operations()
end

property "it's an error to set a colour above 1" do
Expand All @@ -158,9 +153,9 @@ defmodule Mudbrick.DrawingTest do
end
end

defp output(f), do: output(fn _ -> f.() end, Mudbrick.Path.Output)

defp operations(ops) do
Enum.map(ops, &Mudbrick.TestHelper.show/1) |> Enum.reverse()
defp operations(f) do
output(fn _ -> f.() end, Mudbrick.Path.Output)
|> Enum.map(&Mudbrick.TestHelper.show/1)
|> Enum.reverse()
end
end

0 comments on commit 678e7eb

Please sign in to comment.