private static void ECEF_Parse_Options_Test() { Coordinate coordinate; bool pass = true; Coordinate.TryParse("5242.118 km 2444.44 km 2679.085 km", CartesianType.ECEF, out coordinate); if (Math.Abs(coordinate.Latitude.DecimalDegree - 25) > .001) { pass = false; } if (Math.Abs(coordinate.Longitude.DecimalDegree - 25) > .001) { pass = false; } if (Math.Abs(coordinate.ECEF.GeoDetic_Height.Meters - 25) > 1) { pass = false; } Coordinate.TryParse("-96.867, -1107.196 , 6261.02 km", new DateTime(2019, 1, 1), CartesianType.ECEF, out coordinate); if (Math.Abs(coordinate.Latitude.DecimalDegree - 80) > .001) { pass = false; } if (Math.Abs(coordinate.Longitude.DecimalDegree - -95) > .001) { pass = false; } if (Math.Abs(coordinate.ECEF.GeoDetic_Height.Meters - 1500) > 1) { pass = false; } Console.WriteLine(); Pass.Write("ECEF PARSE OPTION", pass); }
private static void Null_Properties_Check(Coordinate c) { EagerLoad e = new EagerLoad(false); //Check to make sure items don't initialize bool pass = true; if (c.CelestialInfo != null) { pass = false; } if (c.UTM != null) { pass = false; } if (c.MGRS != null) { pass = false; } if (c.Cartesian != null) { pass = false; } if (c.ECEF != null) { pass = false; } Pass.Write("Null Properties (Celestial, UTM, MGRS, Cartesian, ECEF)", pass); }
private static void Check_UTM_MGRS_Boundaries() { //UTM MGRS BOUNDARY CHECK bool p = true; Coordinate cr = new Coordinate(-79.99, 0); if (!cr.UTM.WithinCoordinateSystemBounds || !cr.MGRS.WithinCoordinateSystemBounds) { p = false; } cr.Latitude.DecimalDegree = -80; if (cr.UTM.WithinCoordinateSystemBounds || cr.MGRS.WithinCoordinateSystemBounds) { p = false; } cr.Latitude.DecimalDegree = 83.99; if (!cr.UTM.WithinCoordinateSystemBounds || !cr.MGRS.WithinCoordinateSystemBounds) { p = false; } cr.Latitude.DecimalDegree = 84; if (cr.UTM.WithinCoordinateSystemBounds || cr.MGRS.WithinCoordinateSystemBounds) { p = false; } Pass.Write("UTM MGRS BOUNDARY CHECK", p); }
private static void Global_Settings_Check() { //Check for errors with initialization as most calculations occur on load bool pass = true; try { GlobalSettings.Default_CoordinateFormatOptions = new CoordinateFormatOptions() { Format = CoordinateFormatType.Decimal }; GlobalSettings.Default_EagerLoad = new EagerLoad(false); Coordinate c = new Coordinate(25, 25); //Ensure setting took if (c.ToString() != "25 25") { pass = false; } if (c.CelestialInfo != null) { pass = false; } //Reset to continue tests GlobalSettings.Default_CoordinateFormatOptions = new CoordinateFormatOptions() { Format = CoordinateFormatType.Degree_Minutes_Seconds }; GlobalSettings.Default_EagerLoad = new EagerLoad(true); } catch { pass = false; } Pass.Write("Global Settings Check", pass); }
private static void Coordinate_Init_Range_Checks() { bool pass = true; try { EagerLoad eg = new EagerLoad(); Coordinate c = new Coordinate(90, 180); c = new Coordinate(-90, -180); c = new Coordinate(90, 180, new DateTime()); c = new Coordinate(-90, -180, new DateTime()); c = new Coordinate(90, 180, eg); c = new Coordinate(-90, -180, eg); c = new Coordinate(90, 180, new DateTime(), eg); c = new Coordinate(-90, -180, new DateTime(), eg); //Should fail as arguments are out of range. try { c = new Coordinate(91, 180); pass = false; } catch { } //Should fail as arguments are out of range. try { c = new Coordinate(90, 181); pass = false; } catch { } //Should fail as arguments are out of range. try { c = new Coordinate(-91, -180); pass = false; } catch { } //Should fail as arguments are out of range. try { c = new Coordinate(-90, -181); pass = false; } catch { } //Should fail as arguments are out of range. try { c = new Coordinate(91, 180, new DateTime()); pass = false; } catch { } //Should fail as arguments are out of range. try { c = new Coordinate(90, 181, new DateTime()); pass = false; } catch { } //Should fail as arguments are out of range. try { c = new Coordinate(-91, -180, new DateTime()); pass = false; } catch { } //Should fail as arguments are out of range. try { c = new Coordinate(-90, -181, new DateTime()); pass = false; } catch { } //Should fail as arguments are out of range. try { c = new Coordinate(91, 180, new DateTime(), eg); pass = false; } catch { } //Should fail as arguments are out of range. try { c = new Coordinate(90, 181, new DateTime(), eg); pass = false; } catch { } //Should fail as arguments are out of range. try { c = new Coordinate(-91, -180, new DateTime(), eg); pass = false; } catch { } //Should fail as arguments are out of range. try { c = new Coordinate(-90, -181, new DateTime(), eg); pass = false; } catch { } } catch { pass = false; } Pass.Write("Coordinate Initialization Range Checks", pass); }
private static void CoordinatePart_Constructor_PropChange_Checks() { bool pass = true; try { Coordinate coord = new Coordinate(); double lat = coord.Latitude.DecimalDegree; double lng = coord.Longitude.DecimalDegree; string MGRS = coord.MGRS.ToString(); string UTM = coord.UTM.ToString(); string ECEF = coord.ECEF.ToString(); string Cartesian = coord.Cartesian.ToString(); DateTime?cel = coord.CelestialInfo.MoonSet; CoordinatePart cpLat = new CoordinatePart(25, CoordinateType.Lat); CoordinatePart cpLng = new CoordinatePart(25, CoordinateType.Long); //PROP CHANGE ERROR CHECK cpLat.DecimalDegree = 27; cpLng.Seconds = 24; coord.Latitude = cpLat; if (coord.Latitude.ToDouble() == lat) { pass = false; } coord.Longitude = cpLng; if (coord.Longitude.ToDouble() == lng) { pass = false; } if (MGRS == coord.MGRS.ToString()) { pass = false; } if (UTM == coord.UTM.ToString()) { pass = false; } if (ECEF == coord.ECEF.ToString()) { pass = false; } if (Cartesian == coord.Cartesian.ToString()) { pass = false; } if (cel == coord.CelestialInfo.MoonSet) { pass = false; } } catch { pass = false; } Pass.Write("CoordinatePart Constructor Property Change Checks: ", pass); }
private static void Check_ECEF_Height_Conversions() { //ECEF WITH HEIGHT CHECK Console.WriteLine(); bool passE = true; double latE = -80.6586; double longE = -152.49; Distance h = new Distance(1500, DistanceType.Meters); Coordinate cE = new Coordinate(latE, longE); cE.ECEF.Set_GeoDetic_Height(cE, h); if (Math.Abs(cE.ECEF.X - -921.443) >= .001) { passE = false; Debug.WriteLine("...Setting GeoDetic Height Conversions Outside Limits"); } if (Math.Abs(cE.ECEF.Y - -479.878) >= .001) { passE = false; Debug.WriteLine("...Setting GeoDetic Height Conversions Outside Limits"); } if (Math.Abs(cE.ECEF.Z - -6273.377) >= .001) { passE = false; Debug.WriteLine("...Setting GeoDetic Height Conversions Outside Limits"); } ECEF ecefE = new ECEF(cE.ECEF.X, cE.ECEF.Y, cE.ECEF.Z); Coordinate rcE = ECEF.ECEFToLatLong(ecefE); if (Math.Abs(rcE.Latitude.ToDouble() - cE.Latitude.ToDouble()) >= .00001) { passE = false; Debug.WriteLine("...ECEF Conversion Outside Limits: " + rcE.Latitude.ToDouble() + " - " + cE.Latitude.ToDouble()); } if (Math.Abs(rcE.Longitude.ToDouble() - cE.Longitude.ToDouble()) >= .00001) { passE = false; Debug.WriteLine("...ECEF Conversion Outside Limits: " + rcE.Longitude.ToDouble() + " - " + cE.Longitude.ToDouble()); } if (Math.Abs(rcE.ECEF.GeoDetic_Height.Meters - cE.ECEF.GeoDetic_Height.Meters) >= .00001) { passE = false; Debug.WriteLine("...ECEF Conversion Outside Limits: " + rcE.Longitude.ToDouble() + " - " + cE.Longitude.ToDouble()); } ecefE = new ECEF(cE, cE.ECEF.GeoDetic_Height); rcE = ECEF.ECEFToLatLong(ecefE); if (Math.Abs(rcE.Latitude.ToDouble() - cE.Latitude.ToDouble()) >= .00001) { passE = false; Debug.WriteLine("...ECEF Conversion Outside Limits: " + rcE.Latitude.ToDouble() + " - " + cE.Latitude.ToDouble()); } if (Math.Abs(rcE.Longitude.ToDouble() - cE.Longitude.ToDouble()) >= .00001) { passE = false; Debug.WriteLine("...ECEF Conversion Outside Limits: " + rcE.Longitude.ToDouble() + " - " + cE.Longitude.ToDouble()); } if (Math.Abs(rcE.ECEF.GeoDetic_Height.Meters - cE.ECEF.GeoDetic_Height.Meters) >= .00001) { passE = false; Debug.WriteLine("...ECEF Conversion Outside Limits: " + rcE.ECEF.GeoDetic_Height.Meters + " - " + cE.ECEF.GeoDetic_Height.Meters); } Pass.Write("ECEF WITH HEIGHT CHECK", passE); }
private static void Coordinate_Parses_EagerLoad_Test() { Coordinate coordinate; //Parse Coordinate Formats string[] coordStrings = File.ReadAllLines("CoordinateData\\Coordinates.txt"); bool pass = true; foreach (string c in coordStrings) { EagerLoad el = new EagerLoad(false); if (!Coordinate.TryParse("12,12", el, out coordinate)) { pass = false; } if (coordinate.CelestialInfo != null) { pass = false; } //Simple check to see if eager loading is off. el = new EagerLoad(EagerLoadType.Celestial); if (!Coordinate.TryParse("12,12", DateTime.Now, el, out coordinate)) { pass = false; } if (coordinate.CelestialInfo == null || coordinate.ECEF != null) { pass = false; } //Simple check to see if eager loading is specified el = new EagerLoad(EagerLoadType.ECEF); if (!Coordinate.TryParse("12,12", CartesianType.ECEF, el, out coordinate)) { pass = false; } if (coordinate.ECEF == null || coordinate.CelestialInfo != null) { pass = false; } //Simple check to see if eager loading is off. el = new EagerLoad(EagerLoadType.ECEF | EagerLoadType.Celestial); if (!Coordinate.TryParse("12,12", DateTime.Now, CartesianType.ECEF, el, out coordinate)) { pass = false; } if (coordinate.CelestialInfo == null || coordinate.ECEF == null) { pass = false; } //Simple check to see if eager loading is off. } Pass.Write("Coordinate Eager Load Parses", pass); Console.WriteLine(); }
private static void Parse_Type_Enumerator_Test() { bool pass = true; Coordinate coordinate = new Coordinate(25, 25); if (coordinate.Parse_Format != Parse_Format_Type.None) { pass = false; } Coordinate.TryParse("25,25", out coordinate); if (coordinate.Parse_Format != Parse_Format_Type.Signed_Degree) { pass = false; } Coordinate.TryParse("N 25º E 25º", out coordinate); if (coordinate.Parse_Format != Parse_Format_Type.Decimal_Degree) { pass = false; } Coordinate.TryParse("N 25º 0' E 25º 0'", out coordinate); if (coordinate.Parse_Format != Parse_Format_Type.Degree_Decimal_Minute) { pass = false; } Coordinate.TryParse("N 25º 0' 0\" E 25º 0' 0\"", out coordinate); if (coordinate.Parse_Format != Parse_Format_Type.Degree_Minute_Second) { pass = false; } Coordinate.TryParse("35R 298154mE 2766437mN", out coordinate); if (coordinate.Parse_Format != Parse_Format_Type.UTM) { pass = false; } Coordinate.TryParse("35R KH 98154 66437", out coordinate); if (coordinate.Parse_Format != Parse_Format_Type.MGRS) { pass = false; } Coordinate.TryParse("0.8213938 0.38302222 0.42261826", CartesianType.Cartesian, out coordinate); if (coordinate.Parse_Format != Parse_Format_Type.Cartesian_Spherical) { pass = false; } Coordinate.TryParse("5242.097 km, 2444.43 km, 2679.074 km", CartesianType.ECEF, out coordinate); if (coordinate.Parse_Format != Parse_Format_Type.Cartesian_ECEF) { pass = false; } Console.WriteLine(); Pass.Write("PARSE FORMAT ENUM", pass); }
private static void ECEF_Init_Error_Checks() { bool pass = true; try { Coordinate c = new Coordinate(); ECEF ecef = new ECEF(c); ecef = new ECEF(3194.469, 3194.469, 4487.419); } catch { pass = false; } Pass.Write("ECEF Initialization Error Checks", pass); }
private static void Cartesian_Init_Error_Checks() { bool pass = true; try { Coordinate c = new Coordinate(); Cartesian cart = new Cartesian(c); cart = new Cartesian(345, -123, 2839); } catch { pass = false; } Pass.Write("Cartesian Initialization Error Checks", pass); }
private static void UTM_Init_Error_Checks() { bool pass = true; try { UniversalTransverseMercator utm = new UniversalTransverseMercator("Q", 14, 581943.5, 2111989.8); utm = new UniversalTransverseMercator("Q", 14, 581943.5, 2111989.8, 6378160.000, 298.25); utm = new UniversalTransverseMercator("14Q", 581943.5, 2111989.8); utm = new UniversalTransverseMercator("14Q", 581943.5, 2111989.8, 6378160.000, 298.25); } catch { pass = false; } Pass.Write("UniversalTransverseMercator Initialization Error Checks", pass); }
private static void MGRS_Init_Error_Checks() { bool pass = true; try { //Outputs 19T CE 51307 93264 MilitaryGridReferenceSystem mgrs = new MilitaryGridReferenceSystem("T", 19, "CE", 51307, 93264); mgrs = new MilitaryGridReferenceSystem("T", 19, "CE", 51307, 93264, 6378160.000, 298.25); mgrs = new MilitaryGridReferenceSystem("19T", "CE", 51307, 93264); mgrs = new MilitaryGridReferenceSystem("19T", "CE", 51307, 93264, 6378160.000, 298.25); } catch { pass = false; } Pass.Write("MilitaryGridReferenceSytem Initialization Error Checks", pass); }
//Tests switching EagerLoading from on to off to see if properties initialize and avoid null exceptions private static void Switch_Test() { Coordinate c = new Coordinate(1, 1, new EagerLoad(false)); c.EagerLoadSettings = new EagerLoad(true); try { c.Latitude.DecimalDegree++; Pass.Write("EagerLoad Switch Test", true); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); Pass.Write("EagerLoad Switch Test", false); } }
public static void Run_Test() { Console.WriteLine("Loading Celestial Values..."); Console.WriteLine(); CelestialTests ct = new CelestialTests(); ct.Populate_CelestialTests(); Coordinate c = new Coordinate(); Pass.Write("Sunset: ", ct.Check_Values(ct.SunSets, "CelestialData\\SunSet.txt")); Pass.Write("Sunrise: ", ct.Check_Values(ct.SunRises, "CelestialData\\SunRise.txt")); Pass.Write("AstroDawn: ", ct.Check_Values(ct.AstroDawn, "CelestialData\\AstroDawn.txt")); Pass.Write("AstroDusk: ", ct.Check_Values(ct.AstroDusk, "CelestialData\\AstroDusk.txt")); Pass.Write("CivilDawn: ", ct.Check_Values(ct.CivilDawn, "CelestialData\\CivilDawn.txt")); Pass.Write("CivilDusk: ", ct.Check_Values(ct.CivilDusk, "CelestialData\\CivilDusk.txt")); Pass.Write("NauticalDawn: ", ct.Check_Values(ct.NauticalDawn, "CelestialData\\NauticalDawn.txt")); Pass.Write("NauticalDusk: ", ct.Check_Values(ct.NauticalDusk, "CelestialData\\NauticalDusk.txt")); Pass.Write("BottomSolarDiscRise: ", ct.Check_Values(ct.BottomSolarDiscRise, "CelestialData\\BottomDiscRise.txt")); Pass.Write("BottomSolarDiscSet: ", ct.Check_Values(ct.BottomSolarDiscSet, "CelestialData\\BottomDiscSet.txt")); Pass.Write("Moon Set: ", ct.Check_Values(ct.MoonSets, "CelestialData\\MoonSet.txt")); Pass.Write("Moon Rise: ", ct.Check_Values(ct.MoonRises, "CelestialData\\MoonRise.txt")); Console.WriteLine(); Pass.Write("Sun Altitude: ", ct.Check_Values(ct.SunAlts, "CelestialData\\SunAlts.txt")); Pass.Write("Sun Azimuth: ", ct.Check_Values(ct.SunAzs, "CelestialData\\SunAzs.txt")); Pass.Write("Moon Altitude: ", ct.Check_Values(ct.MoonAlts, "CelestialData\\MoonAlts.txt")); Pass.Write("Moon Azimuth: ", ct.Check_Values(ct.MoonAzs, "CelestialData\\MoonAzs.txt")); Pass.Write("Moon Distance: ", ct.Check_Values(ct.MoonDistances, "CelestialData\\MoonDistance.txt")); Pass.Write("Moon Fraction: ", ct.Check_Values(ct.MoonFraction, "CelestialData\\MoonFraction.txt")); Pass.Write("Moon Phase ", ct.Check_Values(ct.MoonPhase, "CelestialData\\MoonPhase.txt")); Pass.Write("Moon Phase Name: ", ct.Check_Values(ct.MoonPhaseName, "CelestialData\\MoonPhaseName.txt")); Console.WriteLine(); Pass.Write("Solar Eclipse: ", ct.Check_Solar_Eclipse()); Pass.Write("Lunar Eclipse: ", ct.Check_Lunar_Eclipse()); Pass.Write("Perigee: ", ct.Check_Perigee()); Pass.Write("Apogee: ", ct.Check_Apogee()); Console.WriteLine(); Console.WriteLine("***Running IsSunUp Test (This will take a minute)****"); Console.WriteLine(); Pass.Write("IsSunUp", ct.Check_IsSunUp()); Console.WriteLine(); Console.WriteLine("***Running IsMoonUp Test (This will take a minute)****"); Console.WriteLine(); Pass.Write("IsMoonUp", ct.Check_IsMoonUp()); Console.WriteLine(); }
private static void CoordinatePart_Init_Error_Checks() { bool pass = true; try { Coordinate c = new Coordinate(); CoordinatePart cp = new CoordinatePart(CoordinateType.Lat); cp = new CoordinatePart(CoordinateType.Long); cp = new CoordinatePart(25, CoordinateType.Lat); cp = new CoordinatePart(25, CoordinateType.Long); cp = new CoordinatePart(25, 25, CoordinatesPosition.N); cp = new CoordinatePart(25, 25, CoordinatesPosition.E); cp = new CoordinatePart(25, 25, CoordinatesPosition.S); cp = new CoordinatePart(25, 25, CoordinatesPosition.W); cp = new CoordinatePart(25, 25, 25, CoordinatesPosition.N); cp = new CoordinatePart(25, 25, 25, CoordinatesPosition.E); cp = new CoordinatePart(25, 25, 25, CoordinatesPosition.S); cp = new CoordinatePart(25, 25, 25, CoordinatesPosition.W); } catch { pass = false; } Pass.Write("CoordinatePart Initialization Error Checks", pass); }
private static void Coordinate_Init_Error_Checks() { //Check for errors with initialization as most calculations occur on load bool pass = true; try { Coordinate c = new Coordinate(); c = new Coordinate(25, 25); c = new Coordinate(25, 25, new DateTime(2018, 8, 5, 10, 10, 0)); EagerLoad eg = new EagerLoad(); eg.Cartesian = false; eg.Celestial = false; eg.UTM_MGRS = false; c = new Coordinate(eg); c = new Coordinate(25, 25, eg); c = new Coordinate(25, 25, new DateTime(2018, 8, 5, 10, 10, 0), eg); } catch { pass = false; } Pass.Write("Coordinate Initialization Error Checks", pass); }
public static void Run_Test() { Console.WriteLine("Loading Celestial Values..."); Console.WriteLine(); CelestialTests ct = new CelestialTests(); ct.Populate_CelestialTests(); Coordinate c = new Coordinate(); Pass.Write("Sunset: ", ct.Check_Values(ct.SunSets, "CelestialData\\SunSet.txt")); Pass.Write("Sunrise: ", ct.Check_Values(ct.SunRises, "CelestialData\\SunRise.txt")); Pass.Write("AstroDawn: ", ct.Check_Values(ct.AstroDawn, "CelestialData\\AstroDawn.txt")); Pass.Write("AstroDusk: ", ct.Check_Values(ct.AstroDusk, "CelestialData\\AstroDusk.txt")); Pass.Write("CivilDawn: ", ct.Check_Values(ct.CivilDawn, "CelestialData\\CivilDawn.txt")); Pass.Write("CivilDusk: ", ct.Check_Values(ct.CivilDusk, "CelestialData\\CivilDusk.txt")); Pass.Write("NauticalDawn: ", ct.Check_Values(ct.NauticalDawn, "CelestialData\\NauticalDawn.txt")); Pass.Write("NauticalDusk: ", ct.Check_Values(ct.NauticalDusk, "CelestialData\\NauticalDusk.txt")); Pass.Write("BottomSolarDiscRise: ", ct.Check_Values(ct.BottomSolarDiscRise, "CelestialData\\BottomDiscRise.txt")); Pass.Write("BottomSolarDiscSet: ", ct.Check_Values(ct.BottomSolarDiscSet, "CelestialData\\BottomDiscSet.txt")); Pass.Write("Moon Set: ", ct.Check_Values(ct.MoonSets, "CelestialData\\MoonSet.txt")); Pass.Write("Moon Rise: ", ct.Check_Values(ct.MoonRises, "CelestialData\\MoonRise.txt")); Console.WriteLine(); Pass.Write("Sun Altitude: ", ct.Check_Values(ct.SunAlts, "CelestialData\\SunAlts.txt")); Pass.Write("Sun Azimuth: ", ct.Check_Values(ct.SunAzs, "CelestialData\\SunAzs.txt")); Pass.Write("Moon Altitude: ", ct.Check_Values(ct.MoonAlts, "CelestialData\\MoonAlts.txt")); Pass.Write("Moon Azimuth: ", ct.Check_Values(ct.MoonAzs, "CelestialData\\MoonAzs.txt")); Pass.Write("Moon Distance: ", ct.Check_Values(ct.MoonDistances, "CelestialData\\MoonDistance.txt")); Pass.Write("Moon Fraction: ", ct.Check_Values(ct.MoonFraction, "CelestialData\\MoonFraction.txt")); Pass.Write("Moon Phase ", ct.Check_Values(ct.MoonPhase, "CelestialData\\MoonPhase.txt")); Pass.Write("Moon Phase Name: ", ct.Check_Values(ct.MoonPhaseName, "CelestialData\\MoonPhaseName.txt")); Console.WriteLine(); Pass.Write("Solar Eclipse: ", ct.Check_Solar_Eclipse()); Pass.Write("Lunar Eclipse: ", ct.Check_Lunar_Eclipse()); Pass.Write("Perigee: ", ct.Check_Perigee()); Pass.Write("Apogee: ", ct.Check_Apogee()); Console.WriteLine(); Pass.Write("Local Time Conversions", ct.Check_Local_Times()); Console.WriteLine(); Pass.Write("Static_Last_Next_Rise_Set_Checks", ct.Check_Static_Last_Next_Times()); Console.WriteLine(); Console.WriteLine(); while (true) { Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine("Base celestial tests are completed. Do you wish to run additional \"IsUp\" tests? (Y/N)..."); ConsoleKeyInfo key = Console.ReadKey(); Console.ForegroundColor = ConsoleColor.White; if (key.Key == ConsoleKey.Y) { break; } if (key.Key == ConsoleKey.N) { return; } Console.WriteLine(); Console.WriteLine("INVALID CHOICE!"); Console.WriteLine(); } Console.WriteLine(); Console.WriteLine("***Running IsSunUp Test (This will take a minute)****"); Console.WriteLine(); Pass.Write("IsSunUp", ct.Check_IsSunUp()); Console.WriteLine(); Console.WriteLine("***Running IsMoonUp Test (This will take a minute)****"); Console.WriteLine(); Pass.Write("IsMoonUp", ct.Check_IsMoonUp()); Console.WriteLine(); }
public static void Run_Test() { // CHANGE LATS e LONS Coordinate c1 = new Coordinate(31.66, -106.52); Coordinate c2 = new Coordinate(31.64, -106.53); Coordinate c3 = new Coordinate(42.02, -106.52); Coordinate c4 = new Coordinate(42.03, -106.53); List <GeoFence.Point> points = new List <GeoFence.Point>(); points.Add(new GeoFence.Point(31.65, -106.52)); points.Add(new GeoFence.Point(31.65, -84.02)); points.Add(new GeoFence.Point(42.03, -84.02)); points.Add(new GeoFence.Point(42.03, -106.52)); points.Add(new GeoFence.Point(31.65, -106.52)); GeoFence gf = new GeoFence(points); bool pass = true; if (gf.IsPointInPolygon(c1)) { pass = false; } if (gf.IsPointInPolygon(c2)) { pass = false; } if (gf.IsPointInPolygon(c3)) { pass = false; } if (gf.IsPointInPolygon(c4)) { pass = false; } Pass.Write("Outside Polygon: ", pass); c1 = new Coordinate(31.67, -106.51); c2 = new Coordinate(31.67, -84.03); c3 = new Coordinate(42.01, -106.51); c4 = new Coordinate(42.01, -84.03); pass = true; if (!gf.IsPointInPolygon(c1)) { pass = false; } if (!gf.IsPointInPolygon(c2)) { pass = false; } if (!gf.IsPointInPolygon(c3)) { pass = false; } if (!gf.IsPointInPolygon(c4)) { pass = false; } Pass.Write("Inside Polygon: ", pass); pass = true; Distance d = new Distance(1000, DistanceType.Meters); if (!gf.IsPointInRangeOfLine(c1, 1000)) { pass = false; } if (!gf.IsPointInRangeOfLine(c1, d)) { pass = false; } Pass.Write("In Range of Polyline: ", pass); pass = true; d = new Distance(900, DistanceType.Meters); if (gf.IsPointInRangeOfLine(c1, 900)) { pass = false; } if (gf.IsPointInRangeOfLine(c1, d)) { pass = false; } Pass.Write("Out of Range of Polyline: ", pass); //Draw rectangle and ensure prescision falls withing met guideline; pass = true; Coordinate c = new Coordinate(25, 45); //Check Vincenty GeoFence.Drawer gd = new GeoFence.Drawer(c, Shape.Ellipsoid, 0); gd.Draw(new Distance(20), 0); gd.Draw(new Distance(20), 90); gd.Draw(new Distance(20), 90); gd.Draw(new Distance(20), 90); double latPrecision = Math.Abs(c.Latitude.ToDouble() - gd.Last.Latitude.ToDouble()); double longPrecision = Math.Abs(c.Longitude.ToDouble() - gd.Last.Longitude.ToDouble()); if (latPrecision > .000001 || longPrecision > .000001) { pass = false; } //111.32 mm precision boundary //Check Haversine gd = new GeoFence.Drawer(c, Shape.Sphere, 0); gd.Draw(new Distance(20), 0); gd.Draw(new Distance(20), 90); gd.Draw(new Distance(20), 90); gd.Draw(new Distance(20), 90); latPrecision = Math.Abs(c.Latitude.ToDouble() - gd.Last.Latitude.ToDouble()); longPrecision = Math.Abs(c.Longitude.ToDouble() - gd.Last.Longitude.ToDouble()); //Check shape closer if (latPrecision > .000001 || longPrecision > .000001) { pass = false; } //111.32 mm precision boundary gd = new GeoFence.Drawer(c, Shape.Ellipsoid, 0); gd.Draw(new Distance(20), 0); gd.Draw(new Distance(20), 90); gd.Draw(new Distance(20), 90); gd.Close(); latPrecision = Math.Abs(c.Latitude.ToDouble() - gd.Last.Latitude.ToDouble()); longPrecision = Math.Abs(c.Longitude.ToDouble() - gd.Last.Longitude.ToDouble()); if (latPrecision != 0 || longPrecision != 0 || gd.Points.Count != 5) { pass = false; } //111.32 mm precision boundary Pass.Write("GeoFence Drawer Precision Checks: ", pass); }
private static void CoordinatePart_Parses_Test() { //Parse CoordinatePart Formats Console.WriteLine("CoordinatePart Parses..."); string[] coordStrings = File.ReadAllLines("CoordinateData\\CoordinateParts.txt"); CoordinatePart cp; bool pass = true; string lastType = ""; foreach (string c in coordStrings) { c.Trim(); if (c.Contains("\\")) { if (lastType != "") { Pass.Write(lastType.Split('#')[0], pass); } lastType = ""; pass = true; lastType = c; } else { string[] cc = c.Split('#'); if (!CoordinatePart.TryParse(cc[0], out cp)) { pass = false; } else { if (cp.ToString().Replace(",", "*").Replace(".", "*") != cc[1].Replace(",", "*").Replace(".", "*")) { Debug.WriteLine("...MISMATCH: " + cp.ToString() + " - " + cc[1]); pass = false; } } } } if (lastType != "") { Pass.Write(lastType.Split(',')[0], pass); } //Attempt Forces Param pass = true; try { if (CoordinatePart.TryParse("95", CoordinateType.Lat, out cp)) { pass = false; } //Intentional Fail if (CoordinatePart.TryParse("E181", CoordinateType.Lat, out cp)) { pass = false; } //Intentional Fail if (CoordinatePart.TryParse("N 95 45", CoordinateType.Lat, out cp)) { pass = false; } //Intentional Fail if (CoordinatePart.TryParse("95", CoordinateType.Lat, out cp)) { pass = false; } //Intentional Fail if (CoordinatePart.TryParse("WD24 45", CoordinateType.Lat, out cp)) { pass = false; } //Intentional Fail } catch { pass = false; } Console.WriteLine(); Pass.Write("\\\\Intentional Fails", pass); }
public static void Run_Test() { // CHANGE LATS e LONS Coordinate c1 = new Coordinate(31.66, -106.52); Coordinate c2 = new Coordinate(31.64, -106.53); Coordinate c3 = new Coordinate(42.02, -106.52); Coordinate c4 = new Coordinate(42.03, -106.53); List <GeoFence.Point> points = new List <GeoFence.Point>(); points.Add(new GeoFence.Point(31.65, -106.52)); points.Add(new GeoFence.Point(31.65, -84.02)); points.Add(new GeoFence.Point(42.03, -84.02)); points.Add(new GeoFence.Point(42.03, -106.52)); points.Add(new GeoFence.Point(31.65, -106.52)); GeoFence gf = new GeoFence(points); bool pass = true; if (gf.IsPointInPolygon(c1)) { pass = false; } if (gf.IsPointInPolygon(c2)) { pass = false; } if (gf.IsPointInPolygon(c3)) { pass = false; } if (gf.IsPointInPolygon(c4)) { pass = false; } Pass.Write("Outside Polygon: ", pass); c1 = new Coordinate(31.67, -106.51); c2 = new Coordinate(31.67, -84.03); c3 = new Coordinate(42.01, -106.51); c4 = new Coordinate(42.01, -84.03); pass = true; if (!gf.IsPointInPolygon(c1)) { pass = false; } if (!gf.IsPointInPolygon(c2)) { pass = false; } if (!gf.IsPointInPolygon(c3)) { pass = false; } if (!gf.IsPointInPolygon(c4)) { pass = false; } Pass.Write("Inside Polygon: ", pass); pass = true; Distance d = new Distance(1000, DistanceType.Meters); if (!gf.IsPointInRangeOfLine(c1, 1000)) { pass = false; } if (!gf.IsPointInRangeOfLine(c1, d)) { pass = false; } Pass.Write("In Range of Polyline: ", pass); pass = true; d = new Distance(900, DistanceType.Meters); if (gf.IsPointInRangeOfLine(c1, 900)) { pass = false; } if (gf.IsPointInRangeOfLine(c1, d)) { pass = false; } Pass.Write("Out of Range of Polyline: ", pass); }
private static void Extensions_Test() { EagerLoad e = new EagerLoad(false); Coordinate c = new Coordinate(45, 75, new DateTime(2008, 1, 2), e); Celestial cel = c.CelestialInfo; c.Latitude.DecimalDegree = -44; //Trigger Calculations bool pass = true; if (!ReflectiveEquals(c.CelestialInfo, cel)) { pass = false; } c.EagerLoadSettings.Celestial = true; c.EagerLoadSettings.Extensions = new EagerLoad_Extensions(false); //All Extensions Off cel = c.CelestialInfo; c.Latitude.DecimalDegree++; //EagerLoading was turned on but exentsions were turned off //CelestialInfo should no longer be null but, properties will still be empty if (c.CelestialInfo == null || c.CelestialInfo.SunSet != null) { pass = false; } if (c.CelestialInfo == null) { pass = false; } var sunset = c.CelestialInfo.SunSet; var moonset = c.CelestialInfo.MoonSet; var sEclipse = c.CelestialInfo.SolarEclipse.LastEclipse.MaximumEclipse; var lEclipse = c.CelestialInfo.LunarEclipse.LastEclipse.PenumbralEclipseBegin; var moonZodiac = c.CelestialInfo.AstrologicalSigns.MoonSign; var sunZodiac = c.CelestialInfo.AstrologicalSigns.ZodiacSign; var moonName = c.CelestialInfo.AstrologicalSigns.MoonName; //The following test will test each extension individually. //The Eager Loaded extension property should change while all others should not. c.EagerLoadSettings.Extensions = new EagerLoad_Extensions(EagerLoad_ExtensionsType.Solar_Cycle); c.Latitude.DecimalDegree++; if (c.CelestialInfo.SunSet == sunset) { pass = false; } sunset = c.CelestialInfo.SunSet; c.EagerLoadSettings.Extensions = new EagerLoad_Extensions(EagerLoad_ExtensionsType.Lunar_Cycle); c.Latitude.DecimalDegree++; if (c.CelestialInfo.MoonSet == moonset || sunset != c.CelestialInfo.SunSet) { pass = false; } moonset = c.CelestialInfo.MoonSet; c.EagerLoadSettings.Extensions = new EagerLoad_Extensions(EagerLoad_ExtensionsType.Solar_Eclipse); c.Latitude.DecimalDegree *= -1; if (c.CelestialInfo.SolarEclipse.LastEclipse.MaximumEclipse == sEclipse || moonset != c.CelestialInfo.MoonSet) { pass = false; } sEclipse = c.CelestialInfo.SolarEclipse.LastEclipse.MaximumEclipse; c.EagerLoadSettings.Extensions = new EagerLoad_Extensions(EagerLoad_ExtensionsType.Lunar_Eclipse); c.Latitude.DecimalDegree++; if (c.CelestialInfo.LunarEclipse.LastEclipse.PenumbralEclipseBegin == lEclipse || sEclipse != c.CelestialInfo.SolarEclipse.LastEclipse.MaximumEclipse) { pass = false; } lEclipse = c.CelestialInfo.LunarEclipse.LastEclipse.PenumbralEclipseBegin; //Check both moon and sun signs and names! c.EagerLoadSettings.Extensions = new EagerLoad_Extensions(EagerLoad_ExtensionsType.Zodiac); c.GeoDate = c.GeoDate.AddDays(15); if (c.CelestialInfo.AstrologicalSigns.MoonName == moonName || c.CelestialInfo.AstrologicalSigns.MoonSign == moonZodiac || c.CelestialInfo.AstrologicalSigns.ZodiacSign == sunZodiac || lEclipse != c.CelestialInfo.LunarEclipse.LastEclipse.PenumbralEclipseBegin) { pass = false; } moonName = c.CelestialInfo.AstrologicalSigns.MoonName; sunZodiac = c.CelestialInfo.AstrologicalSigns.ZodiacSign; moonZodiac = c.CelestialInfo.AstrologicalSigns.MoonSign; c.EagerLoadSettings.UTM_MGRS = true; c.EagerLoadSettings.Extensions = new EagerLoad_Extensions(EagerLoad_ExtensionsType.MGRS); c.Latitude.DecimalDegree++; if (c.MGRS == null || c.CelestialInfo.AstrologicalSigns.MoonName != moonName || c.CelestialInfo.AstrologicalSigns.MoonSign != moonZodiac || c.CelestialInfo.AstrologicalSigns.ZodiacSign != sunZodiac) { pass = false; } Pass.Write("Extensions Tests (EagerLoad Extensions)", pass); }
private static void CoordinatePart_Init_Range_Checks() { bool pass = true; try { Coordinate c = new Coordinate(); CoordinatePart cp = new CoordinatePart(90, CoordinateType.Lat); cp = new CoordinatePart(-90, CoordinateType.Lat); cp = new CoordinatePart(89, 59, CoordinatesPosition.N); cp = new CoordinatePart(89, 59, CoordinatesPosition.S); cp = new CoordinatePart(89, 59, 59, CoordinatesPosition.N); cp = new CoordinatePart(89, 59, 59, CoordinatesPosition.S); cp = new CoordinatePart(180, CoordinateType.Long); cp = new CoordinatePart(-180, CoordinateType.Long); cp = new CoordinatePart(179, 59, CoordinatesPosition.E); cp = new CoordinatePart(179, 59, CoordinatesPosition.W); cp = new CoordinatePart(179, 59, 59, CoordinatesPosition.E); cp = new CoordinatePart(179, 59, 59, CoordinatesPosition.W); //Should fail try { cp = new CoordinatePart(91, CoordinateType.Lat); pass = false; } catch { } try { cp = new CoordinatePart(-91, CoordinateType.Lat); pass = false; } catch { } try { cp = new CoordinatePart(181, CoordinateType.Long); pass = false; } catch { } try { cp = new CoordinatePart(-181, CoordinateType.Long); pass = false; } catch { } try { cp = new CoordinatePart(91, 0, CoordinatesPosition.N); pass = false; } catch { } try { cp = new CoordinatePart(90, 1, CoordinatesPosition.N); pass = false; } catch { } try { cp = new CoordinatePart(89, 60, CoordinatesPosition.N); pass = false; } catch { } try { cp = new CoordinatePart(91, 0, CoordinatesPosition.N); pass = false; } catch { } try { cp = new CoordinatePart(90, 1, CoordinatesPosition.N); pass = false; } catch { } try { cp = new CoordinatePart(89, 60, CoordinatesPosition.N); pass = false; } catch { } try { cp = new CoordinatePart(-90, 1, CoordinatesPosition.N); pass = false; } catch { } try { cp = new CoordinatePart(89, -1, CoordinatesPosition.N); pass = false; } catch { } try { cp = new CoordinatePart(91, 0, CoordinatesPosition.S); pass = false; } catch { } try { cp = new CoordinatePart(90, 1, CoordinatesPosition.S); pass = false; } catch { } try { cp = new CoordinatePart(89, 60, CoordinatesPosition.S); pass = false; } catch { } try { cp = new CoordinatePart(91, 0, CoordinatesPosition.S); pass = false; } catch { } try { cp = new CoordinatePart(90, 1, CoordinatesPosition.S); pass = false; } catch { } try { cp = new CoordinatePart(89, 60, CoordinatesPosition.S); pass = false; } catch { } try { cp = new CoordinatePart(-90, 1, CoordinatesPosition.S); pass = false; } catch { } try { cp = new CoordinatePart(89, -1, CoordinatesPosition.S); pass = false; } catch { } try { cp = new CoordinatePart(91, 0, 0, CoordinatesPosition.N); pass = false; } catch { } try { cp = new CoordinatePart(90, 0, 1, CoordinatesPosition.N); pass = false; } catch { } try { cp = new CoordinatePart(89, 59, 60, CoordinatesPosition.N); pass = false; } catch { } try { cp = new CoordinatePart(90, 0, 1, CoordinatesPosition.N); pass = false; } catch { } try { cp = new CoordinatePart(89, 59, 60, CoordinatesPosition.N); pass = false; } catch { } try { cp = new CoordinatePart(-90, 0, 0, CoordinatesPosition.N); pass = false; } catch { } try { cp = new CoordinatePart(89, -1, 0, CoordinatesPosition.N); pass = false; } catch { } try { cp = new CoordinatePart(89, 1, -1, CoordinatesPosition.N); pass = false; } catch { } try { cp = new CoordinatePart(91, 0, 0, CoordinatesPosition.S); pass = false; } catch { } try { cp = new CoordinatePart(90, 0, 1, CoordinatesPosition.S); pass = false; } catch { } try { cp = new CoordinatePart(89, 59, 60, CoordinatesPosition.S); pass = false; } catch { } try { cp = new CoordinatePart(90, 0, 1, CoordinatesPosition.S); pass = false; } catch { } try { cp = new CoordinatePart(89, 59, 60, CoordinatesPosition.S); pass = false; } catch { } try { cp = new CoordinatePart(-90, 0, 0, CoordinatesPosition.S); pass = false; } catch { } try { cp = new CoordinatePart(89, -1, 0, CoordinatesPosition.S); pass = false; } catch { } try { cp = new CoordinatePart(89, 1, -1, CoordinatesPosition.S); pass = false; } catch { } try { cp = new CoordinatePart(181, 0, CoordinatesPosition.E); pass = false; } catch { } try { cp = new CoordinatePart(180, 1, CoordinatesPosition.E); pass = false; } catch { } try { cp = new CoordinatePart(179, 60, CoordinatesPosition.E); pass = false; } catch { } try { cp = new CoordinatePart(181, 0, CoordinatesPosition.E); pass = false; } catch { } try { cp = new CoordinatePart(180, 1, CoordinatesPosition.E); pass = false; } catch { } try { cp = new CoordinatePart(179, 60, CoordinatesPosition.E); pass = false; } catch { } try { cp = new CoordinatePart(-180, 1, CoordinatesPosition.E); pass = false; } catch { } try { cp = new CoordinatePart(179, -1, CoordinatesPosition.E); pass = false; } catch { } try { cp = new CoordinatePart(181, 0, CoordinatesPosition.W); pass = false; } catch { } try { cp = new CoordinatePart(180, 1, CoordinatesPosition.W); pass = false; } catch { } try { cp = new CoordinatePart(179, 60, CoordinatesPosition.W); pass = false; } catch { } try { cp = new CoordinatePart(181, 0, CoordinatesPosition.W); pass = false; } catch { } try { cp = new CoordinatePart(180, 1, CoordinatesPosition.W); pass = false; } catch { } try { cp = new CoordinatePart(179, 60, CoordinatesPosition.W); pass = false; } catch { } try { cp = new CoordinatePart(-180, 1, CoordinatesPosition.W); pass = false; } catch { } try { cp = new CoordinatePart(179, -1, CoordinatesPosition.W); pass = false; } catch { } try { cp = new CoordinatePart(181, 0, 0, CoordinatesPosition.E); pass = false; } catch { } try { cp = new CoordinatePart(180, 0, 1, CoordinatesPosition.E); pass = false; } catch { } try { cp = new CoordinatePart(179, 59, 60, CoordinatesPosition.E); pass = false; } catch { } try { cp = new CoordinatePart(180, 0, 1, CoordinatesPosition.E); pass = false; } catch { } try { cp = new CoordinatePart(179, 59, 60, CoordinatesPosition.E); pass = false; } catch { } try { cp = new CoordinatePart(-180, 0, 0, CoordinatesPosition.E); pass = false; } catch { } try { cp = new CoordinatePart(179, -1, 0, CoordinatesPosition.E); pass = false; } catch { } try { cp = new CoordinatePart(179, 1, -1, CoordinatesPosition.E); pass = false; } catch { } try { cp = new CoordinatePart(181, 0, 0, CoordinatesPosition.W); pass = false; } catch { } try { cp = new CoordinatePart(180, 0, 1, CoordinatesPosition.W); pass = false; } catch { } try { cp = new CoordinatePart(179, 59, 60, CoordinatesPosition.W); pass = false; } catch { } try { cp = new CoordinatePart(180, 0, 1, CoordinatesPosition.W); pass = false; } catch { } try { cp = new CoordinatePart(179, 59, 60, CoordinatesPosition.W); pass = false; } catch { } try { cp = new CoordinatePart(-180, 0, 0, CoordinatesPosition.W); pass = false; } catch { } try { cp = new CoordinatePart(179, -1, 0, CoordinatesPosition.W); pass = false; } catch { } try { cp = new CoordinatePart(179, 1, -1, CoordinatesPosition.W); pass = false; } catch { } } catch { pass = false; } Pass.Write("CoordinatePart Initialization Range Checks", pass); }
private static void Coordinate_Parses_Test() { Coordinate coordinate; //Parse Coordinate Formats string[] coordStrings = File.ReadAllLines("CoordinateData\\Coordinates.txt"); bool pass = true; string lastType = ""; Console.WriteLine("Coordinate Parses..."); foreach (string c in coordStrings) { if (c.Contains("\\")) { if (lastType != "") { Pass.Write(lastType, pass); } lastType = ""; pass = true; lastType = c; } else { string[] cc = c.Split('#'); if (!Coordinate.TryParse(cc[0], out coordinate)) { pass = false; } else { //CHECK STRING COMPARISON, BUT REPLACE , and . with * to avoid cultural mismatch if (coordinate.ToString().Replace(",", "*").Replace(".", "*") != cc[1].Replace(",", "*").Replace(".", "*")) { Debug.WriteLine("...MISMATCH: " + coordinate.ToString() + " - " + cc[1]); pass = false; } } } } if (lastType != "") { Pass.Write(lastType.Split(',')[0], pass); } //Attempt Forces Param pass = true; try { //Parse wraps TryParse, so Parse does not need to be added to tests unless this structure changes. if (Coordinate.TryParse("95F, 54", out coordinate)) { pass = false; } //Intentional Fail if (Coordinate.TryParse("E 181 30, 56 76", out coordinate)) { pass = false; } //Intentional Fail if (Coordinate.TryParse("N 95 45, E 45", out coordinate)) { pass = false; } //Intentional Fail if (Coordinate.TryParse("95 87 46 78 D", out coordinate)) { pass = false; } //Intentional Fail if (Coordinate.TryParse("W24 45, W45", out coordinate)) { pass = false; } //Intentional Fail } catch { pass = false; } Console.WriteLine(); Pass.Write("\\\\Intentional Fails", pass); Console.WriteLine(); }
//Verifies that Parse is wrapping Try_Parse correctly private static void Parse_Wrap_Tests() { bool pass = true; string coord = "45.6, 22.4"; EagerLoad el = new EagerLoad(EagerLoadType.Celestial | EagerLoadType.Cartesian | EagerLoadType.ECEF); CartesianType cType = CartesianType.ECEF; DateTime geoDate = new DateTime(2020, 3, 10, 10, 10, 12); Coordinate parseCoord; Coordinate tryParseCoord; parseCoord = Coordinate.Parse(coord); Coordinate.TryParse(coord, out tryParseCoord); if (!Parse_Wrap_Check(parseCoord, tryParseCoord, false)) { pass = false; } parseCoord = Coordinate.Parse(coord, geoDate); Coordinate.TryParse(coord, geoDate, out tryParseCoord); if (!Parse_Wrap_Check(parseCoord, tryParseCoord, false)) { pass = false; } parseCoord = Coordinate.Parse(coord, cType); Coordinate.TryParse(coord, cType, out tryParseCoord); if (!Parse_Wrap_Check(parseCoord, tryParseCoord, false)) { pass = false; } parseCoord = Coordinate.Parse(coord, geoDate, cType); Coordinate.TryParse(coord, geoDate, cType, out tryParseCoord); if (!Parse_Wrap_Check(parseCoord, tryParseCoord, false)) { pass = false; } parseCoord = Coordinate.Parse(coord, el); Coordinate.TryParse(coord, el, out tryParseCoord); if (!Parse_Wrap_Check(parseCoord, tryParseCoord, false)) { pass = false; } parseCoord = Coordinate.Parse(coord, geoDate, el); Coordinate.TryParse(coord, geoDate, el, out tryParseCoord); if (!Parse_Wrap_Check(parseCoord, tryParseCoord, false)) { pass = false; } parseCoord = Coordinate.Parse(coord, cType, el); Coordinate.TryParse(coord, cType, el, out tryParseCoord); if (!Parse_Wrap_Check(parseCoord, tryParseCoord, false)) { pass = false; } parseCoord = Coordinate.Parse(coord, geoDate, cType, el); Coordinate.TryParse(coord, geoDate, cType, el, out tryParseCoord); if (!Parse_Wrap_Check(parseCoord, tryParseCoord, false)) { pass = false; } //CoordinatePart Check CoordinatePart cp = CoordinatePart.Parse("45"); if (cp.ToDouble() != 45 || cp.Position != CoordinatesPosition.N) { pass = false; } cp = CoordinatePart.Parse("45", CoordinateType.Long); if (cp.ToDouble() != 45 || cp.Position != CoordinatesPosition.E) { pass = false; } Pass.Write("Parse Wrapper Test", pass); }
private static void Check_UPS_MGRS_Polar() { bool pass = true; EagerLoad el = new EagerLoad(EagerLoadType.UTM_MGRS); Console.WriteLine(); Console.WriteLine("...Checking Polar Regions (this may take a minute)"); Console.WriteLine(); using (StreamReader sr = new StreamReader("CoordinateData\\UPS.csv")) { string currentLine; // currentLine will be null when the StreamReader reaches the end of file while ((currentLine = sr.ReadLine()) != null) { string[] parts = currentLine.Split(','); double lat = Convert.ToDouble(parts[5]); double lng = Convert.ToDouble(parts[6]); string utm = parts[0]; string mgrs = parts[4]; string zone = parts[1]; int easting = Convert.ToInt32(parts[2]); int northing = Convert.ToInt32(parts[3]); Coordinate c = new Coordinate(lat, lng, el); //skip 80-84 due to Earthpoint using different UTM zone returns. Both methods are accurate and test against EarthPoint, but will cause test to fail. if (lat >= 80 && lat <= 84) { continue; } if (Math.Abs(lat) >= 89.99999) { continue; } //Dont test as long doesn't exist at pole. if (string.Format("{0}{1}", c.UTM.LongZone, c.UTM.LatZone) != zone) { pass = false; break; } if (Math.Abs(c.UTM.Easting - easting) > 1) { pass = false; break; } if (Math.Abs(c.UTM.Northing - northing) > 1) { pass = false; break; } string nMgrs = c.MGRS.ToString().Replace(" ", ""); if (nMgrs != mgrs) { pass = false; break; } if (Math.Abs(c.UTM.Easting - easting) > 1) { pass = false; break; } if (Math.Abs(c.UTM.Northing - northing) > 1) { pass = false; break; } //CONVERT BACK TEST double precision = .0000001; //1.1 CM Convert Back Precision Coordinate bc = UniversalTransverseMercator.ConvertUTMtoLatLong(c.UTM, new EagerLoad(false)); double l = c.Latitude.ToDouble(); double bL = bc.Latitude.ToDouble(); //IGNORE 360 values as that equals 0 degrees if (Math.Abs(bL - l) > precision && Math.Abs(bL - l) != 360) { pass = false; break; } l = c.Longitude.ToDouble(); bL = bc.Longitude.ToDouble(); if (Math.Abs(bL - l) > precision && Math.Abs(bL - l) != 360) { pass = false; break; } precision = .0003; if (Math.Abs(c.Latitude.ToDouble()) > 89) { precision = .002; } else if (Math.Abs(c.Latitude.ToDouble()) > 88) { precision = .0006; } bc = MilitaryGridReferenceSystem.MGRStoLatLong(c.MGRS, new EagerLoad(false)); l = c.Latitude.ToDouble(); bL = bc.Latitude.ToDouble(); if (Math.Abs(bL - l) > precision && Math.Abs(bL - l) != 360) { pass = false; break; } l = c.Longitude.ToDouble(); bL = bc.Longitude.ToDouble(); if (Math.Abs(bL - l) > precision && Math.Abs(bL - l) != 360) { pass = false; break; } } } Pass.Write("UPS MGRS Polar Conversions: ", pass); }
private static void Flags_Test() { EagerLoad eg = new EagerLoad(EagerLoadType.Cartesian | EagerLoadType.Celestial | EagerLoadType.UTM_MGRS | EagerLoadType.ECEF); bool pass = true; if (eg.Cartesian == false || eg.Celestial == false || eg.UTM_MGRS == false || eg.ECEF == false) { pass = false; } eg = new EagerLoad(EagerLoadType.Celestial); if (eg.Cartesian == true || eg.Celestial == false || eg.UTM_MGRS == true || eg.ECEF == true) { pass = false; } eg = new EagerLoad(EagerLoadType.Cartesian); if (eg.Cartesian == false || eg.Celestial == true || eg.UTM_MGRS == true || eg.ECEF == true) { pass = false; } eg = new EagerLoad(EagerLoadType.UTM_MGRS); if (eg.Cartesian == true || eg.Celestial == true || eg.UTM_MGRS == false || eg.ECEF == true) { pass = false; } eg = new EagerLoad(EagerLoadType.ECEF); if (eg.Cartesian == true || eg.Celestial == true || eg.UTM_MGRS == true || eg.ECEF == false) { pass = false; } eg = new EagerLoad(EagerLoadType.UTM_MGRS | EagerLoadType.Celestial); if (eg.Cartesian == true || eg.Celestial == false || eg.UTM_MGRS == false || eg.ECEF == true) { pass = false; } eg = new EagerLoad(EagerLoadType.Cartesian | EagerLoadType.Celestial); if (eg.Cartesian == false || eg.Celestial == false || eg.UTM_MGRS == true || eg.ECEF == true) { pass = false; } eg = new EagerLoad(EagerLoadType.UTM_MGRS | EagerLoadType.Cartesian); if (eg.Cartesian == false || eg.Celestial == true || eg.UTM_MGRS == false || eg.ECEF == true) { pass = false; } eg = new EagerLoad(EagerLoadType.ECEF | EagerLoadType.Celestial); if (eg.Cartesian == true || eg.Celestial == false || eg.UTM_MGRS == true || eg.ECEF == false) { pass = false; } eg = new EagerLoad(EagerLoadType.ECEF | EagerLoadType.Cartesian); if (eg.Cartesian == false || eg.Celestial == true || eg.UTM_MGRS == true || eg.ECEF == false) { pass = false; } eg = new EagerLoad(EagerLoadType.ECEF | EagerLoadType.Cartesian | EagerLoadType.UTM_MGRS); if (eg.Cartesian == false || eg.Celestial == true || eg.UTM_MGRS == false || eg.ECEF == false) { pass = false; } Pass.Write("Flags Test", pass); }
private static void Run_Conversion_Passes(List <List <string> > Conversions) { //List of coordinates to test conversions against. List <double[]> coords = new List <double[]>(); coords.Add(new double[] { 39.5768, 72.4859 }); coords.Add(new double[] { -15.5768, 100.4859 }); coords.Add(new double[] { 65.25, -15.1859 }); coords.Add(new double[] { -80.659, -152.49 }); for (int x = 0; x < Conversions.Count; x++) { List <string> coordList = Conversions[x]; double lat = coords[x][0]; double lng = coords[x][1]; //0 = Decimal / Signed //1 = Decimal Degree //2 = Degree Decimal Minute //3 = Degree Minutes Seconds //4 = UTM //5 = MGRS //6 = Cartesian //7 = ECEF Coordinate c = new Coordinate(lat, lng); bool pass = true; Coordinate rc = new Coordinate(); for (int y = 0; y < 8; y++) { switch (y) { case 0: c.FormatOptions.Format = CoordinateFormatType.Decimal; if (c.ToString() != coordList[y]) { pass = false; } break; case 1: c.FormatOptions.Format = CoordinateFormatType.Decimal_Degree; if (c.ToString() != coordList[y]) { pass = false; } break; case 2: c.FormatOptions.Format = CoordinateFormatType.Degree_Decimal_Minutes; if (c.ToString() != coordList[y]) { pass = false; } rc = new Coordinate(); rc.Latitude = new CoordinatePart(c.Latitude.Degrees, c.Latitude.DecimalMinute, c.Latitude.Position); rc.Longitude = new CoordinatePart(c.Longitude.Degrees, c.Longitude.DecimalMinute, c.Longitude.Position); if (rc.Latitude.ToDouble() != c.Latitude.ToDouble()) { pass = false; Debug.WriteLine("...Conversion Outside Limits: " + rc.Latitude.ToDouble() + " - " + c.Latitude.ToDouble()); } if (rc.Longitude.ToDouble() != c.Longitude.ToDouble()) { pass = false; Debug.WriteLine("...Conversion Outside Limits: " + rc.Longitude.ToDouble() + " - " + c.Longitude.ToDouble()); } break; case 3: c.FormatOptions.Format = CoordinateFormatType.Degree_Minutes_Seconds; if (c.ToString() != coordList[y]) { pass = false; } rc = new Coordinate(); rc.Latitude = new CoordinatePart(c.Latitude.Degrees, c.Latitude.Minutes, c.Latitude.Seconds, c.Latitude.Position); rc.Longitude = new CoordinatePart(c.Longitude.Degrees, c.Longitude.Minutes, c.Longitude.Seconds, c.Longitude.Position); if (rc.Latitude.ToDouble() != c.Latitude.ToDouble()) { pass = false; Debug.WriteLine("...Conversion Outside Limits: " + rc.Latitude.ToDouble() + " - " + c.Latitude.ToDouble()); } if (rc.Longitude.ToDouble() != c.Longitude.ToDouble()) { pass = false; Debug.WriteLine("...Conversion Outside Limits: " + rc.Longitude.ToDouble() + " - " + c.Longitude.ToDouble()); } break; case 4: if (c.UTM.ToString() != coordList[y]) { pass = false; } UniversalTransverseMercator utm = new UniversalTransverseMercator(c.UTM.LatZone, c.UTM.LongZone, c.UTM.Easting, c.UTM.Northing); rc = UniversalTransverseMercator.ConvertUTMtoLatLong(utm); if (Math.Abs(rc.Latitude.ToDouble() - c.Latitude.ToDouble()) >= .00001) { pass = false; Debug.WriteLine("...UTM Conversion Outside Limits: " + rc.Latitude.ToDouble() + " - " + c.Latitude.ToDouble()); } if (Math.Abs(rc.Longitude.ToDouble() - c.Longitude.ToDouble()) >= .00001) { pass = false; Debug.WriteLine("...UTM Conversion Outside Limits: " + rc.Longitude.ToDouble() + " - " + c.Longitude.ToDouble()); } //SIGNED DEGREE METHOD double[] sd = UniversalTransverseMercator.ConvertUTMtoSignedDegree(utm); if (Math.Abs(sd[0] - c.Latitude.ToDouble()) >= .00001) { pass = false; Debug.WriteLine("...UTM Conversion Outside Limits: " + rc.Latitude.ToDouble() + " - " + c.Latitude.ToDouble()); } if (Math.Abs(sd[1] - c.Longitude.ToDouble()) >= .00001) { pass = false; Debug.WriteLine("...UTM Conversion Outside Limits: " + rc.Longitude.ToDouble() + " - " + c.Longitude.ToDouble()); } //OVERLOAD METHOD utm = new UniversalTransverseMercator(c.UTM.LongZone + c.UTM.LatZone.ToString(), c.UTM.Easting, c.UTM.Northing); rc = UniversalTransverseMercator.ConvertUTMtoLatLong(utm); if (Math.Abs(rc.Latitude.ToDouble() - c.Latitude.ToDouble()) >= .00001) { pass = false; Debug.WriteLine("...UTM Conversion Outside Limits: " + rc.Latitude.ToDouble() + " - " + c.Latitude.ToDouble()); } if (Math.Abs(rc.Longitude.ToDouble() - c.Longitude.ToDouble()) >= .00001) { pass = false; Debug.WriteLine("...UTM Conversion Outside Limits: " + rc.Longitude.ToDouble() + " - " + c.Longitude.ToDouble()); } break; case 5: if (c.MGRS.ToString() != coordList[y]) { pass = false; } MilitaryGridReferenceSystem mgrs = new MilitaryGridReferenceSystem(c.MGRS.LatZone, c.MGRS.LongZone, c.MGRS.Digraph, c.MGRS.Easting, c.MGRS.Northing); rc = MilitaryGridReferenceSystem.MGRStoLatLong(mgrs); if (Math.Abs(rc.Latitude.ToDouble() - c.Latitude.ToDouble()) >= .0001) { pass = false; Debug.WriteLine("...MGRS Conversion Outside Limits: " + rc.Latitude.ToDouble() + " - " + c.Latitude.ToDouble()); } if (Math.Abs(rc.Longitude.ToDouble() - c.Longitude.ToDouble()) >= .0001) { pass = false; Debug.WriteLine("...MGRS Conversion Outside Limits: " + rc.Longitude.ToDouble() + " - " + c.Longitude.ToDouble()); } //SIGNED DEGREE METHOD double[] sdM = MilitaryGridReferenceSystem.MGRStoSignedDegree(mgrs); if (Math.Abs(sdM[0] - c.Latitude.ToDouble()) >= .0001) { pass = false; Debug.WriteLine("...MGRS Conversion Outside Limits: " + rc.Latitude.ToDouble() + " - " + c.Latitude.ToDouble()); } if (Math.Abs(sdM[1] - c.Longitude.ToDouble()) >= .0001) { pass = false; Debug.WriteLine("...MGRS Conversion Outside Limits: " + rc.Longitude.ToDouble() + " - " + c.Longitude.ToDouble()); } //OVERLOAD METHOD mgrs = new MilitaryGridReferenceSystem(c.MGRS.LongZone + c.MGRS.LatZone.ToString(), c.MGRS.Digraph, c.MGRS.Easting, c.MGRS.Northing); rc = MilitaryGridReferenceSystem.MGRStoLatLong(mgrs); if (Math.Abs(rc.Latitude.ToDouble() - c.Latitude.ToDouble()) >= .0001) { pass = false; Debug.WriteLine("...MGRS Conversion Outside Limits: " + rc.Latitude.ToDouble() + " - " + c.Latitude.ToDouble()); } if (Math.Abs(rc.Longitude.ToDouble() - c.Longitude.ToDouble()) >= .0001) { pass = false; Debug.WriteLine("...MGRS Conversion Outside Limits: " + rc.Longitude.ToDouble() + " - " + c.Longitude.ToDouble()); } break; case 6: if (c.Cartesian.ToString() != coordList[y]) { pass = false; } Cartesian cart = new Cartesian(c.Cartesian.X, c.Cartesian.Y, c.Cartesian.Z); rc = Cartesian.CartesianToLatLong(cart); if (Math.Abs(rc.Latitude.ToDouble() - c.Latitude.ToDouble()) >= .00001) { pass = false; Debug.WriteLine("...Cartesian Conversion Outside Limits: " + rc.Latitude.ToDouble() + " - " + c.Latitude.ToDouble()); } if (Math.Abs(rc.Longitude.ToDouble() - c.Longitude.ToDouble()) >= .00001) { pass = false; Debug.WriteLine("...Cartesian Conversion Outside Limits: " + rc.Longitude.ToDouble() + " - " + c.Longitude.ToDouble()); } break; case 7: string ec = c.ECEF.ToString().Replace(" km", "").Replace(",", ""); if (ec != coordList[y]) { pass = false; } ECEF ecef = new ECEF(c.ECEF.X, c.ECEF.Y, c.ECEF.Z); rc = ECEF.ECEFToLatLong(ecef); if (Math.Abs(rc.Latitude.ToDouble() - c.Latitude.ToDouble()) >= .00001) { pass = false; Debug.WriteLine("...ECEF Conversion Outside Limits: " + rc.Latitude.ToDouble() + " - " + c.Latitude.ToDouble()); } if (Math.Abs(rc.Longitude.ToDouble() - c.Longitude.ToDouble()) >= .00001) { pass = false; Debug.WriteLine("...ECEF Conversion Outside Limits: " + rc.Longitude.ToDouble() + " - " + c.Longitude.ToDouble()); } if (Math.Abs(rc.ECEF.GeoDetic_Height.Meters - c.ECEF.GeoDetic_Height.Meters) >= .00001) { pass = false; Debug.WriteLine("...ECEF Conversion Outside Limits: " + rc.Longitude.ToDouble() + " - " + c.Longitude.ToDouble()); } break; default: break; } } Pass.Write("Conversion Pass " + ((int)(x + 1)).ToString() + ": ", pass); } }
private static void Load_Call_Tests(Coordinate c) { //Check Load_Calls bool pass = true; c.LoadCelestialInfo(); if (c.CelestialInfo == null) { pass = false; } c.LoadUTM_MGRS_Info(); if (c.UTM == null) { pass = false; } if (c.MGRS == null) { pass = false; } c.LoadCartesianInfo(); if (c.Cartesian == null) { pass = false; } c.LoadECEFInfo(); if (c.ECEF == null) { pass = false; } Pass.Write("Load Calls (Celestial, UTM, MGRS, Cartesian, ECEF)", pass); if (pass) { Celestial cel = c.CelestialInfo; MilitaryGridReferenceSystem mgrs = c.MGRS; UniversalTransverseMercator utm = c.UTM; Cartesian cart = c.Cartesian; ECEF ecef = c.ECEF; c.Latitude.DecimalDegree = -45; c.Longitude.DecimalDegree = -75; //Properties should not change. if (!ReflectiveEquals(c.CelestialInfo, cel)) { pass = false; } if (!ReflectiveEquals(c.MGRS, mgrs)) { pass = false; } if (!ReflectiveEquals(c.UTM, utm)) { pass = false; } if (!ReflectiveEquals(c.Cartesian, cart)) { pass = false; } if (!ReflectiveEquals(c.ECEF, ecef)) { pass = false; } //Properties should remain equal as no load calls were made Pass.Write("Property State Hold (Celestial, UTM, MGRS, Cartesian, ECEF)", pass); //Properties should change pass = true; c.LoadCelestialInfo(); c.LoadCartesianInfo(); c.LoadUTM_MGRS_Info(); c.LoadECEFInfo(); if (ReflectiveEquals(c.CelestialInfo, cel)) { pass = false; } if (ReflectiveEquals(c.MGRS, mgrs)) { pass = false; } if (ReflectiveEquals(c.UTM, utm)) { pass = false; } if (ReflectiveEquals(c.Cartesian, cart)) { pass = false; } if (ReflectiveEquals(c.ECEF, ecef)) { pass = false; } //Properties should not be equal as chages have been made Pass.Write("Property State Change (Celestial, UTM, MGRS, Cartesian, ECEF)", pass); } else { //Passes auto fail has properties didn't load when called. Pass.Write("Property State Hold (Celestial, UTM, MGRS, Cartesian, ECEF)", false); Pass.Write("Property State Change (Celestial, UTM, MGRS, Cartesian, ECEF)", false); } }
private static void Check_UTM_MGRS_Grid_Zone_Lock() { bool pass = true; Coordinate coord1 = new Coordinate(51.5074, 1); Coordinate coord2 = new Coordinate(51.5074, 1); coord1.Lock_UTM_MGRS_Zone(30); //Lock first coord to zone 30 //2 degree change tested at 1.1 Meter precision //Try UTM Coordinate coordVal; if (!Coordinate.TryParse(coord1.UTM.ToString(), out coordVal)) { pass = false; return; } if (Math.Abs(coordVal.Latitude.ToDouble() - coord2.Latitude.ToDouble()) > .00001) { pass = false; } if (Math.Abs(coordVal.Longitude.ToDouble() - coord2.Longitude.ToDouble()) > .00001) { pass = false; } //TRY MGRS if (!Coordinate.TryParse(coord1.MGRS.ToString(), out coordVal)) { pass = false; return; } if (Math.Abs(coordVal.Latitude.ToDouble() - coord2.Latitude.ToDouble()) > .00001) { pass = false; } if (Math.Abs(coordVal.Longitude.ToDouble() - coord2.Longitude.ToDouble()) > .00001) { pass = false; } coord1.Unlock_UTM_MGRS_Zone(); if (coord1.UTM.LongZone != 31 || coord1.MGRS.LongZone != 31) { pass = false; } //Test Validation try { coord1.Lock_UTM_MGRS_Zone(0); pass = false; } catch {//Intentional fail } try { coord1.Lock_UTM_MGRS_Zone(61); pass = false; } catch {//Intentional fail } Pass.Write("UTM MGRS Zone Lock Test", pass); }