public PersonComparer() { personsComparer = new ListComparer <Person>(Equals); }
/// <summary> /// Checks if given lists are equal. /// Lists are considered equal if they contain the same elements in the same order. /// </summary> /// <param name="sequence1">The first list.</param> /// <param name="sequence2">The second list.</param> /// <returns><see langword="true"/> if the lists are equal, <see langword="false"/> otherwise.</returns> public bool SequencesAreEqual(TList sequence1, TList sequence2) => ListComparer <TElement> .EqualLists(sequence1, sequence2);
public void GetModelTest() { var firstPoint = new Point { PointId = 1, HorizontalDisplacement = 0, VerticalDisplacement = 0 }; var secondPoint = new Point { PointId = 2, HorizontalDisplacement = 0, VerticalDisplacement = 2 }; var thirdPoint = new Point { PointId = 3, HorizontalDisplacement = 3, VerticalDisplacement = 3 }; var firstModeledPoint = new ClusteredPoint { PointId = firstPoint.PointId, HorizontalDisplacement = firstPoint.HorizontalDisplacement, VerticalDisplacement = firstPoint.VerticalDisplacement, ClusterSnapshots = new List <ClusterSnapshot> { new ClusterSnapshot { ClusterId = 1, ClusterCount = 3 }, new ClusterSnapshot { ClusterId = 1, ClusterCount = 2 }, new ClusterSnapshot { ClusterId = 1, ClusterCount = 1 }, } }; var secondModeledPoint = new ClusteredPoint { PointId = secondPoint.PointId, HorizontalDisplacement = secondPoint.HorizontalDisplacement, VerticalDisplacement = secondPoint.VerticalDisplacement, ClusterSnapshots = new List <ClusterSnapshot> { new ClusterSnapshot { ClusterId = 2, ClusterCount = 3 }, new ClusterSnapshot { ClusterId = 1, ClusterCount = 2 }, new ClusterSnapshot { ClusterId = 1, ClusterCount = 1 }, } }; var thirdModeledPoint = new ClusteredPoint { PointId = thirdPoint.PointId, HorizontalDisplacement = thirdPoint.HorizontalDisplacement, VerticalDisplacement = thirdPoint.VerticalDisplacement, ClusterSnapshots = new List <ClusterSnapshot> { new ClusterSnapshot { ClusterId = 3, ClusterCount = 3 }, new ClusterSnapshot { ClusterId = 3, ClusterCount = 2 }, new ClusterSnapshot { ClusterId = 1, ClusterCount = 1 }, } }; var modeledPoints = new AgglomerativeHierarchicalClusteringService(this._distanceService).GetModel(new List <Point> { firstPoint, secondPoint, thirdPoint }); var expectedModeledPoints = new List <ClusteredPoint> { firstModeledPoint, secondModeledPoint, thirdModeledPoint }; Assert.IsTrue(ListComparer.Compare(modeledPoints, expectedModeledPoints)); }
public void MergeClusterTest() { var firstCluster = new Cluster <ClusteredPoint> { ClusterId = 1, Points = new List <ClusteredPoint> { new ClusteredPoint { PointId = 10, HorizontalDisplacement = 1, VerticalDisplacement = 2 } } }; var secondCluster = new Cluster <ClusteredPoint> { ClusterId = 2, Points = new List <ClusteredPoint> { new ClusteredPoint { PointId = 20, HorizontalDisplacement = 3, VerticalDisplacement = 4 } } }; var thirdCluster = new Cluster <ClusteredPoint> { ClusterId = 3, Points = new List <ClusteredPoint> { new ClusteredPoint { PointId = 30, HorizontalDisplacement = 5, VerticalDisplacement = 6 } } }; var clusters = new List <Cluster <ClusteredPoint> > { firstCluster, secondCluster, thirdCluster }; var mergedClusters = AgglomerativeHierarchicalClusteringService .MergeClusters <Cluster <ClusteredPoint>, ClusteredPoint>(clusters, secondCluster, thirdCluster) .ToList(); var expectedMergedClusters = new List <Cluster <ClusteredPoint> > { new Cluster <ClusteredPoint> { ClusterId = 1, Points = new List <ClusteredPoint> { new ClusteredPoint { PointId = 10, HorizontalDisplacement = 1, VerticalDisplacement = 2 } } }, new Cluster <ClusteredPoint> { ClusterId = 2, Points = new List <ClusteredPoint> { new ClusteredPoint { PointId = 20, HorizontalDisplacement = 3, VerticalDisplacement = 4 }, new ClusteredPoint { PointId = 30, HorizontalDisplacement = 5, VerticalDisplacement = 6 } } } }; Assert.IsTrue(ListComparer.Compare(mergedClusters, expectedMergedClusters)); }
public void RecordClustersTest() { var firstPoint = new ClusteredPoint { PointId = 1, HorizontalDisplacement = 2, VerticalDisplacement = 3, ClusterSnapshots = new List <ClusterSnapshot> { new ClusterSnapshot { ClusterCount = 2, ClusterId = 1 } } }; var secondPoint = new ClusteredPoint { PointId = 2, HorizontalDisplacement = 4, VerticalDisplacement = 5, ClusterSnapshots = new List <ClusterSnapshot> { new ClusterSnapshot { ClusterCount = 3, ClusterId = 2 } } }; var thirdPoint = new ClusteredPoint { PointId = 3, HorizontalDisplacement = 6, VerticalDisplacement = 7, ClusterSnapshots = new List <ClusterSnapshot> { new ClusterSnapshot { ClusterCount = 4, ClusterId = 1 } } }; var clusters = new List <Cluster <ClusteredPoint> > { new Cluster <ClusteredPoint> { ClusterId = 1, Points = new List <ClusteredPoint> { firstPoint, secondPoint } }, new Cluster <ClusteredPoint> { ClusterId = 2, Points = new List <ClusteredPoint> { thirdPoint } } }; var actualRecordedClusters = AgglomerativeHierarchicalClusteringService.RecordClusters(clusters); var recordedFirstPoint = firstPoint.GetShallowCopy(); var recordedSecondPoint = secondPoint.GetShallowCopy(); var recordedThirdPoint = thirdPoint.GetShallowCopy(); recordedFirstPoint.ClusterSnapshots.Append(new ClusterSnapshot { ClusterId = 1, ClusterCount = 3 }); recordedSecondPoint.ClusterSnapshots.Append(new ClusterSnapshot { ClusterId = 2, ClusterCount = 3 }); recordedThirdPoint.ClusterSnapshots.Append(new ClusterSnapshot { ClusterId = 2, ClusterCount = 3 }); var expectedRecordedClusters = new List <Cluster <ClusteredPoint> > { new Cluster <ClusteredPoint> { ClusterId = 1, Points = new List <ClusteredPoint> { recordedFirstPoint, recordedSecondPoint } }, new Cluster <ClusteredPoint> { ClusterId = 2, Points = new List <ClusteredPoint> { recordedThirdPoint } } }; Assert.IsTrue(ListComparer.Compare(actualRecordedClusters, expectedRecordedClusters)); }