Skip to content
Snippets Groups Projects
Commit 9fc0b76d authored by Johan de Klerk's avatar Johan de Klerk
Browse files

Added IsProvince to address utils

parent ccce5c8d
Branches
Tags v1.21.0
No related merge requests found
...@@ -8,6 +8,30 @@ import ( ...@@ -8,6 +8,30 @@ import (
"strings" "strings"
) )
const (
ProvinceKwaZuluNatal string = "KwaZulu-Natal"
ProvinceGauteng string = "Gauteng"
ProvinceFreeState string = "Free State"
ProvinceLimpopo string = "Limpopo"
ProvinceMpumalanga string = "Mpumalanga"
ProvinceNorthWest string = "North West"
ProvinceEasternCape string = "Eastern Cape"
ProvinceWesternCape string = "Western Cape"
ProvinceNorthernCape string = "Northern Cape"
)
var Provinces = []string{
ProvinceKwaZuluNatal,
ProvinceGauteng,
ProvinceFreeState,
ProvinceLimpopo,
ProvinceMpumalanga,
ProvinceNorthWest,
ProvinceEasternCape,
ProvinceWesternCape,
ProvinceNorthernCape,
}
// MD5HashOfAddress m(E,L,L) - calculates and returns the MD5 hash of the entered address, lat and lng concatenated together. If lat and lng is blank, it is only the hash of the entered address // MD5HashOfAddress m(E,L,L) - calculates and returns the MD5 hash of the entered address, lat and lng concatenated together. If lat and lng is blank, it is only the hash of the entered address
func MD5HashOfAddress(enteredAddress string, lat *float64, lng *float64, addressType *string) string { func MD5HashOfAddress(enteredAddress string, lat *float64, lng *float64, addressType *string) string {
valueToHash := enteredAddress valueToHash := enteredAddress
...@@ -124,17 +148,17 @@ func CleanZone(oldCountry, oldZone *string) (newCountry, newZone *string) { ...@@ -124,17 +148,17 @@ func CleanZone(oldCountry, oldZone *string) (newCountry, newZone *string) {
zone = "KZN" zone = "KZN"
} }
zone = string_utils.ReplaceCaseInsensitive(zone, "KwaZulu-Natal", "KZN") zone = string_utils.ReplaceCaseInsensitive(zone, ProvinceKwaZuluNatal, "KZN")
zone = string_utils.ReplaceCaseInsensitive(zone, "KwaZulu Natal", "KZN") zone = string_utils.ReplaceCaseInsensitive(zone, "KwaZulu Natal", "KZN")
zone = string_utils.ReplaceCaseInsensitive(zone, "Gauteng", "GP") zone = string_utils.ReplaceCaseInsensitive(zone, ProvinceGauteng, "GP")
zone = string_utils.ReplaceCaseInsensitive(zone, "Freestate", "FS") zone = string_utils.ReplaceCaseInsensitive(zone, "Freestate", "FS")
zone = string_utils.ReplaceCaseInsensitive(zone, "Free State", "FS") zone = string_utils.ReplaceCaseInsensitive(zone, ProvinceFreeState, "FS")
zone = string_utils.ReplaceCaseInsensitive(zone, "Limpopo", "LP") zone = string_utils.ReplaceCaseInsensitive(zone, ProvinceLimpopo, "LP")
zone = string_utils.ReplaceCaseInsensitive(zone, "Mpumalanga", "MP") zone = string_utils.ReplaceCaseInsensitive(zone, ProvinceMpumalanga, "MP")
zone = string_utils.ReplaceCaseInsensitive(zone, "North West", "NW") zone = string_utils.ReplaceCaseInsensitive(zone, ProvinceNorthWest, "NW")
zone = string_utils.ReplaceCaseInsensitive(zone, "Eastern Cape", "EC") zone = string_utils.ReplaceCaseInsensitive(zone, ProvinceEasternCape, "EC")
zone = string_utils.ReplaceCaseInsensitive(zone, "Western Cape", "WC") zone = string_utils.ReplaceCaseInsensitive(zone, ProvinceWesternCape, "WC")
zone = string_utils.ReplaceCaseInsensitive(zone, "Northern Cape", "NC") zone = string_utils.ReplaceCaseInsensitive(zone, ProvinceNorthernCape, "NC")
zone = string_utils.ReplaceCaseInsensitive(zone, "Eastern-Cape", "EC") zone = string_utils.ReplaceCaseInsensitive(zone, "Eastern-Cape", "EC")
zone = string_utils.ReplaceCaseInsensitive(zone, "Western-Cape", "WC") zone = string_utils.ReplaceCaseInsensitive(zone, "Western-Cape", "WC")
zone = string_utils.ReplaceCaseInsensitive(zone, "Northern-Cape", "NC") zone = string_utils.ReplaceCaseInsensitive(zone, "Northern-Cape", "NC")
...@@ -144,3 +168,13 @@ func CleanZone(oldCountry, oldZone *string) (newCountry, newZone *string) { ...@@ -144,3 +168,13 @@ func CleanZone(oldCountry, oldZone *string) (newCountry, newZone *string) {
return return
} }
func IsProvince(address string) bool {
for _, province := range Provinces {
if strings.ToLower(address) == strings.ToLower(fmt.Sprintf("%v, South Africa", province)) {
return true
}
}
return false
}
package address_utils
import (
"testing"
)
func TestIsProvince(t *testing.T) {
type args struct {
address string
}
tests := []struct {
name string
args args
want bool
}{{
name: "IsProvince",
args: args{address: "North West, South Africa"},
want: true,
}, {
name: "IsNotProvince",
args: args{address: "22 Kruis Street, Potchefstroom, Potchefstroom, 2531, GP, ZA"},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := IsProvince(tt.args.address); got != tt.want {
t.Errorf("IsProvince() = %v, want %v", got, tt.want)
}
})
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment