|
|
@@ -0,0 +1,71 @@ |
|
|
|
|
|
package point_test |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
|
"math" |
|
|
|
|
|
"testing" |
|
|
|
|
|
|
|
|
|
|
|
"git.wtrh.nl/patterns/gopatterns/pkg/point" |
|
|
|
|
|
"git.wtrh.nl/patterns/gopatterns/pkg/position" |
|
|
|
|
|
"git.wtrh.nl/patterns/gopatterns/pkg/util" |
|
|
|
|
|
"git.wtrh.nl/patterns/gopatterns/pkg/vector" |
|
|
|
|
|
"github.com/stretchr/testify/require" |
|
|
|
|
|
"github.com/tdewolff/canvas" |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
func EqualMatrix(t *testing.T, expected, actual canvas.Matrix, delta float64) { |
|
|
|
|
|
t.Helper() |
|
|
|
|
|
|
|
|
|
|
|
require.InDeltaSlice(t, expected[0][:], actual[0][:], delta) |
|
|
|
|
|
require.InDeltaSlice(t, expected[1][:], actual[1][:], delta) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestAbsolutePoint_Matrix(t *testing.T) { |
|
|
|
|
|
rotation := math.Pi/2 + 2 |
|
|
|
|
|
newPoint := point.NewAbsolutePoint(1, 2, rotation, "1") |
|
|
|
|
|
actual := newPoint.Matrix() |
|
|
|
|
|
|
|
|
|
|
|
expected := canvas.Matrix{ |
|
|
|
|
|
{math.Cos(rotation), -math.Sin(rotation), 1.0}, |
|
|
|
|
|
{math.Sin(rotation), math.Cos(rotation), 2.0}, |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
EqualMatrix(t, actual, expected, 1e-10) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestAbsolutePoint_ID(t *testing.T) { |
|
|
|
|
|
newPoint := point.NewAbsolutePoint(1, 2, 3, "this is a test value") |
|
|
|
|
|
require.Equal(t, util.ID("this is a test value"), newPoint.ID()) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestAbsolutePoint_Name(t *testing.T) { |
|
|
|
|
|
require.Equal(t, "this is a test value", point.NewAbsolutePoint(1, 2, 3, "this is a test value").Name()) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestAbsolutePoint_Position(t *testing.T) { |
|
|
|
|
|
actual := point.NewAbsolutePoint(1, 2, 3, "this is a test value").Position() |
|
|
|
|
|
expected := position.Position{ |
|
|
|
|
|
Vector: vector.Vector{X: 1, Y: 2}, |
|
|
|
|
|
Rotation: 3, |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
require.Equal(t, expected, actual) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestAbsolutePoint_Draw(t *testing.T) { |
|
|
|
|
|
newPoint := point.NewAbsolutePoint(1, 2, 3, "this is a test value") |
|
|
|
|
|
require.False(t, newPoint.Draw()) |
|
|
|
|
|
|
|
|
|
|
|
newPoint.SetDraw() |
|
|
|
|
|
require.True(t, newPoint.Draw()) |
|
|
|
|
|
|
|
|
|
|
|
newPoint.UnsetDraw() |
|
|
|
|
|
require.False(t, newPoint.Draw()) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestAbsolutePoint_Hide(t *testing.T) { |
|
|
|
|
|
newPoint := point.NewAbsolutePoint(1, 2, 3, "this is a test value") |
|
|
|
|
|
require.False(t, newPoint.Hide()) |
|
|
|
|
|
|
|
|
|
|
|
newPoint.SetHide() |
|
|
|
|
|
require.True(t, newPoint.Hide()) |
|
|
|
|
|
} |