From 0f02b0db05ea9c1c844a852cc22638fa0561bd19 Mon Sep 17 00:00:00 2001 From: Christian Pogea Date: Sat, 10 Feb 2024 16:40:08 +0100 Subject: [PATCH] unit tests geofence.csv --- TeslaLogger/bin/geofence.csv | 4 +-- UnitTestsTeslalogger/UnitTestsGeocode.cs | 44 +++++++++++++++++++++++- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/TeslaLogger/bin/geofence.csv b/TeslaLogger/bin/geofence.csv index 9cbb21c68..7d7a3f406 100644 --- a/TeslaLogger/bin/geofence.csv +++ b/TeslaLogger/bin/geofence.csv @@ -788,7 +788,7 @@ Supercharger NO-Dombås, 62.074749, 9.12783 Supercharger NO-Eidfjord, 60.467438, 7.068209 Supercharger NO-Eidsvoll Verk, 60.312269, 11.145104 Supercharger NO-Elverum old, 60.884053, 11.541698, 20 -Supercharger-V3 Elverum, 60.887617,11.515327 +Supercharger-V3 NO-Elverum, 60.887617,11.515327 Supercharger-V3 NO-Fauske, 67.258778,15.400971, 20 Supercharger NO-Flå, 60.381236, 9.610003 Supercharger NO-Gol, 60.70232, 8.9862 @@ -5891,7 +5891,7 @@ Fastned NL-Vliedberg, 51.484310, 3.850840 Fastned NL-Vrijenban, 51.983412, 4.392855 Fastned NL-Wellerzand, 52.784360, 5.759275 Fastned NL-Willemsbos, 52.360573, 5.766818 -Fastned-NL Swentibold, 51.010590, 5.800570 +Fastned NL-Swentibold, 51.010590, 5.800570 Familia DE-Hamburg, 53.608366, 10.044162 Familia DE-Osterholz-Scharmbeck, 53.232695, 8.754733 diff --git a/UnitTestsTeslalogger/UnitTestsGeocode.cs b/UnitTestsTeslalogger/UnitTestsGeocode.cs index 0857c9d5f..4457802fe 100644 --- a/UnitTestsTeslalogger/UnitTestsGeocode.cs +++ b/UnitTestsTeslalogger/UnitTestsGeocode.cs @@ -153,8 +153,50 @@ public void ParseGeocodeFile() if (name.Contains("\"")) Assert.Fail($"'${name}' contains illegal characters: \""); + if (name.IndexOf("supercharger", StringComparison.OrdinalIgnoreCase) >= 0) + { + if (!name.StartsWith("Supercharger")) + Assert.Fail($"'${name}' must start with Supercharger"); + + var s = name.Split(' '); + if (s[0] == "Supercharger-V3" || s[0] == "Supercharger-V4" || s[0] == "Supercharger") + { + CheckCountry(s[1], name); + } + else + { + Assert.Fail("Supercharger must start with 'Supercharger', 'Supercherger-V3' or 'Supercharger-V4' : " + name); + } + } + else if (name.StartsWith("Tesla Service Center")) + { + CheckCountry(name.Substring(21), name); + } + else if (name.StartsWith("Circle K")) + { + CheckCountry(name.Substring(9), name); + } + else if (name.StartsWith("Grønn Kontakt")) + { + CheckCountry(name.Substring(14), name); + } + else if (name.Substring(2,1) == " ") + { + // Unspecific Charger starting with country code + } + else + { + CheckCountry(name.Substring(name.IndexOf(" ")+1), name); + } } } - } + } + + private static void CheckCountry(string name, string fullname) + { + var l = name.Split('-'); + if (l[0].Length != 2) + Assert.Fail($"Country ({l}) should be 2 chars: " + fullname); + } } }