<commit_before>﻿using System;
using System.Data;
using System.Linq;
using NBi.Service;
using NUnit.Framework;

namespace NBi.Testing.Unit.Service
{
    [TestFixture]
    public class TestCasesManagerTest
    {
        [Test]
        public void Filter_Equal_CorrectNewContent()
        {
            var manager = new TestCasesManager();
            //Setup content;
            manager.Content.Columns.Add(new DataColumn("columnName"));
            manager.Variables.Add("columnName");
            var matchingRow = manager.Content.NewRow();
            matchingRow[0]="matching";
            var nonMatchingRow = manager.Content.NewRow();
            nonMatchingRow[0]="xyz";
            manager.Content.Rows.Add(matchingRow);
            manager.Content.Rows.Add(nonMatchingRow);
            manager.Content.AcceptChanges();

            //Setup filter
            manager.Filter("columnName", Operator.Equal, false, "matching");

            Assert.That(manager.Content.Rows, Has.Count.EqualTo(1));
            Assert.That(manager.Content.Rows[0][0], Is.EqualTo("matching"));
        }

        [Test]
        public void Filter_NotEqual_CorrectNewContent()
        {
            var manager = new TestCasesManager();
            //Setup content;
            manager.Content.Columns.Add(new DataColumn("columnName"));
            manager.Variables.Add("columnName");
            var matchingRow = manager.Content.NewRow();
            matchingRow[0] = "matching";
            var nonMatchingRow = manager.Content.NewRow();
            nonMatchingRow[0] = "xyz";
            manager.Content.Rows.Add(matchingRow);
            manager.Content.Rows.Add(nonMatchingRow);
            manager.Content.AcceptChanges();

            //Setup filter
            manager.Filter("columnName", Operator.Equal, true, "matching");

            Assert.That(manager.Content.Rows, Has.Count.EqualTo(1));
            Assert.That(manager.Content.Rows[0][0], Is.Not.EqualTo("matching"));
        }

        [Test]
        public void Filter_LikeStart_CorrectNewContent()
        {
            var manager = new TestCasesManager();
            //Setup content;
            manager.Content.Columns.Add(new DataColumn("columnName"));
            manager.Variables.Add("columnName");
            var matchingRow = manager.Content.NewRow();
            matchingRow[0] = "matching";
            var nonMatchingRow = manager.Content.NewRow();
            nonMatchingRow[0] = "xyz";
            manager.Content.Rows.Add(matchingRow);
            manager.Content.Rows.Add(nonMatchingRow);
            manager.Content.AcceptChanges();

            //Setup filter
            manager.Filter("columnName", Operator.Like, false, "match%");

            Assert.That(manager.Content.Rows, Has.Count.EqualTo(1));
            Assert.That(manager.Content.Rows[0][0], Is.EqualTo("matching"));
        }

        [Test]
        public void Filter_LikeEnd_CorrectNewContent()
        {
            var manager = new TestCasesManager();
            //Setup content;
            manager.Content.Columns.Add(new DataColumn("columnName"));
            manager.Variables.Add("columnName");
            var matchingRow = manager.Content.NewRow();
            matchingRow[0] = "matching";
            var nonMatchingRow = manager.Content.NewRow();
            nonMatchingRow[0] = "xyz";
            manager.Content.Rows.Add(matchingRow);
            manager.Content.Rows.Add(nonMatchingRow);
            manager.Content.AcceptChanges();

            //Setup filter
            manager.Filter("columnName", Operator.Like, false, "%ing");

            Assert.That(manager.Content.Rows, Has.Count.EqualTo(1));
            Assert.That(manager.Content.Rows[0][0], Is.EqualTo("matching"));
        }

        [Test]
        public void Filter_LikeContain_CorrectNewContent()
        {
            var manager = new TestCasesManager();
            //Setup content;
            manager.Content.Columns.Add(new DataColumn("columnName"));
            manager.Variables.Add("columnName");
            var matchingRow = manager.Content.NewRow();
            matchingRow[0] = "matching";
            var nonMatchingRow = manager.Content.NewRow();
            nonMatchingRow[0] = "xyz";
            manager.Content.Rows.Add(matchingRow);
            manager.Content.Rows.Add(nonMatchingRow);
            manager.Content.AcceptChanges();

            //Setup filter
            manager.Filter("columnName", Operator.Like, false, "%atch%");

            Assert.That(manager.Content.Rows, Has.Count.EqualTo(1));
            Assert.That(manager.Content.Rows[0][0], Is.EqualTo("matching"));
        }
        
