示例#1
0
        public void TestSamplingGetCoverage()
        {
            DataRow[] itemsToBeCovered =
                TestContext.DataRow.GetChildRows("TestDataRow_itemsToBeCovered")[0].GetChildRows("itemsToBeCovered_item");
            DataRow[] itemsCoveringDataToBeCovered =
                TestContext.DataRow.GetChildRows("TestDataRow_itemsCoveringDataToBeCovered")[0].GetChildRows("itemsCoveringDataToBeCovered_item");

            var normalizedDataToBeCovered             = new Dictionary <long, object[]>();
            var normalizedDataCoveringDataToBeCovered = new Dictionary <long, object[]>();

            foreach (DataRow row in itemsToBeCovered)
            {
                object[] objectTemp = ((string)row[0]).Split(',')
                                      .Select(item => Convert.ToDouble(item, CultureInfo.InvariantCulture))
                                      .Select(item => (object)item)
                                      .ToArray();
                normalizedDataToBeCovered.Add(((string)row[0]).GetHashCode(), objectTemp);
            }

            foreach (DataRow row in itemsCoveringDataToBeCovered)
            {
                object[] objectTemp = ((string)row[0]).Split(',')
                                      .Select(item => Convert.ToDouble(item, CultureInfo.InvariantCulture))
                                      .Select(item => (object)item)
                                      .ToArray();
                normalizedDataCoveringDataToBeCovered.Add(((string)row[0]).GetHashCode(), objectTemp);
            }

            double expectedCoverage = Convert.ToDouble(TestContext.DataRow["expectedCoverage"].ToString(),
                                                       CultureInfo.InvariantCulture);

            var useColumns = new int[((string)itemsToBeCovered[0][0]).Split(',').ToArray().Length];

            for (var i = 0; i < useColumns.Length; i++)
            {
                useColumns[i] = i;
            }

            double actualCoverage = SetCoverage.GetCoverage(normalizedDataToBeCovered, normalizedDataCoveringDataToBeCovered, useColumns);

            Assert.AreEqual(expectedCoverage, actualCoverage, 0.000000000001);
        }
示例#2
0
        private void TestForSetCoverage()
        {
            var common = new SQLCommon
            {
                SkylineType =
                    new SkylineBNL()
                {
                    Provider = Helper.ProviderName, ConnectionString = Helper.ConnectionString
                },
                ShowInternalAttributes = true
            };

            DataTable entireSkylineDataTable = common.ParseAndExecutePrefSQL(Helper.ConnectionString,
                                                                             Helper.ProviderName, _entireSkylineSql);

            //Console.WriteLine("time entire: " + common.TimeInMilliseconds);
            //Console.WriteLine("count entire: " + entireSkylineDataTable.Rows.Count);

            int[] skylineAttributeColumns = SkylineSamplingHelper.GetSkylineAttributeColumns(entireSkylineDataTable);
            IReadOnlyDictionary <long, object[]> entireSkylineNormalized =
                prefSQL.SQLSkyline.Helper.GetDatabaseAccessibleByUniqueId(entireSkylineDataTable, 0);

            SkylineSamplingHelper.NormalizeColumns(entireSkylineNormalized, skylineAttributeColumns);

            for (var i = 0; i < 10; i++)
            {
                DataTable sampleSkylineDataTable = common.ParseAndExecutePrefSQL(Helper.ConnectionString,
                                                                                 Helper.ProviderName, _skylineSampleSql);
                Console.WriteLine("time sample: " + common.TimeInMilliseconds);
                Console.WriteLine("count sample: " + sampleSkylineDataTable.Rows.Count);

                IReadOnlyDictionary <long, object[]> sampleSkylineNormalized =
                    prefSQL.SQLSkyline.Helper.GetDatabaseAccessibleByUniqueId(sampleSkylineDataTable, 0);
                SkylineSamplingHelper.NormalizeColumns(sampleSkylineNormalized, skylineAttributeColumns);

                IReadOnlyDictionary <long, object[]> baseRandomSampleNormalized =
                    SkylineSamplingHelper.GetRandomSample(entireSkylineNormalized,
                                                          sampleSkylineDataTable.Rows.Count);
                IReadOnlyDictionary <long, object[]> secondRandomSampleNormalized =
                    SkylineSamplingHelper.GetRandomSample(entireSkylineNormalized,
                                                          sampleSkylineDataTable.Rows.Count);

                double setCoverageCoveredBySecondRandomSample = SetCoverage.GetCoverage(baseRandomSampleNormalized,
                                                                                        secondRandomSampleNormalized, skylineAttributeColumns);
                double setCoverageCoveredBySkylineSample = SetCoverage.GetCoverage(baseRandomSampleNormalized,
                                                                                   sampleSkylineNormalized, skylineAttributeColumns);

                DataTable entireSkylineDataTableBestRank = common.ParseAndExecutePrefSQL(Helper.ConnectionString,
                                                                                         Helper.ProviderName,
                                                                                         _entireSkylineSqlBestRank.Replace("XXX", sampleSkylineDataTable.Rows.Count.ToString()));
                DataTable entireSkylineDataTableSumRank = common.ParseAndExecutePrefSQL(Helper.ConnectionString,
                                                                                        Helper.ProviderName,
                                                                                        _entireSkylineSqlSumRank.Replace("XXX", sampleSkylineDataTable.Rows.Count.ToString()));

                IReadOnlyDictionary <long, object[]> entireSkylineDataTableBestRankNormalized =
                    prefSQL.SQLSkyline.Helper.GetDatabaseAccessibleByUniqueId(entireSkylineDataTableBestRank, 0);
                SkylineSamplingHelper.NormalizeColumns(entireSkylineDataTableBestRankNormalized, skylineAttributeColumns);
                IReadOnlyDictionary <long, object[]> entireSkylineDataTableSumRankNormalized =
                    prefSQL.SQLSkyline.Helper.GetDatabaseAccessibleByUniqueId(entireSkylineDataTableSumRank, 0);
                SkylineSamplingHelper.NormalizeColumns(entireSkylineDataTableSumRankNormalized, skylineAttributeColumns);

                double setCoverageCoveredByEntireBestRank = SetCoverage.GetCoverage(baseRandomSampleNormalized,
                                                                                    entireSkylineDataTableBestRankNormalized, skylineAttributeColumns);
                double setCoverageCoveredByEntireSumRank = SetCoverage.GetCoverage(baseRandomSampleNormalized,
                                                                                   entireSkylineDataTableSumRankNormalized, skylineAttributeColumns);

                Console.WriteLine("sc second random: " + setCoverageCoveredBySecondRandomSample);
                Console.WriteLine("sc sample       : " + setCoverageCoveredBySkylineSample);
                Console.WriteLine("sc entire best  : " + setCoverageCoveredByEntireBestRank);
                Console.WriteLine("sc entire sum   : " + setCoverageCoveredByEntireSumRank);
                Console.WriteLine();
                //Console.WriteLine("set coverage covered by second random sample: " +
                //                  setCoverageCoveredBySecondRandomSample);
                //Console.WriteLine("set coverage covered by skyline sample: " + setCoverageCoveredBySkylineSample);
            }
        }