public void GetIntraclusterDistancesTest()
        {
            var clusteringSummaryService = new ClusteringSummaryService(new FakeDistanceService());
            var clusteredPoints          = new List <ClusterPoint>
            {
                new ClusterPoint
                {
                    ClusterId = 1,
                    HorizontalDisplacement = 1,
                    VerticalDisplacement   = 0
                },
                new ClusterPoint
                {
                    ClusterId = 1,
                    HorizontalDisplacement = 3,
                    VerticalDisplacement   = 0
                },
                new ClusterPoint
                {
                    ClusterId = 2,
                    HorizontalDisplacement = 1,
                    VerticalDisplacement   = 2
                },
                new ClusterPoint
                {
                    ClusterId = 2,
                    HorizontalDisplacement = 1,
                    VerticalDisplacement   = 4
                },
                new ClusterPoint
                {
                    ClusterId = 2,
                    HorizontalDisplacement = 1,
                    VerticalDisplacement   = 6
                },
            };

            var actualIntraclusterDistances = clusteringSummaryService.GetIntraclusterDistances(clusteredPoints);

            var expectedIntraclusterDistances = new List <IntraclusterDistance>
            {
                new IntraclusterDistance
                {
                    ClusterId = 1,
                    Distance  = 1
                },
                new IntraclusterDistance
                {
                    ClusterId = 2,
                    Distance  = 4.0 / 3
                }
            };

            Assert.IsTrue(ListComparer.Compare(actualIntraclusterDistances, expectedIntraclusterDistances));
        }
Example #2
0
        public void Compare_MissingAndOneMissingItem_MissingHasCountOfOneWithCorrectMissingItem()
        {
            var listComparer = new ListComparer();
            var res          = listComparer.Compare(
                new List <string> {
                "a", "b", "z"
            },
                new List <string> {
                "a", "b"
            },
                ListComparer.Comparison.Both
                );

            Assert.That(res.Missing, Has.Count.EqualTo(1));
            Assert.That(res.Missing.ElementAt(0), Is.EqualTo("z"));
        }
Example #3
0
        public void Compare_BothWithMissingAndUnexpectedItems_MissingUnexpectedNotNullAndNotEmpty()
        {
            var listComparer = new ListComparer();
            var res          = listComparer.Compare(
                new List <string> {
                "a", "b", "c"
            },
                new List <string> {
                "a", "b", "d"
            },
                ListComparer.Comparison.Both
                );

            Assert.That(res.Missing, Is.Not.Null.And.Not.Empty);
            Assert.That(res.Unexpected, Is.Not.Null.And.Not.Empty);
        }
Example #4
0
        public void Compare_Missing_MissingNullUnexpectedNotNull()
        {
            var listComparer = new ListComparer();
            var res          = listComparer.Compare(
                new List <string> {
                "a", "b", "c"
            },
                new List <string> {
                "a", "b", "c"
            },
                ListComparer.Comparison.UnexpectedItems
                );

            Assert.That(res.Missing, Is.Null.Or.Empty);
            Assert.That(res.Unexpected, Is.Not.Null);
        }
Example #5
0
        public void Compare_Both_MissingUnexpectedNotNull()
        {
            var listComparer = new ListComparer();
            var res          = listComparer.Compare(
                new List <string> {
                "a", "b", "c"
            },
                new List <string> {
                "a", "b", "c"
            },
                ListComparer.Comparison.Both
                );

            Assert.That(res.Missing, Is.Not.Null);
            Assert.That(res.Unexpected, Is.Not.Null);
        }
Example #6
0
        public void Compare_UnexpectedAndOneUnexpectedItem_UnexpectedHasCountOfOneWithCorrectUnexpectedItem()
        {
            var listComparer = new ListComparer();
            var res          = listComparer.Compare(
                new List <string> {
                "a", "b"
            },
                new List <string> {
                "a", "b", "z"
            },
                ListComparer.Comparison.Both
                );

            Assert.That(res.Unexpected, Has.Count.EqualTo(1));
            Assert.That(res.Unexpected.ElementAt(0), Is.EqualTo("z"));
        }
        public void SolveTest()
        {
            var vertices = new [] { 0, 1, 2, 3 };
            var matrix   = new double[, ]
            {
                { 0, 10, 15, 20 },
                { 5, 0, 9, 10 },
                { 6, 13, 0, 12 },
                { 8, 8, 9, 0 }
            };

            var expectedRoute = new [] { 0, 1, 3, 2, 0 };

            var DynamicProgramming = new TourProvider(vertices, matrix);
            var route = DynamicProgramming.Solve();

            Assert.IsTrue(ListComparer.Compare(expectedRoute, route.ToArray()));
        }