        [Test]
        public void Filter_LikeContainBounded_CorrectNewContent()
        {
            var manager = new TestCasesManager();
            //Setup content;
            manager.Content.Columns.Add(new DataColumn("columnName"));
            manager.Variables.Add("columnName");
            var matchingRow = manager.Content.NewRow();
            matchingRow[0] = "matching";
            var nonMatchingRow = manager.Content.NewRow();
            nonMatchingRow[0] = "xyz";
            manager.Content.Rows.Add(matchingRow);
            manager.Content.Rows.Add(nonMatchingRow);
            manager.Content.AcceptChanges();

            //Setup filter
            manager.Filter("columnName", Operator.Like, false, "%matching%");

            Assert.That(manager.Content.Rows, Has.Count.EqualTo(1));
            Assert.That(manager.Content.Rows[0][0], Is.EqualTo("matching"));
        }

        [Test]
        public void Filter_LikeContainComplex_CorrectNewContent()
        {
            var manager = new TestCasesManager();
            //Setup content;
            manager.Content.Columns.Add(new DataColumn("columnName"));
            manager.Variables.Add("columnName");
            var matchingRow = manager.Content.NewRow();
            matchingRow[0] = "matching";
            var nonMatchingRow = manager.Content.NewRow();
            nonMatchingRow[0] = "xyz";
            manager.Content.Rows.Add(matchingRow);
            manager.Content.Rows.Add(nonMatchingRow);
            manager.Content.AcceptChanges();

            //Setup filter
            manager.Filter("columnName", Operator.Like, false, "ma%h%ng%");

            Assert.That(manager.Content.Rows, Has.Count.EqualTo(1));
            Assert.That(manager.Content.Rows[0][0], Is.EqualTo("matching"));
        }
    }
}<commit_msg>Tested filter distinct implementation<commit_after>﻿using System;
using System.Data;
using System.Linq;
using NBi.Service;
using NUnit.Framework;

namespace NBi.Testing.Unit.Service
{
    [TestFixture]
    public class TestCasesManagerTest
    {
        [Test]
        public void Filter_Equal_CorrectNewContent()
        {
            var manager = new TestCasesManager();
            //Setup content;
            manager.Content.Columns.Add(new DataColumn("columnName"));
            manager.Variables.Add("columnName");
            var matchingRow = manager.Content.NewRow();
            matchingRow[0]="matching";
            var nonMatchingRow = manager.Content.NewRow();
            nonMatchingRow[0]="xyz";
            manager.Content.Rows.Add(matchingRow);
            manager.Content.Rows.Add(nonMatchingRow);
            manager.Content.AcceptChanges();

            //Setup filter
            manager.Filter("columnName", Operator.Equal, false, "matching");

            Assert.That(manager.Content.Rows, Has.Count.EqualTo(1));
            Assert.That(manager.Content.Rows[0][0], Is.EqualTo("matching"));
        }

        [Test]
        public void Filter_NotEqual_CorrectNewContent()
        {
            var manager = new TestCasesManager();
            //Setup content;
            manager.Content.Columns.Add(new DataColumn("columnName"));
            manager.Variables.Add("columnName");
            var matchingRow = manager.Content.NewRow();
            matchingRow[0] = "matching";
            var nonMatchingRow = manager.Content.NewRow();
            nonMatchingRow[0] = "xyz";
            manager.Content.Rows.Add(matchingRow);
            manager.Content.Rows.Add(nonMatchingRow);
            manager.Content.AcceptChanges();

            //Setup filter
            manager.Filter("columnName", Operator.Equal, true, "matching");

            Assert.That(manager.Content.Rows, Has.Count.EqualTo(1));
            Assert.That(manager.Content.Rows[0][0], Is.Not.EqualTo("matching"));
        }

        [Test]
        public void Filter_LikeStart_CorrectNewContent()
        {
            var manager = new TestCasesManager();
            //Setup content;
            manager.Content.Columns.Add(new DataColumn("columnName"));
            manager.Variables.Add("columnName");
            var matchingRow = manager.Content.NewRow();
            matchingRow[0] = "matching";
            var nonMatchingRow = manager.Content.NewRow();
            nonMatchingRow[0] = "xyz";
            manager.Content.Rows.Add(matchingRow);
            manager.Content.Rows.Add(nonMatchingRow);
            manager.Content.AcceptChanges();

            //Setup filter
            manager.Filter("columnName", Operator.Like, false, "match%");

            Assert.That(manager.Content.Rows, Has.Count.EqualTo(1));
            Assert.That(manager.Content.Rows[0][0], Is.EqualTo("matching"));
        }

