public void SetUp() { weightFactory = CrsTransformationAdapterWeightFactory.Create(); crsTransformationAdapterCompositeFactory = CrsTransformationAdapterCompositeFactory.Create(); var dotSpatial = new CrsTransformationAdapterDotSpatial(); var ProjNet = new CrsTransformationAdapterProjNet(); var mightyLittleGeodesy = new CrsTransformationAdapterMightyLittleGeodesy(); listOfAdaptersWithOneDuplicated = new List<ICrsTransformationAdapter>{ dotSpatial, ProjNet, mightyLittleGeodesy, // Duplicate added below ! new CrsTransformationAdapterDotSpatial() }; listOfTwoAdaptersWithoutDotSpatial = new List<ICrsTransformationAdapter>{ ProjNet, mightyLittleGeodesy }; listOfWeightsWithOneDuplicated = new List<CrsTransformationAdapterWeight>{ weightFactory.CreateFromInstance(dotSpatial, 1.0), weightFactory.CreateFromInstance(ProjNet, 2.0), weightFactory.CreateFromInstance(mightyLittleGeodesy, 3.0), // Duplicate added below ! // (Duplicate regarding the class, the weight value is not relevant) weightFactory.CreateFromInstance(dotSpatial, 4.0) }; CrsTransformationAdapterLeafFactory leafFactoryOnlyCreatingDotSpatialImplementationAsDefault = CrsTransformationAdapterLeafFactory.Create(new List<ICrsTransformationAdapter>{dotSpatial}); compositeFactoryConfiguredWithLeafFactoryOnlyCreatingDotSpatialImplementationAsDefault = CrsTransformationAdapterCompositeFactory.Create(leafFactoryOnlyCreatingDotSpatialImplementationAsDefault); }
private void crsTransformationAdapterCode() { // The three (currently) 'Leaf' adapters: crsTransformationAdapter = new CrsTransformationAdapterDotSpatial(); crsTransformationAdapter = new CrsTransformationAdapterProjNet(); crsTransformationAdapter = new CrsTransformationAdapterMightyLittleGeodesy(); crsTransformationAdapterCompositeFactory = CrsTransformationAdapterCompositeFactory.Create(); // Three factory methods for 'composite' adapters // (trying to create them all with reflection, and thus no parameter) crsTransformationAdapter = crsTransformationAdapterCompositeFactory.CreateCrsTransformationMedian(); crsTransformationAdapter = crsTransformationAdapterCompositeFactory.CreateCrsTransformationAverage(); crsTransformationAdapter = crsTransformationAdapterCompositeFactory.CreateCrsTransformationFirstSuccess(); // a list used as parameter for the below 'Composite' adapters: IList <ICrsTransformationAdapter> crsTransformationAdapters = new List <ICrsTransformationAdapter> { crsTransformationAdapter }; // Three factory methods for 'composite' adapters // (with the specified leaf adapters in a list parameter) crsTransformationAdapterCompositeFactory = CrsTransformationAdapterCompositeFactory.Create(crsTransformationAdapters); crsTransformationAdapter = crsTransformationAdapterCompositeFactory.CreateCrsTransformationMedian(); crsTransformationAdapter = crsTransformationAdapterCompositeFactory.CreateCrsTransformationAverage(); crsTransformationAdapter = crsTransformationAdapterCompositeFactory.CreateCrsTransformationFirstSuccess(); // leaf adapters (used below for creating a composite with weighted average): var crsTransformationAdapterDotSpatial = new CrsTransformationAdapterDotSpatial(); var crsTransformationAdapterProjNet = new CrsTransformationAdapterProjNet(); // One of the above are used below, with the instance, // and one of them is instead below using the class name created here: string fullClassNameForImplementation = crsTransformationAdapterDotSpatial.GetType().FullName; // Now creating the composite with weighted average, using the above two // leaf adapters, using two different create methods: crsTransformationAdapter = crsTransformationAdapterCompositeFactory.CreateCrsTransformationWeightedAverage(new List <CrsTransformationAdapterWeight> { CrsTransformationAdapterWeightFactory.Create().CreateFromInstance(crsTransformationAdapterProjNet, 1.0), CrsTransformationAdapterWeightFactory.Create().CreateFromStringWithFullClassNameForImplementation(fullClassNameForImplementation, 2.0) }); // public properties crsTransformationAdapteeType = crsTransformationAdapter.AdapteeType; isComposite = crsTransformationAdapter.IsComposite; longNameOfImplementation = crsTransformationAdapter.LongNameOfImplementation; shortNameOfImplementation = crsTransformationAdapter.ShortNameOfImplementation; // public methods: transformationAdapterChildren = crsTransformationAdapter.TransformationAdapterChildren; crsTransformationResult = crsTransformationAdapter.Transform(crsCoordinate, crsIdentifier); crsTransformationResult = crsTransformationAdapter.Transform(crsCoordinate, epsgNumber); crsTransformationResult = crsTransformationAdapter.Transform(crsCoordinate, crsCode); crsCoordinate = crsTransformationAdapter.TransformToCoordinate(crsCoordinate, crsIdentifier); crsCoordinate = crsTransformationAdapter.TransformToCoordinate(crsCoordinate, epsgNumber); crsCoordinate = crsTransformationAdapter.TransformToCoordinate(crsCoordinate, crsCode); }
public void LeafAdapters_ShouldBeEqual_WhenTheSameTypeAndConfiguration() { var dotSpatial1 = new CrsTransformationAdapterDotSpatial(); var dotSpatial2 = new CrsTransformationAdapterDotSpatial(); Assert.AreEqual( dotSpatial1, dotSpatial2 ); Assert.AreEqual( dotSpatial1.GetHashCode(), dotSpatial2.GetHashCode() ); Assert.AreEqual( dotSpatial, // created in the Setup method dotSpatial1 ); Assert.AreEqual( dotSpatial.GetHashCode(), dotSpatial1.GetHashCode() ); var mightyLittleGeodesy2 = new CrsTransformationAdapterMightyLittleGeodesy(); Assert.AreEqual( mightyLittleGeodesy, // created in the Setup method mightyLittleGeodesy2 ); Assert.AreEqual( mightyLittleGeodesy.GetHashCode(), mightyLittleGeodesy2.GetHashCode() ); var ProjNet2 = new CrsTransformationAdapterProjNet(); Assert.AreEqual( projNet, // created in the Setup method ProjNet2 ); Assert.AreEqual( projNet.GetHashCode(), ProjNet2.GetHashCode() ); }
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" ); }
public void SetUp() { weightFactory = CrsTransformationAdapterWeightFactory.Create(); // Leaf adapters: dotSpatial = new CrsTransformationAdapterDotSpatial(); mightyLittleGeodesy = new CrsTransformationAdapterMightyLittleGeodesy(); // currently there are no configurations possibilities for the above two leafs // but for the below leaf it is possible to create instances with // different configurations projNet = new CrsTransformationAdapterProjNet(); ProjNetWithDifferentConfiguration = new CrsTransformationAdapterProjNet(new SridReader("somepath.csv")); // Composite adapters: crsTransformationAdapterCompositeFactory = CrsTransformationAdapterCompositeFactory.Create( new List <ICrsTransformationAdapter> { dotSpatial, mightyLittleGeodesy, projNet } ); // Note that below list parameter is the same as the above but with the list items in reversed order crsTransformationAdapterCompositeFactoryWithLeafsInReversedOrder = CrsTransformationAdapterCompositeFactory.Create( new List <ICrsTransformationAdapter> { projNet, mightyLittleGeodesy, dotSpatial } ); crsTransformationAdapterCompositeFactoryWithOneLeafDifferentlyConfigured = CrsTransformationAdapterCompositeFactory.Create( new List <ICrsTransformationAdapter> { dotSpatial, mightyLittleGeodesy, ProjNetWithDifferentConfiguration } ); average = crsTransformationAdapterCompositeFactory.CreateCrsTransformationAverage(); median = crsTransformationAdapterCompositeFactory.CreateCrsTransformationMedian(); firstSuccess = crsTransformationAdapterCompositeFactory.CreateCrsTransformationFirstSuccess(); weightedAverage = crsTransformationAdapterCompositeFactory.CreateCrsTransformationWeightedAverage(new List <CrsTransformationAdapterWeight> { weightFactory.CreateFromInstance(dotSpatial, 1.0), weightFactory.CreateFromInstance(projNet, 2.0), weightFactory.CreateFromInstance(mightyLittleGeodesy, 3.0) }); }
public void TransformToCoordinate_ShouldBePossibleToInvokeAndProduceTheSameResult_WhenTheInstanceIsTypedWithTheClassOrTheInterfaceSubTypes() { // Before the git commit when this test method // and this comment was added, only the below a4 object // could invoke the method 'TransformToCoordinate'. // (because of F# explicit interfaces) // The other objects a1, a2 and a3 now also can invoke // the same method because of the "implicit interfaces" // implementation which was added in the same git commit as // this comment and test method CrsTransformationAdapterMightyLittleGeodesy a1 = new CrsTransformationAdapterMightyLittleGeodesy(); CrsTransformationAdapterBaseLeaf a2 = a1; CrsTransformationAdapterBase a3 = a1; ICrsTransformationAdapter a4 = a1; CrsCoordinate c1, c2, c3, c4; c1 = a1.TransformToCoordinate(validInputCoordinate, epsgNumberForSweref99TM); c2 = a2.TransformToCoordinate(validInputCoordinate, epsgNumberForSweref99TM); c3 = a3.TransformToCoordinate(validInputCoordinate, epsgNumberForSweref99TM); c4 = a4.TransformToCoordinate(validInputCoordinate, epsgNumberForSweref99TM); Assert.AreEqual(c1, c2); Assert.AreEqual(c1, c3); Assert.AreEqual(c1, c4); }
public void TransformToCoordinateWithComposite_ShouldAggregateAsExpected_WhenTheLeafsAreAlsoCompositesAndNestedAtManyLevels() { // The method first creates two composites (average and success) // and then uses those two composites as leafs for a // weighted average composite, which in // turn is then used as a leaf within // the final median composite (together with a "normal leaf" i.e. DotSpatial implementation) var crsTransformationAdapterCompositeFactory = CrsTransformationAdapterCompositeFactory.Create(); var compositeAverage = crsTransformationAdapterCompositeFactory.CreateCrsTransformationAverage(); var compositeFirstSuccess = crsTransformationAdapterCompositeFactory.CreateCrsTransformationFirstSuccess(); var weightsForCompositeLeafs = new List <CrsTransformationAdapterWeight> { CrsTransformationAdapterWeightFactory.Create().CreateFromInstance( compositeAverage, 1.0 // weight ), CrsTransformationAdapterWeightFactory.Create().CreateFromInstance( compositeFirstSuccess, 2.0 // weight ) }; CrsTransformationAdapterComposite weightedCompositeAdapterWithOtherCompositesAsLeafs = crsTransformationAdapterCompositeFactory.CreateCrsTransformationWeightedAverage( weightsForCompositeLeafs ); var normalLeafDotSpatialAdapter = new CrsTransformationAdapterDotSpatial(); var adaptersForMedian = new List <ICrsTransformationAdapter> { weightedCompositeAdapterWithOtherCompositesAsLeafs, normalLeafDotSpatialAdapter }; var compositeMedian = crsTransformationAdapterCompositeFactory.CreateCrsTransformationMedian( adaptersForMedian ); // Now the "complex" composite (nested at two lelvels, with composites as leafs) // has been conctructed. // Now create a coordinate: var inputCoordinate = CrsCoordinateFactory.LatLon(60.0, 20.0); // Now use the above "complex" composite to transform the coordinate: var resultMedianWithNestedComposite = compositeMedian.Transform( inputCoordinate, EpsgNumber.SWEDEN__SWEREF99_TM__3006 ); Assert.IsTrue(resultMedianWithNestedComposite.isSuccess); var coordinateResultMedianWithNestedComposite = resultMedianWithNestedComposite.OutputCoordinate; // Now use some leaf (not using DotSpatial as above) // to also make the same Transform, to use it // in the result comparison var mightyLittleGeodesyAdapter = new CrsTransformationAdapterMightyLittleGeodesy(); var coordinateResultMightyLittleGeodesyAdapter = mightyLittleGeodesyAdapter.TransformToCoordinate( inputCoordinate, EpsgNumber.SWEDEN__SWEREF99_TM__3006 ); // The difference should not be very large, and the delta // value below is one decimeter const double deltaValueForAssertions = 0.1; Assert.AreEqual( coordinateResultMightyLittleGeodesyAdapter.X, coordinateResultMedianWithNestedComposite.X, deltaValueForAssertions ); Assert.AreEqual( coordinateResultMightyLittleGeodesyAdapter.Y, coordinateResultMedianWithNestedComposite.Y, deltaValueForAssertions ); var children = resultMedianWithNestedComposite.TransformationResultChildren; // one child is the weightedComposite and the other dotSpatial Assert.AreEqual(2, children.Count); // the assumed order in the two rows below is a little bit fragile CrsTransformationResult resultWeightedComposite = children[0]; CrsTransformationResult resultDotSpatial = children[1]; Assert.AreEqual(weightedCompositeAdapterWithOtherCompositesAsLeafs, resultWeightedComposite.CrsTransformationAdapterResultSource); Assert.AreEqual(normalLeafDotSpatialAdapter, resultDotSpatial.CrsTransformationAdapterResultSource); // the weighted composite has two children (average and firstSuccess) var childrenForWeightedComposite = resultWeightedComposite.TransformationResultChildren; Assert.AreEqual(2, childrenForWeightedComposite.Count); // the leaf should not have any child results Assert.AreEqual(0, resultDotSpatial.TransformationResultChildren.Count); // the assumed order in the two rows below is a little bit fragile CrsTransformationResult resultAverage = childrenForWeightedComposite[0]; CrsTransformationResult resultFirstSuccess = childrenForWeightedComposite[1]; // Average should use all normal leafs Assert.AreEqual(EXPECTED_NUMBER_OF_ADAPTER_LEAF_IMPLEMENTATIONS, resultAverage.TransformationResultChildren.Count); // First success should only have one child result i.e. the first should have succeeded Assert.AreEqual(1, resultFirstSuccess.TransformationResultChildren.Count); }