Example #8
0
        public void Sample_LessThan10Items_DontThrowException()
        {
            var listComparer = new ListComparer();
            var res          = listComparer.Compare(
                new List <string> {
                "a", "b", "c", "d", "e", "f", "g", "h"
            },
                new List <string> {
                "z"
            },
                ListComparer.Comparison.Both
                );

            var sampledRes = res.Sample(2);

            Assert.That(sampledRes.Missing.Count(), Is.EqualTo(2));
            Assert.That(sampledRes.MissingCount, Is.GreaterThan(2));

            Assert.That(sampledRes.Unexpected.Count(), Is.EqualTo(1));
            Assert.That(sampledRes.UnexpectedCount, Is.EqualTo(1));
        }
Example #9
0
        /// <summary>
        /// Сравнение результатов расчетов с эталонными
        /// </summary>
        /// <param name="data">Данные из xml</param>
        /// <param name="sorce">Данные с формы</param>
        /// <returns></returns>
        public static void RegistryValidation(BonusCalculationData data, List <RegistryLine> sorce)
        {
            Trace("Сравниваем результаты расчетов с эталонными данными");
            var resultCompare = ListComparer <List <RegistryLine> > .Compare(data.RegistryResult, sorce);

            if (resultCompare > 0)
            {
                if (resultCompare == 1)
                {
                    Trace("Есть ошибки в расчете");
                    Assert.Fail("Есть ошибки в расчете");
                }
                else if (resultCompare == 2)
                {
                    string ErrorMsg = string.Format("Количество строк не совпало ожидаем = {0}, найдено = {1}", data.RegistryResult.Count, sorce.Count);
                    Trace(ErrorMsg);
                    Assert.Fail(ErrorMsg);
                }
            }
            else
            {
                Trace("Расчет проведен верно");
            }
        }
        public void TestGetValidItems()
        {
            var options = new DbContextOptionsBuilder <DatabaseContext>().UseInMemoryDatabase("TEST_DATABASE", new InMemoryDatabaseRoot()).Options;

            using (var context = new DatabaseContext(options))

            {
                var items = new List <Item>
                {
                    new Item
                    {
                        ItemId               = 1,
                        ItemTypeId           = ItemType.PointsGroup,
                        ItemPermissionTypeId = ItemPermissionType.Public
                    },
                    new Item
                    {
                        ItemId               = 2,
                        ItemTypeId           = ItemType.PointsGroup,
                        ItemPermissionTypeId = ItemPermissionType.Private,
                    },
                    new Item
                    {
                        ItemId               = 3,
                        ItemTypeId           = ItemType.PointsGroup,
                        ItemPermissionTypeId = ItemPermissionType.Private
                    },
                    new Item
                    {
                        ItemId               = 4,
                        ItemTypeId           = ItemType.PointsGroup,
                        ItemPermissionTypeId = ItemPermissionType.Public,
                        DateDeleted          = DateTime.Now
                    }
                };

                var userItems = new List <UserItem>
                {
                    new UserItem
                    {
                        ItemId = 1,
                        UserId = UserId
                    },
                    new UserItem
                    {
                        ItemId = 3,
                        UserId = SomeOtherUserId
                    },
                    new UserItem
                    {
                        ItemId = 4,
                        UserId = UserId
                    }
                };

                context.AddRange(items);
                context.AddRange(userItems);
                context.SaveChanges();

                var expectedValidItems = new List <Item>
                {
                    new Item
                    {
                        ItemId               = 1,
                        ItemTypeId           = ItemType.PointsGroup,
                        ItemPermissionTypeId = ItemPermissionType.Public
                    }
                };

                var itemFilterer = new ItemFilterer(context);

                var actualValidItems = itemFilterer.GetValidItems(UserId, items);

                Assert.IsTrue(ListComparer.Compare(actualValidItems, expectedValidItems));
            }
        }
Example #11
0
        public override bool Equals(object obj)
        {
            var cluster = (Cluster <T>)obj;

            return(cluster.ClusterId == this.ClusterId && ListComparer.Compare(cluster.Points, this.Points));
        }
Example #12
0
        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));
        }
Example #13
0
        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));
        }
Example #14
0
        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));
        }