<commit_before>﻿namespace prefSQL.SQLParserTest
{
    using System.Collections.Generic;
    using System.Data;
    using System.Diagnostics;
    using System.Globalization;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using prefSQL.SQLParser;
    using prefSQL.SQLSkyline;

    [TestClass]
    public class HelperIntegrationTests
    {
        private const string DbConnection = "Data Source=localhost;Initial Catalog=eCommerce;Integrated Security=True";
        private const string DbProvider = "System.Data.SqlClient";

        public TestContext TestContext { get; set; }

        [TestMethod]
        [DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "HelperIntegrationTests.xml",
            "TestDataRow", DataAccessMethod.Sequential),
         DeploymentItem("HelperIntegrationTests.xml")]
        public void TestOnlyNonDominatedObjectsWithinSampleSkylineViaGetSkyline()
        {
            var skylineSampleSql = TestContext.DataRow["skylineSampleSQL"].ToString();
            var entireSkylineSql = TestContext.DataRow["entireSkylineSQL"].ToString();
            var testComment = TestContext.DataRow["comment"].ToString();
            Debug.WriteLine(testComment);
            Debug.WriteLine(skylineSampleSql);

            var common = new SQLCommon {SkylineType = new SkylineBNL()};

            var prefSqlModelSkylineSample = common.GetPrefSqlModelFromPreferenceSql(skylineSampleSql);
            var prefSqlModelEntireSkyline = common.GetPrefSqlModelFromPreferenceSql(entireSkylineSql);
            var subjectUnderTest = new Helper
            {
                ConnectionString = DbConnection,
                DriverString = DbProvider
            };

            var sw = new Stopwatch();
            sw.Start();
            var entireSkyline = subjectUnderTest.getResults(
                common.GetAnsiSqlFromPrefSqlModel(prefSqlModelEntireSkyline), common.SkylineType,
                prefSqlModelEntireSkyline);
            sw.Stop();
            Debug.WriteLine("ORIG Elapsed={0}", sw.Elapsed);
            sw.Restart();
            var sampleSkyline = subjectUnderTest.getResults(
                common.GetAnsiSqlFromPrefSqlModel(prefSqlModelSkylineSample), common.SkylineType,
                prefSqlModelSkylineSample);
            sw.Stop();
            Debug.WriteLine("SMPL Elapsed={0}", sw.Elapsed);

            var entireSkylineObjectsIds = GetHashSetOfIdsFromDataTable(entireSkyline);
            var sampleSkylineObjectsIds = GetHashSetOfIdsFromDataTable(sampleSkyline);
            Debug.WriteLine("ORIG Count={0}", entireSkylineObjectsIds.Count);
            Debug.WriteLine("SMPL Count={0}", sampleSkylineObjectsIds.Count);

            Assert.IsTrue(sampleSkylineObjectsIds.IsSubsetOf(entireSkylineObjectsIds),
                "Dominated objects contained in Sample Skyline (i.e., objects which are not contained in the entire Skyline).");
        }

        private static HashSet<int> GetHashSetOfIdsFromDataTable(DataTable entireSkyline)
        {
            var entireSkylineObjectsIds = new HashSet<int>();
            foreach (DataRow entireSkylineRow in entireSkyline.Rows)
            {
                entireSkylineObjectsIds.Add(int.Parse(entireSkylineRow["id"].ToString()));
            }
            return entireSkylineObjectsIds;
        }<commit_msg>minor cosmetics<commit_after>﻿namespace prefSQL.SQLParserTest
{
    using System.Collections.Generic;
    using System.Data;
    using System.Diagnostics;
    using System.Globalization;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using prefSQL.SQLParser;
    using prefSQL.SQLSkyline;

    [TestClass]
    public class HelperIntegrationTests
    {
        private const string DbConnection = "Data Source=localhost;Initial Catalog=eCommerce;Integrated Security=True";
        private const string DbProvider = "System.Data.SqlClient";

        public TestContext TestContext { get; set; }

        [TestMethod]
        [DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "HelperIntegrationTests.xml",
            "TestDataRow", DataAccessMethod.Sequential),
         DeploymentItem("HelperIntegrationTests.xml")]
        public void TestOnlyNonDominatedObjectsWithinSampleSkylineViaGetSkyline()
        {
            var skylineSampleSql = TestContext.DataRow["skylineSampleSQL"].ToString();
            var entireSkylineSql = TestContext.DataRow["entireSkylineSQL"].ToString();
            var testComment = TestContext.DataRow["comment"].ToString();
            Debug.WriteLine(testComment);
            Debug.WriteLine(skylineSampleSql);

            var common = new SQLCommon {SkylineType = new SkylineBNL()};

            var prefSqlModelSkylineSample = common.GetPrefSqlModelFromPreferenceSql(skylineSampleSql);
            var prefSqlModelEntireSkyline = common.GetPrefSqlModelFromPreferenceSql(entireSkylineSql);
            var subjectUnderTest = new Helper
            {
                ConnectionString = DbConnection,
                DriverString = DbProvider
            };

            var sw = new Stopwatch();
            sw.Start();
            var entireSkyline = subjectUnderTest.getResults(
                common.GetAnsiSqlFromPrefSqlModel(prefSqlModelEntireSkyline), common.SkylineType,
                prefSqlModelEntireSkyline);
            sw.Stop();
            Debug.WriteLine("ORIG ElapsedMilliseconds={0}", sw.ElapsedMilliseconds);
            Debug.WriteLine("ORIG Algorithm ElapsedMilliseconds={0}", subjectUnderTest.timeInMilliseconds);
            sw.Restart();
            var sampleSkyline = subjectUnderTest.getResults(
                common.GetAnsiSqlFromPrefSqlModel(prefSqlModelSkylineSample), common.SkylineType,
                prefSqlModelSkylineSample);
            sw.Stop();
            Debug.WriteLine("SMPL ElapsedMilliseconds={0}", sw.ElapsedMilliseconds);
            Debug.WriteLine("SMPL Algorithm ElapsedMilliseconds={0}", subjectUnderTest.timeInMilliseconds); 

            var entireSkylineObjectsIds = GetHashSetOfIdsFromDataTable(entireSkyline);
            var sampleSkylineObjectsIds = GetHashSetOfIdsFromDataTable(sampleSkyline);
            Debug.WriteLine("ORIG Count={0}", entireSkylineObjectsIds.Count);
            Debug.WriteLine("SMPL Count={0}", sampleSkylineObjectsIds.Count);

            Assert.IsTrue(sampleSkylineObjectsIds.IsSubsetOf(entireSkylineObjectsIds),
                "Dominated objects contained in Sample Skyline (i.e., objects which are not contained in the entire Skyline).");
        }

        private static HashSet<int> GetHashSetOfIdsFromDataTable(DataTable entireSkyline)
        {
            var entireSkylineObjectsIds = new HashSet<int>();
            foreach (DataRow entireSkylineRow in entireSkyline.Rows)
            {
                entireSkylineObjectsIds.Add(int.Parse(entireSkylineRow["id"].ToString()));
            }
            return entireSkylineObjectsIds;
        }
{'fraction_non_alphanumeric': 0.08380129589632829, 'fraction_numerical': 0.0014398848092152627, 'mean_word_length': 2.8481994459833797, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1199237', 'n_tokens_mistral': 1851, 'n_tokens_neox': 1739, 'n_words': 311}