Skip to content

Commit 5f2170b

Browse files
authored
Merge pull request #75 from boydm/boyd
Add missing tests
2 parents 75038b0 + bff5466 commit 5f2170b

File tree

6 files changed

+77
-2
lines changed

6 files changed

+77
-2
lines changed

test/scenic/math/matrix_test.exs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,11 @@ defmodule Scenic.Math.MatrixTest do
384384
assert Matrix.rotate(mx_trans, 1.3) == Matrix.mul(mx_trans, mx_rot)
385385
end
386386

387+
test "rotate does nothing with nil" do
388+
mx_trans = Matrix.build_translation({123, 456})
389+
assert Matrix.rotate(mx_trans, nil) == mx_trans
390+
end
391+
387392
test "translate translates a matrix" do
388393
mx_trans = Matrix.build_translation({123, 456})
389394
mx_rot = Matrix.build_rotation(1.3)

test/scenic/primitive/quad_test.exs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,32 @@ defmodule Scenic.Primitive.QuadTest do
8181
assert Quad.contains_point?(@convex, {400, 520}) == false
8282
assert Quad.contains_point?(@convex, {100, 520}) == false
8383
end
84+
85+
# ============================================================================
86+
# expand
87+
88+
# only works if it is square...
89+
defp quad_square_area({{x0, y0}, {x1, _}, {_, y2}, _}) do
90+
w = abs(x1 - x0) * 1.0
91+
h = abs(y2 - y0) * 1.0
92+
w * h
93+
end
94+
95+
test "expand clockwise works" do
96+
quad = {{10, 10}, {20, 10}, {20, 20}, {10, 20}}
97+
expanded = Quad.expand(quad, 2)
98+
shrunk = Quad.expand(quad, -2)
99+
100+
assert quad_square_area(expanded) > quad_square_area(quad)
101+
assert quad_square_area(shrunk) < quad_square_area(quad)
102+
end
103+
104+
test "expand counter-clockwise works" do
105+
quad = {{10, 20}, {20, 20}, {20, 10}, {10, 10}}
106+
expanded = Quad.expand(quad, 2)
107+
shrunk = Quad.expand(quad, -2)
108+
109+
assert quad_square_area(expanded) > quad_square_area(quad)
110+
assert quad_square_area(shrunk) < quad_square_area(quad)
111+
end
84112
end

test/scenic/primitive/sector_test.exs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,21 @@ defmodule Scenic.Primitive.SectorTest do
5454

5555
# ============================================================================
5656
# point containment
57-
test "contains_point? always returns false" do
57+
test "contains_point? works (clockwise)" do
5858
assert Sector.contains_point?(@data, {20, 32}) == true
5959
assert Sector.contains_point?(@data, {-20, 32}) == false
6060
assert Sector.contains_point?(@data, {30, 60}) == true
6161
assert Sector.contains_point?(@data, {130, 280}) == false
6262
end
6363

64+
test "contains_point? works (counter-clockwise)" do
65+
data = {100, 1.4, 0.0}
66+
assert Sector.contains_point?(data, {20, 32}) == true
67+
assert Sector.contains_point?(data, {-20, 32}) == false
68+
assert Sector.contains_point?(data, {30, 60}) == true
69+
assert Sector.contains_point?(data, {130, 280}) == false
70+
end
71+
6472
test "contains_point? straight up and down" do
6573
# make it big enough to catch the straight down case
6674
data = {100, 0.0, 2}

test/scenic/primitive/style/paint/color_test.exs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
defmodule Scenic.Primitive.Style.Paint.ColorTest do
2-
@moduledoc false
32
use ExUnit.Case, async: true
43

54
import Scenic.Primitive.Style.Paint.Color
65

6+
test "to_rgba with numbers" do
7+
assert to_rgba({1, 2, 3}) == {1, 2, 3, 0xFF}
8+
assert to_rgba({1, 2, 3, 4}) == {1, 2, 3, 4}
9+
end
10+
711
test "to_rgba/1" do
812
assert to_rgba({:transparent, nil}) == to_rgba(:transparent)
913
assert to_rgba({:clear, nil}) == to_rgba(:transparent)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
defmodule Scenic.Primitive.Style.Paint.ImageTest do
2+
use ExUnit.Case, async: true
3+
4+
alias Scenic.Primitive.Style.Paint.Image
5+
6+
test "normalize works with just a hash_key to the image" do
7+
assert Image.normalize("hash_string") == {"hash_string", 0, 0, 0, 0, 0, 0xFF}
8+
end
9+
10+
test "normalize works with just a hash_key and alpha" do
11+
assert Image.normalize({"hash_string", 128}) == {"hash_string", 0, 0, 0, 0, 0, 128}
12+
end
13+
14+
test "normalize works with everything set" do
15+
assert Image.normalize({"hash_string", 1, 2, 3, 4, 5, 6}) == {"hash_string", 1, 2, 3, 4, 5, 6}
16+
end
17+
end

test/scenic/primitive/transform_test.exs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,19 @@ defmodule Scenic.Primitive.TransformTest do
2929
matrix: @mx
3030
}
3131

32+
# ============================================================================
33+
# verify!
34+
35+
test "verify! works" do
36+
assert Transform.verify!(:pin, {1, 1})
37+
end
38+
39+
test "verify! rejects invalid transform types" do
40+
assert_raise Scenic.Primitive.Transform.FormatError, fn ->
41+
assert Transform.verify!(:invalid, {1, 1})
42+
end
43+
end
44+
3245
# ============================================================================
3346
# calculate the local matrix
3447

0 commit comments

Comments
 (0)