From 0f1106eb3b9f2d3362d38c1322c7d0421f675062 Mon Sep 17 00:00:00 2001 From: graciousgrey Date: Wed, 20 Sep 2023 21:48:55 +0200 Subject: [PATCH] Tests: Add unit tests --- pkg/clean/gps_test.go | 16 ++++++++++++++ pkg/s2/s2_test.go | 51 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/pkg/clean/gps_test.go b/pkg/clean/gps_test.go index 3b3033189..cc2b9528d 100644 --- a/pkg/clean/gps_test.go +++ b/pkg/clean/gps_test.go @@ -63,6 +63,22 @@ func TestGPSBounds(t *testing.T) { assert.Equal(t, float32(0), lngWest) assert.Error(t, err) }) + t.Run("Invalid", func(t *testing.T) { + latNorth, lngEast, latSouth, lngWest, err := GPSBounds("95.87760543823242,-197.62521362304688,98.89404296875,-197.6215591430664") + assert.Equal(t, float32(90.0001), latNorth) + assert.Equal(t, float32(89.9999), latSouth) + assert.Equal(t, float32(-180.0001), lngWest) + assert.Equal(t, float32(-179.9999), lngEast) + assert.NoError(t, err) + }) + t.Run("Invalid2", func(t *testing.T) { + latNorth, lngEast, latSouth, lngWest, err := GPSBounds("-95.87760543823242,197.62521362304688,-98.89404296875,197.6215591430664") + assert.Equal(t, float32(-89.9999), latNorth) + assert.Equal(t, float32(-90.0001), latSouth) + assert.Equal(t, float32(179.9999), lngWest) + assert.Equal(t, float32(180.0001), lngEast) + assert.NoError(t, err) + }) } func TestGPSLatRange(t *testing.T) { diff --git a/pkg/s2/s2_test.go b/pkg/s2/s2_test.go index 5670b8e62..88bf97783 100644 --- a/pkg/s2/s2_test.go +++ b/pkg/s2/s2_test.go @@ -118,6 +118,57 @@ func TestLevel(t *testing.T) { t.Run("0", func(t *testing.T) { assert.Equal(t, 21, Level(0)) }) + t.Run("3999", func(t *testing.T) { + assert.Equal(t, 1, Level(3999)) + }) + t.Run("1825", func(t *testing.T) { + assert.Equal(t, 2, Level(1825)) + }) + t.Run("1500", func(t *testing.T) { + assert.Equal(t, 3, Level(1500)) + }) + t.Run("600", func(t *testing.T) { + assert.Equal(t, 4, Level(600)) + }) + t.Run("100", func(t *testing.T) { + assert.Equal(t, 7, Level(100)) + }) + t.Run("40", func(t *testing.T) { + assert.Equal(t, 8, Level(40)) + }) + t.Run("25", func(t *testing.T) { + assert.Equal(t, 9, Level(25)) + }) + t.Run("10", func(t *testing.T) { + assert.Equal(t, 10, Level(10)) + }) + t.Run("5", func(t *testing.T) { + assert.Equal(t, 11, Level(5)) + }) + t.Run("3", func(t *testing.T) { + assert.Equal(t, 12, Level(3)) + }) + t.Run("1.5", func(t *testing.T) { + assert.Equal(t, 13, Level(1.5)) + }) + t.Run("0.5", func(t *testing.T) { + assert.Equal(t, 14, Level(0.5)) + }) + t.Run("0.15", func(t *testing.T) { + assert.Equal(t, 16, Level(0.15)) + }) + t.Run("0.03", func(t *testing.T) { + assert.Equal(t, 18, Level(0.03)) + }) + t.Run("0.015", func(t *testing.T) { + assert.Equal(t, 19, Level(0.015)) + }) + t.Run("0.008", func(t *testing.T) { + assert.Equal(t, 20, Level(0.008)) + }) + t.Run("445", func(t *testing.T) { + assert.Equal(t, 5, Level(445)) + }) t.Run("Negative", func(t *testing.T) { assert.Equal(t, 21, Level(-1)) })