        [Test]
        public void Filter_LikeEnd_CorrectNewContent()
        {
            var manager = new TestCasesManager();
            //Setup content;
            manager.Content.Columns.Add(new DataColumn("columnName"));
            manager.Variables.Add("columnName");
            var matchingRow = manager.Content.NewRow();
            matchingRow[0] = "matching";
            var nonMatchingRow = manager.Content.NewRow();
            nonMatchingRow[0] = "xyz";
            manager.Content.Rows.Add(matchingRow);
            manager.Content.Rows.Add(nonMatchingRow);
            manager.Content.AcceptChanges();

            //Setup filter
            manager.Filter("columnName", Operator.Like, false, "%ing");

            Assert.That(manager.Content.Rows, Has.Count.EqualTo(1));
            Assert.That(manager.Content.Rows[0][0], Is.EqualTo("matching"));
        }

        [Test]
        public void Filter_LikeContain_CorrectNewContent()
        {
            var manager = new TestCasesManager();
            //Setup content;
            manager.Content.Columns.Add(new DataColumn("columnName"));
            manager.Variables.Add("columnName");
            var matchingRow = manager.Content.NewRow();
            matchingRow[0] = "matching";
            var nonMatchingRow = manager.Content.NewRow();
            nonMatchingRow[0] = "xyz";
            manager.Content.Rows.Add(matchingRow);
            manager.Content.Rows.Add(nonMatchingRow);
            manager.Content.AcceptChanges();

            //Setup filter
            manager.Filter("columnName", Operator.Like, false, "%atch%");

            Assert.That(manager.Content.Rows, Has.Count.EqualTo(1));
            Assert.That(manager.Content.Rows[0][0], Is.EqualTo("matching"));
        }
        
        [Test]
        public void Filter_LikeContainBounded_CorrectNewContent()
        {
            var manager = new TestCasesManager();
            //Setup content;
            manager.Content.Columns.Add(new DataColumn("columnName"));
            manager.Variables.Add("columnName");
            var matchingRow = manager.Content.NewRow();
            matchingRow[0] = "matching";
            var nonMatchingRow = manager.Content.NewRow();
            nonMatchingRow[0] = "xyz";
            manager.Content.Rows.Add(matchingRow);
            manager.Content.Rows.Add(nonMatchingRow);
            manager.Content.AcceptChanges();

            //Setup filter
            manager.Filter("columnName", Operator.Like, false, "%matching%");

            Assert.That(manager.Content.Rows, Has.Count.EqualTo(1));
            Assert.That(manager.Content.Rows[0][0], Is.EqualTo("matching"));
        }

        [Test]
        public void Filter_LikeContainComplex_CorrectNewContent()
        {
            var manager = new TestCasesManager();
            //Setup content;
            manager.Content.Columns.Add(new DataColumn("columnName"));
            manager.Variables.Add("columnName");
            var matchingRow = manager.Content.NewRow();
            matchingRow[0] = "matching";
            var nonMatchingRow = manager.Content.NewRow();
            nonMatchingRow[0] = "xyz";
            manager.Content.Rows.Add(matchingRow);
            manager.Content.Rows.Add(nonMatchingRow);
            manager.Content.AcceptChanges();

            //Setup filter
            manager.Filter("columnName", Operator.Like, false, "ma%h%ng%");

            Assert.That(manager.Content.Rows, Has.Count.EqualTo(1));
            Assert.That(manager.Content.Rows[0][0], Is.EqualTo("matching"));
        }

        [Test]
        public void Filter_Distinct_CorrectNewContent()
        {
            var manager = new TestCasesManager();
            //Setup content;
            manager.Content.Columns.Add(new DataColumn("columnName"));
            manager.Variables.Add("columnName");
            var firstRow = manager.Content.NewRow();
            firstRow[0] = "alpha";
            var secondRow = manager.Content.NewRow();
            secondRow[0] = "beta";
            var duplicatedRow = manager.Content.NewRow();
            duplicatedRow[0] = "alpha";
            manager.Content.Rows.Add(firstRow);
            manager.Content.Rows.Add(secondRow);
            manager.Content.Rows.Add(duplicatedRow);
            manager.Content.AcceptChanges();

            //Setup filter
            manager.FilterDistinct();

            Assert.That(manager.Content.Rows, Has.Count.EqualTo(2));
            Assert.That(manager.Content.Rows[0][0], Is.EqualTo("alpha"));
            Assert.That(manager.Content.Rows[1][0], Is.EqualTo("beta"));
        }
    }
}
{'fraction_non_alphanumeric': 0.1265370317414927, 'fraction_numerical': 0.0055762081784386614, 'mean_word_length': 2.101086233651075, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '4884813', 'n_tokens_mistral': 3708, 'n_tokens_neox': 3606, 'n_words': 576}