public void SetUp() { weightFactory = CrsTransformationAdapterWeightFactory.Create(); crsTransformationAdapterCompositeFactory = CrsTransformationAdapterCompositeFactory.Create(); crsTransformationAdapterLeafImplementations = new List<ICrsTransformationAdapter>{ new CrsTransformationAdapterDotSpatial(), new CrsTransformationAdapterProjNet(), new CrsTransformationAdapterMightyLittleGeodesy() }; crsTransformationAdapterCompositeImplementations = new List<ICrsTransformationAdapter>{ crsTransformationAdapterCompositeFactory.CreateCrsTransformationAverage(), crsTransformationAdapterCompositeFactory.CreateCrsTransformationMedian(), crsTransformationAdapterCompositeFactory.CreateCrsTransformationFirstSuccess(), crsTransformationAdapterCompositeFactory.CreateCrsTransformationWeightedAverage(new List<CrsTransformationAdapterWeight>{ weightFactory.CreateFromInstance(new CrsTransformationAdapterDotSpatial(), 51.0), weightFactory.CreateFromInstance(new CrsTransformationAdapterProjNet(), 52.0), weightFactory.CreateFromInstance(new CrsTransformationAdapterMightyLittleGeodesy(), 53.0) }) }; crsTransformationAdapterImplementations = new List<ICrsTransformationAdapter>(); crsTransformationAdapterImplementations.AddRange(crsTransformationAdapterLeafImplementations); crsTransformationAdapterImplementations.AddRange(crsTransformationAdapterCompositeImplementations); }
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); }
public void CreateFromInstance_ShouldThrowException_WhenAdapterParameterIsNull() { ArgumentNullException exception = Assert.Throws <ArgumentNullException>(() => { weightFactory.CreateFromInstance( null, // adapter 123 // weight ); }); }
public void TestCompositeWeightedAverage() { VerifyExpectedEnumWhenNotRepresentingThirdPartLibrary( crsTransformationAdapterCompositeFactory.CreateCrsTransformationWeightedAverage(new List <CrsTransformationAdapterWeight> { weightFactory.CreateFromInstance(new CrsTransformationAdapterDotSpatial(), 1.0), weightFactory.CreateFromInstance(new CrsTransformationAdapterProjNet(), 2.0), weightFactory.CreateFromInstance(new CrsTransformationAdapterMightyLittleGeodesy(), 3.0) }), CrsTransformationAdapteeType.COMPOSITE_WEIGHTED_AVERAGE ); }
public void TransformToCoordinate_ShouldReturnWeightedAverageResult_WhenUsingWeightedAverageCompositeAdapter() { double[] weights = { 1, 2, 4, 5, 9 }; double totWeights = 0; double totLats = 0; double totLons = 0; for (int i = 0; i < weights.Length; i++) { double weight = weights[i]; totWeights += weight; CrsCoordinate coordinate = outputCoordinates[i]; totLats += weight * coordinate.YNorthingLatitude; totLons += weight * coordinate.XEastingLongitude; } double weightedLat = totLats / totWeights; double weightedLon = totLons / totWeights; CrsCoordinate expectedWeightedAverage = CrsCoordinateFactory.CreateFromLatitudeLongitude(weightedLat, weightedLon); List <CrsTransformationAdapterWeight> weightedAdapters = new List <CrsTransformationAdapterWeight> { weightFactory.CreateFromInstance(leafAdapterImplementation_1, weights[0]), weightFactory.CreateFromInstance(leafAdapterImplementation_2, weights[1]), weightFactory.CreateFromInstance(leafAdapterImplementation_3, weights[2]), weightFactory.CreateFromInstance(leafAdapterImplementation_4, weights[3]), weightFactory.CreateFromInstance(leafAdapterImplementation_5, weights[4]) }; CrsTransformationAdapterComposite weightedAverageCompositeAdapter = crsTransformationAdapterCompositeFactory.CreateCrsTransformationWeightedAverage(weightedAdapters); CrsCoordinate result = weightedAverageCompositeAdapter.TransformToCoordinate(inputCoordinateSweref99, EpsgNumber.WORLD__WGS_84__4326); Assert.IsNotNull(result); Assert.AreEqual(expectedWeightedAverage.YNorthingLatitude, result.YNorthingLatitude, SMALL_DELTA_VALUE_FOR_COMPARISONS); Assert.AreEqual(expectedWeightedAverage.XEastingLongitude, result.XEastingLongitude, SMALL_DELTA_VALUE_FOR_COMPARISONS); AssertCompositeResultHasLeafSubResults( weightedAverageCompositeAdapter, allLeafAdapters.Count ); }
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 CompositeAdapterWeightedAverage_ShouldBeEqual_WhenTheSameWeights() { // Two instances are created below but in different order // but with the same weights var weightedAverage1 = crsTransformationAdapterCompositeFactory.CreateCrsTransformationWeightedAverage(new List <CrsTransformationAdapterWeight> { weightFactory.CreateFromInstance(new CrsTransformationAdapterDotSpatial(), 1.0), weightFactory.CreateFromInstance(new CrsTransformationAdapterProjNet(), 2.0), weightFactory.CreateFromInstance(new CrsTransformationAdapterMightyLittleGeodesy(), 3.0) }); // below the order is switched between the above first and second, // though their weights are the same var weightedAverage2 = crsTransformationAdapterCompositeFactory.CreateCrsTransformationWeightedAverage(new List <CrsTransformationAdapterWeight> { weightFactory.CreateFromInstance(new CrsTransformationAdapterProjNet(), 2.0), weightFactory.CreateFromInstance(new CrsTransformationAdapterDotSpatial(), 1.0), weightFactory.CreateFromInstance(new CrsTransformationAdapterMightyLittleGeodesy(), 3.0) }); Assert.AreEqual( weightedAverage1 , weightedAverage2 ); Assert.AreEqual( weightedAverage1.GetHashCode() , weightedAverage2.GetHashCode() ); }
public void Transform_ShouldReturnWeightedAverageResult_WhenUsingWeightedAverageCompositeAdapter() { var weights = new List <CrsTransformationAdapterWeight> { weightFactory.CreateFromInstance(new CrsTransformationAdapterDotSpatial(), weightForDotSpatial), weightFactory.CreateFromInstance(new CrsTransformationAdapterProjNet(), weightForProjNet), weightFactory.CreateFromInstance(new CrsTransformationAdapterMightyLittleGeodesy(), weightForMightyLittleGeodesy) }; CrsTransformationAdapterComposite adapter = crsTransformationAdapterCompositeFactory.CreateCrsTransformationWeightedAverage(weights); AssertWeightedAverageResult(adapter); }