// ------------------------------------------------------------------------------------- private TestResult RunAllTransformationsOfTheCoordinatesInTheGeneratedCsvFile( ICrsTransformationAdapter crsTransformationAdapter, IList <EpsgCrsAndAreaCodeWithCoordinates> coordinatesFromGeneratedCsvFile ) { var stopWatch = new Stopwatch(); stopWatch.Start(); IList <TestResultItem> testResultItems = new List <TestResultItem>(); int counter = 0; foreach (EpsgCrsAndAreaCodeWithCoordinates item in coordinatesFromGeneratedCsvFile) { CrsCoordinate inputCoordinateWGS84 = CrsCoordinateFactory.CreateFromXEastingLongitudeAndYNorthingLatitude(item.centroidX, item.centroidY, EpsgNumber.WORLD__WGS_84__4326); CrsTransformationResult resultOfTransformationFromWGS84 = crsTransformationAdapter.Transform(inputCoordinateWGS84, item.epsgCrsCode); CrsTransformationResult resultOfTransformationBackToWGS84 = null; if (resultOfTransformationFromWGS84.IsSuccess) { resultOfTransformationBackToWGS84 = crsTransformationAdapter.Transform(resultOfTransformationFromWGS84.OutputCoordinate, EpsgNumber.WORLD__WGS_84__4326); } testResultItems.Add(new TestResultItem(item, inputCoordinateWGS84, resultOfTransformationFromWGS84, resultOfTransformationBackToWGS84)); if (counter++ % 500 == 0) // just to show some progress { Console.WriteLine(this.GetType().Name + " , counter: " + counter + " (of the total " + coordinatesFromGeneratedCsvFile.Count + ") for adapter " + crsTransformationAdapter.GetType().Name); // to show some progress } // if(counter > 300) break; } long totalNumberOfSecondsForAllTransformations = (long)stopWatch.Elapsed.TotalSeconds; Console.WriteLine("Total number of seconds for method runAllTransformationsOfTheCoordinatesInTheGeneratedCsvFile: " + totalNumberOfSecondsForAllTransformations); return(new TestResult(crsTransformationAdapter, totalNumberOfSecondsForAllTransformations, testResultItems)); }
public void method() { Console.WriteLine("SmallCSharpeExample starts"); int epsgWgs84 = 4326; int epsgSweRef = 3006; // alternative to the above two hardcodings: use the library "Programmerare.CrsTransformations.Constants" // and constants EpsgNumber.WORLD__WGS_84__4326 and EpsgNumber.SWEDEN__SWEREF99_TM__3006 // from the class Programmerare.CrsConstants.ConstantsByAreaNameNumber.v9_7.EpsgNumber CrsCoordinate centralStockholmWgs84 = CrsCoordinateFactory.LatLon(59.330231, 18.059196, epsgWgs84); ICrsTransformationAdapter crsTransformationAdapter = CrsTransformationAdapterCompositeFactory.Create().CreateCrsTransformationMedian(); // If the NuGet configuration includes all (currently three) adapter implementations, then the // above created 'Composite' implementation will below use all three 'leaf' implementations // and return a coordinate with a median longitude and a median latitude CrsTransformationResult centralStockholmResultSweRef = crsTransformationAdapter.Transform(centralStockholmWgs84, epsgSweRef); if (centralStockholmResultSweRef.IsSuccess) { Console.WriteLine(centralStockholmResultSweRef.OutputCoordinate); // Console output from the above code row: // CrsCoordinate(xEastingLongitude=674032.357177155, yNorthingLatitude=6580821.99121561, crsIdentifier=CrsIdentifier(crsCode='EPSG:3006', isEpsgCode=True, epsgNumber=3006)) } Console.WriteLine("SmallCSharpeExample ends"); Console.ReadLine(); }
private void AssertTransformationResultFailure( CrsTransformationResult result, CrsCoordinate inputCoordinate, //CrsCoordinate expectedOutputCoordinate, ICrsTransformationAdapter crsTransformationAdapterSource ) { Assert.IsNotNull(result); Assert.IsFalse(result.IsSuccess); Assert.IsNotNull(result.Exception); InvalidOperationException e = Assert.Throws <InvalidOperationException>( () => { var coord = result.OutputCoordinate; }, "Should not try to get output coordinate unless the result was a success" ); Assert.AreEqual(inputCoordinate, result.InputCoordinate); IList <CrsTransformationResult> subresults = result.TransformationResultChildren; Assert.IsNotNull(subresults); Assert.AreEqual(0, subresults.Count); // Leaf should have no children Assert.AreEqual(this.crsTransformationAdapter, result.CrsTransformationAdapterResultSource); AssertStatisticsForLeaf(result); }
public void TransformResult_FromRT90_ToSweref99() { CrsTransformationResult result = crsTransformationAdapter.Transform(coordinateRT90, epsgSweref99); AssertTransformationResultSuccess( result, coordinateRT90, coordinateSweref99, crsTransformationAdapter, maxMeterDifferenceForSuccessfulTest ); // testing the same transform as above but with the overloaded // method taking a string as last parameter instead of integer AssertTransformationResultSuccess( crsTransformationAdapter.Transform(coordinateRT90, crsCodeSweref99), coordinateRT90, coordinateSweref99, crsTransformationAdapter, maxMeterDifferenceForSuccessfulTest ); // testing the same transform as above but with the overloaded // method taking a string as last parameter instead of string or integer AssertTransformationResultSuccess( crsTransformationAdapter.Transform(coordinateRT90, CrsIdentifierFactory.CreateFromEpsgNumber(epsgSweref99)), coordinateRT90, coordinateSweref99, crsTransformationAdapter, maxMeterDifferenceForSuccessfulTest ); }
public void Transform_ShouldReturnMedianResult_WhenUsingMedianCompositeAdapter() { CrsCoordinate expectedCoordinateWithMedianLatitudeAndLongitude = CalculateMedianCoordinate(base.allCoordinateResultsForTheDifferentImplementations); ICrsTransformationAdapter medianCompositeAdapter = crsTransformationAdapterCompositeFactory.CreateCrsTransformationMedian( allAdapters ); CrsTransformationResult medianResult = medianCompositeAdapter.Transform(wgs84coordinate, EpsgNumber.SWEDEN__SWEREF99_TM__3006); Assert.IsNotNull(medianResult); Assert.IsTrue(medianResult.IsSuccess); Assert.AreEqual(base.allCoordinateResultsForTheDifferentImplementations.Count, medianResult.TransformationResultChildren.Count); CrsCoordinate coordinateReturnedByMedianAdapter = medianResult.OutputCoordinate; // The same transformation as above has been done in the base class for the individual adapters Assert.AreEqual( expectedCoordinateWithMedianLatitudeAndLongitude.XEastingLongitude, coordinateReturnedByMedianAdapter.XEastingLongitude, delta ); Assert.AreEqual( expectedCoordinateWithMedianLatitudeAndLongitude.YNorthingLatitude, coordinateReturnedByMedianAdapter.YNorthingLatitude, delta ); }
public void Transform_ShouldReturnAverageResult_WhenUsingAverageCompositeAdapter() { CrsCoordinate coordinateWithAverageLatitudeAndLongitude = CalculateAverageCoordinate( base.allCoordinateResultsForTheDifferentImplementations ); ICrsTransformationAdapter averageCompositeAdapter = crsTransformationAdapterCompositeFactory.CreateCrsTransformationAverage( allAdapters ); CrsTransformationResult averageResult = averageCompositeAdapter.Transform(wgs84coordinate, EpsgNumber.SWEDEN__SWEREF99_TM__3006); Assert.IsNotNull(averageResult); Assert.IsTrue(averageResult.IsSuccess); Assert.AreEqual(base.allCoordinateResultsForTheDifferentImplementations.Count, averageResult.TransformationResultChildren.Count); CrsCoordinate coordinateReturnedByCompositeAdapter = averageResult.OutputCoordinate; Assert.AreEqual( coordinateWithAverageLatitudeAndLongitude.XEastingLongitude, coordinateReturnedByCompositeAdapter.XEastingLongitude, delta ); Assert.AreEqual( coordinateWithAverageLatitudeAndLongitude.YNorthingLatitude, coordinateReturnedByCompositeAdapter.YNorthingLatitude, delta ); // assertEquals(coordinateWithAverageLatitudeAndLongitude, coordinateReturnedByCompositeAdapter); // Expected :Coordinate(xEastingLongitude=674032.3572074446, yNorthingLatitude=6580821.991903967, crsIdentifier=CrsIdentifier(crsCode=EPSG:3006, isEpsgCode=true, epsgNumber=3006)) // Actual :Coordinate(xEastingLongitude=674032.3572074447, yNorthingLatitude=6580821.991903967, crsIdentifier=CrsIdentifier(crsCode=EPSG:3006, isEpsgCode=true, epsgNumber=3006)) }
private void AssertCompositeResultHasLeafSubResults( CrsTransformationAdapterComposite compositeAdapter, int expectedNumberOfLeafResults ) { CrsTransformationResult compositeTransformResult = compositeAdapter.Transform(inputCoordinateSweref99, crsIdentifierWGS84); Assert.IsNotNull(compositeTransformResult); Assert.IsTrue(compositeTransformResult.IsSuccess); //assertEquals(expectedNumberOfLeafResults, allLeafAdapters.size()); // five "leafs" were used to calculate the composite Assert.AreEqual(expectedNumberOfLeafResults, compositeTransformResult.TransformationResultChildren.Count); IList <CrsTransformationResult> subResults = compositeTransformResult.TransformationResultChildren; for (int i = 0; i < subResults.Count; i++) { CrsTransformationResult transformResult = subResults[i]; ICrsTransformationAdapter leafAdapter = allLeafAdapters[i]; CrsTransformationResult transformResultForLeaf = leafAdapter.Transform(inputCoordinateSweref99, crsIdentifierWGS84); Assert.IsNotNull(transformResultForLeaf); Assert.IsTrue(transformResultForLeaf.IsSuccess); AssertEqualCoordinate(transformResult.OutputCoordinate, transformResultForLeaf.OutputCoordinate); Assert.AreEqual(0, transformResultForLeaf.TransformationResultChildren.Count); // no subresults for a leaf } }
public void TransformResult_ShouldReturnSuccess_WhenSuccessParameterIsTrue() { transformResultWithSuccessFalse = CreateCrsTransformationResult( outputCoordinate, null, true ); Assert.IsTrue(transformResultWithSuccessFalse.IsSuccess); }
public void TransformResult_ShouldNotReturnSuccess_WhenSuccessParameterIsFalse() { transformResultWithSuccessFalse = CreateCrsTransformationResult( null, null, false // parameter success = false ! ); Assert.IsFalse(transformResultWithSuccessFalse.IsSuccess); // because of success parameter false }
public void method2() { int epsgNumber = 4326; string crsCode = "EPSG:" + epsgNumber; CrsIdentifier crsIdentifier; // namespace Programmerare.CrsTransformations.Identifier crsIdentifier = CrsIdentifierFactory.CreateFromEpsgNumber(epsgNumber); // Alternative: crsIdentifier = CrsIdentifierFactory.CreateFromCrsCode(crsCode); double latitude = 59.330231; double longitude = 18.059196; CrsCoordinate crsCoordinate; // namespace Programmerare.CrsTransformations.Coordinate // All the below methods are alternatives for creating the same coordinate // with the above latitude/longitude and coordinate reference system. // No class or object is used for the methods below because of the following static import: // using static Programmerare.CrsTransformations.Coordinate.CrsCoordinateFactory; crsCoordinate = LatLon(latitude, longitude, epsgNumber); crsCoordinate = LatLon(latitude, longitude, crsCode); crsCoordinate = LatLon(latitude, longitude, crsIdentifier); crsCoordinate = LonLat(longitude, latitude, epsgNumber); crsCoordinate = LonLat(longitude, latitude, crsCode); crsCoordinate = LonLat(longitude, latitude, crsIdentifier); crsCoordinate = YX(latitude, longitude, epsgNumber); crsCoordinate = YX(latitude, longitude, crsCode); crsCoordinate = YX(latitude, longitude, crsIdentifier); crsCoordinate = XY(longitude, latitude, epsgNumber); crsCoordinate = XY(longitude, latitude, crsCode); crsCoordinate = XY(longitude, latitude, crsIdentifier); crsCoordinate = NorthingEasting(latitude, longitude, epsgNumber); crsCoordinate = NorthingEasting(latitude, longitude, crsCode); crsCoordinate = NorthingEasting(latitude, longitude, crsIdentifier); crsCoordinate = EastingNorthing(longitude, latitude, epsgNumber); crsCoordinate = EastingNorthing(longitude, latitude, crsCode); crsCoordinate = EastingNorthing(longitude, latitude, crsIdentifier); crsCoordinate = CreateFromYNorthingLatitudeAndXEastingLongitude(latitude, longitude, epsgNumber); crsCoordinate = CreateFromYNorthingLatitudeAndXEastingLongitude(latitude, longitude, crsCode); crsCoordinate = CreateFromYNorthingLatitudeAndXEastingLongitude(latitude, longitude, crsIdentifier); crsCoordinate = CreateFromXEastingLongitudeAndYNorthingLatitude(longitude, latitude, epsgNumber); crsCoordinate = CreateFromXEastingLongitudeAndYNorthingLatitude(longitude, latitude, crsCode); crsCoordinate = CreateFromXEastingLongitudeAndYNorthingLatitude(longitude, latitude, crsIdentifier); CrsIdentifier targetCrs = CrsIdentifierFactory.CreateFromEpsgNumber(3006); CrsTransformationResult crsTransformationResult = crsTransformationAdapter.Transform(crsCoordinate, targetCrs); // see more example code further down in this webpage }
public void TransformResult_WhenCrsCodeIsNull() { string crsCode = null; CrsTransformationResult result = crsTransformationAdapter.Transform(coordinateRT90, crsCode); AssertTransformationResultFailure( result, coordinateRT90, crsTransformationAdapter ); }
private void VerifyThatTheCreatedAdapterIsRealObject( ICrsTransformationAdapter crsTransformationAdapter ) { Assert.IsNotNull(crsTransformationAdapter); // below trying to use the created object to really make sure it works CrsCoordinate coordinateWgs84 = CrsCoordinateFactory.CreateFromYNorthingLatitudeAndXEastingLongitude(59.330231, 18.059196, EpsgNumber.WORLD__WGS_84__4326); CrsTransformationResult resultSweref99 = crsTransformationAdapter.Transform(coordinateWgs84, EpsgNumber.SWEDEN__SWEREF99_TM__3006); Assert.IsNotNull(resultSweref99); Assert.IsTrue(resultSweref99.IsSuccess); }
private void AssertResultStatisticsForLeafImplementation( CrsTransformationResult transformResult ) { CrsTransformationResultStatistic crsTransformationResultStatistic = transformResult.CrsTransformationResultStatistic; Assert.IsNotNull(crsTransformationResultStatistic); Assert.IsTrue(crsTransformationResultStatistic.IsStatisticsAvailable); Assert.AreEqual(1, crsTransformationResultStatistic.NumberOfPotentiallySuccesfulResults); Assert.AreEqual(0, crsTransformationResultStatistic.MaxDifferenceForYNorthingLatitude); Assert.AreEqual(0, crsTransformationResultStatistic.MaxDifferenceForXEastingLongitude); Assert.AreEqual(transformResult.OutputCoordinate, crsTransformationResultStatistic.CoordinateAverage); Assert.AreEqual(transformResult.OutputCoordinate, crsTransformationResultStatistic.CoordinateMedian); }
private void AssertStatisticsForLeaf(CrsTransformationResult result) { var stat = result.CrsTransformationResultStatistic; Assert.IsNotNull(stat); // The below assertions should be true for leafs Assert.AreEqual(result.IsSuccess, stat.IsStatisticsAvailable); int expectedNumberOfSuccessResultsForLeaf = result.IsSuccess ? 1 : 0; // note that there is no guarantee for a correct result // i.e. "success" might just mean that an exception was not thrown ... Assert.AreEqual( expectedNumberOfSuccessResultsForLeaf, stat.NumberOfPotentiallySuccesfulResults ); IList <CrsTransformationResult> allResults = stat.AllCrsTransformationResults; Assert.AreEqual(1, allResults.Count); if (stat.IsStatisticsAvailable) { // Since we are not testing a Leaf // there should only one result // and therefore now differences in the // below tests Assert.AreEqual( 0.0, stat.MaxDifferenceForXEastingLongitude ); Assert.AreEqual( 0.0, stat.MaxDifferenceForYNorthingLatitude ); //double smallValue = 0.000000000000001; //Assert.That(stat.MaxDifferenceForXEastingLongitude, Is.LessThan(smallValue)); Assert.AreEqual( result.OutputCoordinate, stat.CoordinateAverage ); Assert.AreEqual( result.OutputCoordinate, stat.CoordinateMedian ); } }
public void TransformResult_WhenInputCoordinateIsNull() { CrsIdentifier crsWgs84 = coordinateWgs84.CrsIdentifier; Assert.IsNotNull(crsWgs84); CrsCoordinate nullCordinate = null; CrsTransformationResult result = crsTransformationAdapter.Transform(nullCordinate, crsWgs84); AssertTransformationResultFailure( result, nullCordinate, crsTransformationAdapter ); }
// [Test] Not intended for test execution, just want to verify compilation, see comment in the method public void TheInternalMethodsShouldBeAvailableFromTestProject() { CrsTransformationResult._CreateCrsTransformationResult(null,null,null,true,null,null); // The above "internal" factory method works from this test project // because of this configuration of the proj file in the F# core project: //<ItemGroup> // <AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo"> // <_Parameter1>Programmerare.CrsTransformations.Test</_Parameter1> // </AssemblyAttribute> //</ItemGroup> // Note that another test project have been created // without the above kind of configuration and from // there the internal method does indeed (as expected) not work // i.e. the code does not even compile if trying to use it. }
public void FindTheNumberOfEpsgCodesPotentiallySupported() { IList <EpsgCrsAndAreaCodeWithCoordinates> coordinatesFromGeneratedCsvFile = CoordinateTestDataGeneratedFromEpsgDatabaseTest.GetCoordinatesFromGeneratedCsvFile(); int totalNumberOfSeconds; foreach (ICrsTransformationAdapter leafAdapter in base.crsTransformationAdapterLeafImplementations) { var stopWatch = new Stopwatch(); stopWatch.Start(); int numberOfFailures = 0; int numberOfSuccesses = 0; for (int i = 0; i < coordinatesFromGeneratedCsvFile.Count; i++) { EpsgCrsAndAreaCodeWithCoordinates epsgCrsAndAreaCodeWithCoordinates = coordinatesFromGeneratedCsvFile[i]; CrsCoordinate coordinateInputWgs84 = CrsCoordinateFactory.LatLon( epsgCrsAndAreaCodeWithCoordinates.centroidY, epsgCrsAndAreaCodeWithCoordinates.centroidX ); CrsTransformationResult resultOutputFromWgs4 = leafAdapter.Transform( coordinateInputWgs84, epsgCrsAndAreaCodeWithCoordinates.epsgCrsCode ); if (resultOutputFromWgs4.IsSuccess) { numberOfSuccesses++; //WriteLine("Success " + DateTime.Now + " " + leafAdapter.AdapteeType + " " + resultOutputFromWgs4.OutputCoordinate); } else { //WriteLine("Failure " + DateTime.Now + " " + leafAdapter.AdapteeType); numberOfFailures++; } if (i % 500 == 0) { //WriteLine("number of rows iterated so far: " + i + " (for leafAdapter " + leafAdapter.AdapteeType + " )"); totalNumberOfSeconds = (int)stopWatch.Elapsed.TotalSeconds; //WriteLine("Number of seconds so far (for the above adapter) : " + totalNumberOfSeconds); //if(i > 500) break; } } totalNumberOfSeconds = (int)stopWatch.Elapsed.TotalSeconds; WriteLine("---------------------"); WriteLine("Result for adapter: " + leafAdapter.AdapteeType); WriteLine("numberOfSuccesses: " + numberOfSuccesses); WriteLine("numberOfFailures: " + numberOfFailures); WriteLine("Number of seconds: " + totalNumberOfSeconds); WriteLine("---------------------"); } }
public void TransformResult_ShouldReturnStatisticsObjectWithCorrectAverageAndMeanAndMaxDiffValues_WhenCreatingResultWithListOfSubresults() { // Both the setup code and the verify/assertion code for this test method // is placed in a base class because it is reused from another test class. // The keyword "super" is used below to make that more obvious. CrsTransformationResult transformResult = CrsTransformationResult._CreateCrsTransformationResult( base.inputCoordinateNotUsedInStatisticsTest, base.outputCoordinateNotUsedInStatisticsTest, null, true, base.compositeAdapterForResultTest, CrsTransformationResultStatistic._CreateCrsTransformationResultStatistic(base.listOfSubresultsForStatisticsTest) ); CrsTransformationResultStatistic crsTransformationResultStatistic = transformResult.CrsTransformationResultStatistic; base.AssertCrsTransformationResultStatistic(crsTransformationResultStatistic); }
private CrsTransformationResult CreateCrsTransformationResult( CrsCoordinate outputCoordinate, ICrsTransformationAdapter adapter, CrsCoordinate inputCoordinateNotUsedInThisTest ) { Exception exceptionNull = null; bool isSuccessTrue = true; return CrsTransformationResult._CreateCrsTransformationResult( inputCoordinateNotUsedInThisTest, outputCoordinate, exceptionNull, isSuccessTrue, adapter, CrsTransformationResultStatistic._CreateCrsTransformationResultStatistic(new List<CrsTransformationResult>()) ); }
// Lots of method in this test class creates a // CrsTransformationResult with three of the six // parameters being exactly the same. // For that reason this helper method is used, // i.e. to not duplicate the three // parameters almost always being the same. private CrsTransformationResult CreateCrsTransformationResult( //CrsCoordinate inputCoordinate: , CrsCoordinate outputCoordinate, Exception exceptionOrNull, bool isSuccess //crsTransformationAdapterResultSource: ICrsTransformationAdapter, //nullableCrsTransformationResultStatistic: CrsTransformationResultStatistic// = null ) { var transformResult = CrsTransformationResult._CreateCrsTransformationResult( inputCoordinate, outputCoordinate, exceptionOrNull, isSuccess, base.compositeAdapterForResultTest, CrsTransformationResultStatistic._CreateCrsTransformationResultStatistic(base.listOfSubresultsForStatisticsTest) ); return transformResult; }
public void TransformResult_WhenCrsIsUnvalidForAllImplementations() { // Negative EPSG values are generally unvalid // and should be handled in a generic way i.e. // without having to implement it in all implementations int epsgNotSupported = -99999999; //int epsgNotSupported = 123; // test this in another method // The transform should not throw exception and not be null // but instead it should return a result object with // IsSuccess property being false CrsTransformationResult result = crsTransformationAdapter.Transform(coordinateRT90, epsgNotSupported); AssertTransformationResultFailure( result, coordinateRT90, crsTransformationAdapter ); }
private void Transform_ShouldReturnSuccessFalseButNotThrowException_WhenCoordinateIsNotValid( CrsCoordinate unvalidInputCoordinate ) { foreach (ICrsTransformationAdapter crsTransformationAdapter in crsTransformationAdapterImplementations) { string messageWhenError = "Problem with the implementation " + crsTransformationAdapter.AdapteeType; CrsTransformationResult transformResult = crsTransformationAdapter.Transform(unvalidInputCoordinate, epsgNumberForSweref99TM); Assert.IsNotNull(transformResult, messageWhenError); if(!unvalidInputCoordinate.CrsIdentifier.IsEpsgCode) { // if the coordinate is unvalid becasue of incorrect crs code // then we can do the below assertions but if the coordinate values // are unreasonable it may not be detected by the implementations // and we can not expect them to return success=false Assert.IsFalse(transformResult.IsSuccess, messageWhenError); Assert.IsNotNull(transformResult.Exception, messageWhenError); Assert.AreEqual(unvalidInputCoordinate, transformResult.InputCoordinate, messageWhenError); } } }
public void CalculateAggregatedResult_ShouldThrowException_WhenResultIsBasedOnLeafsNotBeingPartOfTheWeightedAverageAdapter() { CrsCoordinate coordinate = CrsCoordinateFactory.LatLon(59, 18); List <CrsTransformationResult> emptyListOfTransformationResults = new List <CrsTransformationResult>(); ICrsTransformationAdapter leafMightyLittleGeodesy = new CrsTransformationAdapterMightyLittleGeodesy(); List <CrsTransformationAdapterWeight> leafWeightsForOnlyMightyLittleGeodesy = new List <CrsTransformationAdapterWeight> { weightFactory.CreateFromInstance( leafMightyLittleGeodesy, 1 ) }; // The below type ICompositeStrategy is "internal" in the F# project but still available from here // because of "InternalsVisibleTo" configuration in the .fsproj file. ICompositeStrategy compositeStrategyWeightedAverageForOnlyMightyLittleGeodesy = CompositeStrategyWeightedAverage._CreateCompositeStrategyWeightedAverage(leafWeightsForOnlyMightyLittleGeodesy); // The above composite was created with only one leaf in the list ICrsTransformationAdapter leafDotSpatial = new CrsTransformationAdapterDotSpatial(); CrsTransformationResult crsTransformationResultProblem = new CrsTransformationResult( coordinate, // inputCoordinate irrelevant in this test so okay to use the same as the output coordinate, // outputCoordinate null, // exception true, // isSuccess leafDotSpatial, // crsTransformationAdapterResultSource, CrsTransformationResultStatistic._CreateCrsTransformationResultStatistic(emptyListOfTransformationResults) ); // The composite strategy used below was created with only MightyLittleGeodesy, // and therefore if the result (as below) would be based on "DotSpatial" // then there is a bug somewhere i.e. an exception is thrown // which is tested below InvalidOperationException exception = Assert.Throws <InvalidOperationException>(() => { compositeStrategyWeightedAverageForOnlyMightyLittleGeodesy._CalculateAggregatedResult( new List <CrsTransformationResult> { crsTransformationResultProblem }, // allResults coordinate, coordinate.CrsIdentifier, // crsIdentifier for OutputCoordinateSystem leafDotSpatial // SHOULD CAUSE EXCEPTION ! ); }, "The result adapter was not part of the weighted average composite adapter" ); }
private void verifyThreeImplementations( CrsTransformationAdapterComposite crsTransformationAdapterComposite ) { CrsCoordinate input = CrsCoordinateFactory.LatLon(59.0, 18.0); CrsTransformationResult result = crsTransformationAdapterComposite.Transform(input, EpsgNumber.SWEDEN__SWEREF99_TM__3006); Assert.IsNotNull(result); Assert.IsTrue(result.IsSuccess); const int numberOfImplementations = CrsTransformationAdapterTest.EXPECTED_NUMBER_OF_ADAPTER_LEAF_IMPLEMENTATIONS; Assert.AreEqual(numberOfImplementations, result.TransformationResultChildren.Count); CrsTransformationResultStatistic crsTransformationResultStatistic = result.CrsTransformationResultStatistic; Assert.IsNotNull(crsTransformationResultStatistic); Assert.IsTrue(crsTransformationResultStatistic.IsStatisticsAvailable); Assert.AreEqual(numberOfImplementations, crsTransformationResultStatistic.NumberOfPotentiallySuccesfulResults); Assert.That(crsTransformationResultStatistic.MaxDifferenceForXEastingLongitude, Is.LessThan(0.001)); }
public void Transform_ShouldSuccess_WhenInputCoordinateIsCorrect() { double wgs84Lat = 59.330231; double wgs84Lon = 18.059196; CrsCoordinate wgs84InputCoordinate = CrsCoordinateFactory.CreateFromXEastingLongitudeAndYNorthingLatitude(wgs84Lon, wgs84Lat, base.epsgNumberForWgs84); foreach (ICrsTransformationAdapter crsTransformationAdapter in base.crsTransformationAdapterImplementations) { CrsTransformationResult transformResult = crsTransformationAdapter.Transform(wgs84InputCoordinate, base.epsgNumberForSweref99TM); string errorMessage = "Problem implementation: " + crsTransformationAdapter.AdapteeType; Assert.IsNotNull(transformResult, errorMessage); Assert.IsTrue(transformResult.IsSuccess, errorMessage); Assert.IsNull(transformResult.Exception, errorMessage); CrsCoordinate outputCoordinate = transformResult.OutputCoordinate; Assert.IsNotNull(outputCoordinate, errorMessage); Assert.AreEqual(outputCoordinate.CrsIdentifier.EpsgNumber, base.epsgNumberForSweref99TM, errorMessage); if(!crsTransformationAdapter.IsComposite) { AssertResultStatisticsForLeafImplementation(transformResult); } } }
public void TransformResult_ShouldThrowException_WhenTryingToGetCoordinateWhenSuccessIsFalse() { outputCoordinate = null; transformResultWithSuccessFalse = CreateCrsTransformationResult( outputCoordinate, null, false ); InvalidOperationException e = Assert.Throws<InvalidOperationException>( () => { var coord = transformResultWithSuccessFalse.OutputCoordinate; } , "Should not try to get output coordinate unless the result was a success" ); string exceptionMessage = e.Message.ToLower().Replace("-", ""); // the purpose of the above row is to make the test less sensitive to the exact message // e.g. will match text containing "Pre-condition" (including hyphen and uppercased first letter) // The exception message should be something like "Precondition violated ..." Assert.That(exceptionMessage, Does.Contain("precondition")); }
private void AssertWeightedAverageResult( CrsTransformationAdapterComposite weightedAverageCompositeAdapter ) { CrsTransformationResult weightedAverageResult = weightedAverageCompositeAdapter.Transform(wgs84coordinate, EpsgNumber.SWEDEN__SWEREF99_TM__3006); Assert.IsNotNull(weightedAverageResult); Assert.IsTrue(weightedAverageResult.IsSuccess); Assert.AreEqual(base.allCoordinateResultsForTheDifferentImplementations.Count, weightedAverageResult.TransformationResultChildren.Count); CrsCoordinate weightedAverageCoordinate = weightedAverageResult.OutputCoordinate; Assert.AreEqual(coordinateWithExpectedWeightedValues.YNorthingLatitude, weightedAverageCoordinate.YNorthingLatitude, SMALL_DELTA_VALUE); Assert.AreEqual(coordinateWithExpectedWeightedValues.XEastingLongitude, weightedAverageCoordinate.XEastingLongitude, SMALL_DELTA_VALUE); // The logic for the tests below: // The tested result should of course be very close to the expected result, // i.e. the differences (longitude and latitude differences) // // should be less than a very small SMALL_DELTA_VALUE value double diffLatTestedAdapter = Math.Abs(coordinateWithExpectedWeightedValues.YNorthingLatitude - weightedAverageCoordinate.YNorthingLatitude); double diffLonTestedAdapter = Math.Abs(coordinateWithExpectedWeightedValues.XEastingLongitude - weightedAverageCoordinate.XEastingLongitude); Assert.That(diffLatTestedAdapter, Is.LessThan(SMALL_DELTA_VALUE));// assertTrue(diffLatTestedAdapter < SMALL_DELTA_VALUE); Assert.That(diffLonTestedAdapter, Is.LessThan(SMALL_DELTA_VALUE)); // Now in the rest of the assertions below, // the difference between the individual results which were weighted // should not be quite as close to that same small SMALL_DELTA_VALUE value, // and thus the assertions below are that the difference should be greater // than the SMALL_DELTA_VALUE value. // Of course, in theory some of the individual values below might // come very very close to the weighted result, and then some assertion might fail. // However, it turned out to not be like that with the chosen test values, // and thus they are asserted here as part of regression testing. // If this test would break, it needs to be investigated since these values // have been working fine to assert like below. AssertDiffsAreGreaterThanSmallDelta(resultCoordinateDotSpatial, coordinateWithExpectedWeightedValues); AssertDiffsAreGreaterThanSmallDelta(resultCoordinateMightyLittleGeodesy, coordinateWithExpectedWeightedValues); AssertDiffsAreGreaterThanSmallDelta(resultCoordinateProjNet, coordinateWithExpectedWeightedValues); }
public void IsReliableTest() { var crsTransformationAdapterCompositeFactory = CrsTransformationAdapterCompositeFactory.Create(); CrsTransformationAdapterComposite crsTransformationComposite = crsTransformationAdapterCompositeFactory.CreateCrsTransformationAverage(); var children = crsTransformationComposite.TransformationAdapterChildren; Assert.AreEqual(3, children.Count); CrsCoordinate wgs84coordinateInSweden = CrsCoordinateFactory.LatLon(59.31, 18.04); CrsTransformationResult resultWhenTransformingToSwedishCRS = crsTransformationComposite.Transform(wgs84coordinateInSweden, EpsgNumber.SWEDEN__SWEREF99_TM__3006); Assert.IsNotNull(resultWhenTransformingToSwedishCRS); Assert.IsTrue(resultWhenTransformingToSwedishCRS.IsSuccess); CrsTransformationResultStatistic crsTransformationResultStatistic = resultWhenTransformingToSwedishCRS.CrsTransformationResultStatistic; Assert.IsNotNull(crsTransformationResultStatistic); Assert.IsTrue(crsTransformationResultStatistic.IsStatisticsAvailable); int actualNumberOfResults = crsTransformationResultStatistic.NumberOfPotentiallySuccesfulResults; Assert.AreEqual( EXPECTED_NUMBER_OF_ADAPTER_LEAF_IMPLEMENTATIONS, actualNumberOfResults ); double actualMaxDiffXLongitude = crsTransformationResultStatistic.MaxDifferenceForXEastingLongitude; double actualMaxDiffYLatitude = crsTransformationResultStatistic.MaxDifferenceForYNorthingLatitude; double actualMaxDiffXorY = Math.Max(actualMaxDiffXLongitude, actualMaxDiffYLatitude); Assert.That(actualMaxDiffXorY, Is.LessThan(0.01)); Assert.IsTrue(resultWhenTransformingToSwedishCRS.IsReliable(actualNumberOfResults, actualMaxDiffXorY)); // assertFalse below since trying to require one more result than available Assert.IsFalse(resultWhenTransformingToSwedishCRS.IsReliable(actualNumberOfResults + 1, actualMaxDiffXorY)); // assertFalse below since trying to require too small maxdiff Assert.IsFalse(resultWhenTransformingToSwedishCRS.IsReliable(actualNumberOfResults, actualMaxDiffXorY - 0.00000000001)); }
public TestResultItem( EpsgCrsAndAreaCodeWithCoordinates item, CrsCoordinate inputCoordinateWGS84, CrsTransformationResult resultOfTransformationFromWGS84, CrsTransformationResult resultOfTransformationBackToWGS84 ) { wgs84sourceX = "" + item.centroidX; wgs84sourceY = "" + item.centroidY; epsgCrsCode = "" + item.epsgCrsCode; if (resultOfTransformationFromWGS84 != null && resultOfTransformationFromWGS84.IsSuccess) { CrsCoordinate outputCoordinate = resultOfTransformationFromWGS84.OutputCoordinate; epsgTargetSourceX = "" + outputCoordinate.XEastingLongitude; epsgTargetSourceY = "" + outputCoordinate.YNorthingLatitude; } if (resultOfTransformationBackToWGS84 != null && resultOfTransformationBackToWGS84.IsSuccess) { CrsCoordinate outputCoordinate = resultOfTransformationBackToWGS84.OutputCoordinate; wgs84targetX = "" + outputCoordinate.XEastingLongitude; wgs84targetY = "" + outputCoordinate.YNorthingLatitude; } }
private void AssertTransformationResultSuccess( CrsTransformationResult result, CrsCoordinate inputCoordinate, CrsCoordinate expectedOutputCoordinate, ICrsTransformationAdapter crsTransformationAdapterSource, double maxDeltaDifference ) { Assert.IsNotNull(result); Assert.IsTrue(result.IsSuccess); Assert.IsNull(result.Exception); AssertCoordinateResult( result.OutputCoordinate, expectedOutputCoordinate, maxDeltaDifference ); IList <CrsTransformationResult> subresults = result.TransformationResultChildren; Assert.IsNotNull(subresults); Assert.AreEqual(0, subresults.Count); // Leaf should have no children Assert.AreEqual(this.crsTransformationAdapter, result.CrsTransformationAdapterResultSource); AssertStatisticsForLeaf(result); }