go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/sdk/quad/zone_test.go (about) 1 /* 2 3 Copyright (c) 2023 - Present. Will Charczuk. All rights reserved. 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository. 5 6 */ 7 8 package quad 9 10 import ( 11 "testing" 12 13 "go.charczuk.com/sdk/assert" 14 ) 15 16 func Test_DecodeZoneHigh(t *testing.T) { 17 zone := EncodeZone(NW, SE, SE, SE) 18 zoneNext := DecodeZoneHigh(zone) 19 assert.ItsEqual(t, 'C', zoneNext) 20 zone = Zone("BBB") 21 zoneNext = DecodeZoneHigh(zone) 22 assert.ItsEqual(t, 'B', zoneNext) 23 } 24 25 func Test_ShiftZone(t *testing.T) { 26 zone4 := Zone(NW) // depth 0 27 zone3 := AppendZone(zone4, SE) // depth 1 28 zone2 := AppendZone(zone3, SE) // depth 2 29 zone := AppendZone(zone2, SE) // depth 3 30 31 next := DecodeZoneHigh(zone) 32 assert.ItsEqual(t, NW, next) 33 34 zone = ShiftZone(zone) 35 36 next = DecodeZoneHigh(zone) 37 assert.ItsEqual(t, SE, next) 38 39 zone = ShiftZone(zone) 40 41 next = DecodeZoneHigh(zone) 42 assert.ItsEqual(t, SE, next) 43 44 zone = ShiftZone(zone) 45 46 next = DecodeZoneHigh(zone) 47 assert.ItsEqual(t, SE, next) 48 49 zone = ShiftZone(zone) 50 51 next = DecodeZoneHigh(zone) 52 assert.ItsEqual(t, 0, next) 53 } 54 55 func Test_DecodeZone(t *testing.T) { 56 zone := AppendZone("", NW) 57 assert.ItsEqual(t, EncodeZone(NW), zone) 58 zone = AppendZone(zone, SE) 59 assert.ItsEqual(t, EncodeZone(NW, SE), zone) 60 zone = AppendZone(zone, SE) 61 assert.ItsEqual(t, EncodeZone(NW, SE, SE), zone) 62 zone = AppendZone(zone, SE) 63 assert.ItsEqual(t, EncodeZone(NW, SE, SE, SE), zone) 64 zoneParts := DecodeZone(zone) 65 assert.ItsEqual(t, []ZoneElem(EncodeZone(NW, SE, SE, SE)), zoneParts) 66 } 67 68 func Test_EncodeZone(t *testing.T) { 69 zone := EncodeZone(NW, SE, SE, SE) 70 assert.ItsEqual(t, "CBBB", zone) 71 } 72 73 func Test_HasZonePrefix(t *testing.T) { 74 zone := EncodeZone(NW, SE, NW, NE, NW, SE) 75 assert.ItsTrue(t, HasZonePrefix(zone, EncodeZone(NW))) 76 assert.ItsTrue(t, HasZonePrefix(zone, EncodeZone(NW, SE))) 77 assert.ItsTrue(t, HasZonePrefix(zone, EncodeZone(NW, SE, NW))) 78 assert.ItsTrue(t, HasZonePrefix(zone, EncodeZone(NW, SE, NW, NE))) 79 assert.ItsTrue(t, HasZonePrefix(zone, EncodeZone(NW, SE, NW, NE, NW))) 80 81 assert.ItsFalse(t, HasZonePrefix(zone, EncodeZone(SE))) 82 }