From 876b4ac1488f23b660e31ba617e7f268a25be86e Mon Sep 17 00:00:00 2001 From: Thomas Rudin Date: Sun, 20 Jan 2019 20:10:48 +0100 Subject: [PATCH] more testing --- coords/convert_test.go | 10 +--- coords/tileconvert_test.go | 94 ++++++++++++++++++++++++++++++++++++++ go.mod | 3 ++ go.sum | 4 ++ 4 files changed, 103 insertions(+), 8 deletions(-) create mode 100644 coords/tileconvert_test.go diff --git a/coords/convert_test.go b/coords/convert_test.go index 180a4d6..15c3e7a 100644 --- a/coords/convert_test.go +++ b/coords/convert_test.go @@ -1,8 +1,9 @@ package coords import ( - "github.com/sirupsen/logrus" "testing" + + "github.com/sirupsen/logrus" ) var log *logrus.Entry @@ -33,10 +34,3 @@ func testCoordConvert(t *testing.T, mb MapBlockCoords) { } } - -func TestConvertPlainMapBlock(t *testing.T) { - testCoordConvert(t, NewMapBlockCoords(10, 0, -10)) - testCoordConvert(t, NewMapBlockCoords(-2048, 2047, -10)) - testCoordConvert(t, NewMapBlockCoords(-3, 0, 2047)) //0...2047 - -} diff --git a/coords/tileconvert_test.go b/coords/tileconvert_test.go new file mode 100644 index 0000000..1368830 --- /dev/null +++ b/coords/tileconvert_test.go @@ -0,0 +1,94 @@ +package coords + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestConvertMapblockToTile1(t *testing.T) { + mbc := NewMapBlockCoords(0, 0, 0) + tc := GetTileCoordsFromMapBlock(mbc) + + if tc.X != 0 { + t.Fatal("x does not match") + } + + if tc.Y != -1 { + t.Fatal("y does not match") + } + + if tc.Zoom != 13 { + t.Fatal("zoom does not match") + } +} + +func TestGetMapBlockRangeFromTile(t *testing.T) { + r := GetMapBlockRangeFromTile(NewTileCoords(0, 0, 13, 0), 0) + assert.Equal(t, r.Pos1.X, 0) + assert.Equal(t, r.Pos1.Z, -1) + assert.Equal(t, r.Pos2.X, 0) + assert.Equal(t, r.Pos2.Z, -1) + + r = GetMapBlockRangeFromTile(NewTileCoords(-1, -1, 13, 0), 0) + assert.Equal(t, r.Pos1.X, -1) + assert.Equal(t, r.Pos1.Z, 0) + assert.Equal(t, r.Pos2.X, -1) + assert.Equal(t, r.Pos2.Z, 0) +} + +func TestConvertMapblockToTile2(t *testing.T) { + mbc := NewMapBlockCoords(1, 0, 1) + tc := GetTileCoordsFromMapBlock(mbc) + + if tc.X != 1 { + t.Fatal("x does not match") + } + + if tc.Y != -2 { + t.Fatal("y does not match") + } + + if tc.Zoom != 13 { + t.Fatal("zoom does not match") + } +} + +func TestConvertMapblockToTile3(t *testing.T) { + mbc := NewMapBlockCoords(-1, 0, -1) + tc := GetTileCoordsFromMapBlock(mbc) + + if tc.X != -1 { + t.Fatal("x does not match") + } + + if tc.Y != 0 { + t.Fatal("y does not match") + } + + if tc.Zoom != 13 { + t.Fatal("zoom does not match") + } +} + +func TestZoomedQuadrantsFromTile(t *testing.T) { + tc := NewTileCoords(0, 0, 12, 0) + q := tc.GetZoomedQuadrantsFromTile() + + assert.Equal(t, q.UpperLeft.X, 0) + assert.Equal(t, q.UpperLeft.Y, 0) + assert.Equal(t, q.UpperLeft.Zoom, 13) + + assert.Equal(t, q.UpperRight.X, 1) + assert.Equal(t, q.UpperRight.Y, 0) + assert.Equal(t, q.UpperRight.Zoom, 13) + + assert.Equal(t, q.LowerLeft.X, 0) + assert.Equal(t, q.LowerLeft.Y, 1) + assert.Equal(t, q.LowerLeft.Zoom, 13) + + assert.Equal(t, q.LowerRight.X, 1) + assert.Equal(t, q.LowerRight.Y, 1) + assert.Equal(t, q.LowerRight.Zoom, 13) + +} diff --git a/go.mod b/go.mod index 82788a7..2521c65 100644 --- a/go.mod +++ b/go.mod @@ -1,10 +1,13 @@ module mapserver require ( + github.com/google/go-cmp v0.2.0 // indirect github.com/google/pprof v0.0.0-20190109223431-e84dfd68c163 // indirect github.com/mattn/go-sqlite3 v1.10.0 github.com/mjibson/esc v0.1.0 // indirect github.com/patrickmn/go-cache v2.1.0+incompatible github.com/sirupsen/logrus v1.3.0 + github.com/stretchr/testify v1.2.2 golang.org/x/arch v0.0.0-20181203225421-5a4828bb7045 // indirect + gotest.tools v2.2.0+incompatible ) diff --git a/go.sum b/go.sum index 26ff89c..bd5175d 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,7 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/pprof v0.0.0-20190109223431-e84dfd68c163 h1:beB+Da4k9B1zmgag78k3k1Bx4L/fdWr5FwNa0f8RxmY= github.com/google/pprof v0.0.0-20190109223431-e84dfd68c163/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= @@ -22,3 +24,5 @@ golang.org/x/crypto v0.0.0-20180904163835-0709b304e793 h1:u+LnwYTOOW7Ukr/fppxEb1 golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33 h1:I6FyU15t786LL7oL/hn43zqTuEGr4PN7F4XJ1p4E3Y8= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= +gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=