From 6bda5dd4eee39b05d6173fa1bc21d2df18a3dcfc Mon Sep 17 00:00:00 2001 From: sergio garcia Date: Sun, 6 Oct 2019 20:36:02 -0400 Subject: [PATCH] test(util): add tests for util/geometry --- component/util/geometry_test.go | 52 +++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 component/util/geometry_test.go diff --git a/component/util/geometry_test.go b/component/util/geometry_test.go new file mode 100644 index 0000000..a9f21f5 --- /dev/null +++ b/component/util/geometry_test.go @@ -0,0 +1,52 @@ +package util + +import "testing" +import "image" + +func TestGetRectLeftSideCenter(t *testing.T) { + rect := image.Rect(10, 10, 20, 20) + expected := image.Point{ + X: 10, + Y: 15, + } + result := GetRectLeftSideCenter(rect) + if result != expected { + t.Errorf("GetRectLeftSideCenter was incorrect. Expected %v, got %v.", expected, result) + } +} + +func TestGetRectRightSideCenter(t *testing.T) { + rect := image.Rect(10, 10, 20, 21) + expected := image.Point{ + X: 20, + Y: 15, + } + result := GetRectRightSideCenter(rect) + if result != expected { + t.Errorf("GetRectRightSideCenter was incorrect. Expected %v, got %v.", expected, result) + } +} + +func TestGetRectTopSideCenter(t *testing.T) { + rect := image.Rect(10, 10, 20, 20) + expected := image.Point{ + X: 15, + Y: 10, + } + result := GetRectTopSideCenter(rect) + if result != expected { + t.Errorf("GetRectTopSideCenter was incorrect. Expected %v, got %v.", expected, result) + } +} + +func TestGetRectBottomSideCenter(t *testing.T) { + rect := image.Rect(10, 9, 20, 20) + expected := image.Point{ + X: 15, + Y: 20, + } + result := GetRectBottomSideCenter(rect) + if result != expected { + t.Errorf("GetRectBottomSideCenter was incorrect. Expected %v, got %v.", expected, result) + } +}