<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using DataGen.Types.Mail;
using NUnit.Framework;
using NUnit.Framework.Internal;

namespace Tests {
    [TestFixture]
    public class MailGeneratorTest {
        #region Mail With One String

        [Test]
        public void Mail_OneDomain_null_CalledOneTime() {
            var mailGenerator = new MailGenerator(new[] { "test.com" },true);
            Assert.Throws<NullReferenceException>(() => mailGenerator.Mail(null));
        }

        [Test]
        public void Mail_OneDomain_OneString_CalledOneTime() {
            var mailGenerator = new MailGenerator(new[] { "test.com" },true);
            const string expected = "<EMAIL>";
            var result = mailGenerator.Mail("bob");
            Assert.AreEqual(expected, result);
        }

        [Test]
        public void Mail_OneDomain_OneString_CalledTwoTimes() {
            var mailGenerator = new MailGenerator(new[] { "test.com" },true);
            mailGenerator.Mail("bob");
            Assert.Throws<Exception>(() => mailGenerator.Mail("bob"));
        }

        [Test]
        public void Mail_TwoDomain_OneString_CalledOneTime() {
            var mailGenerator = new MailGenerator(new[]{"test.com", "foo.com"},true);
            const string expected = "<EMAIL>";
            var result = mailGenerator.Mail("bob");
            Assert.AreEqual(expected, result);
        }

        [Test]
        public void Mail_TwoDomain_OneString_CalledTwoTimes() {
            var mailGenerator = new MailGenerator(new[]{"test.com", "foo.com"},true);
            const string expected = "<EMAIL>";
            mailGenerator.Mail("bob");
            var result = mailGenerator.Mail("bob");
            Assert.AreEqual(expected, result);
        }

        [Test]
        public void Mail_TwoDomain_OneString_CalledThreeTimes() {
            var mailGenerator = new MailGenerator(new[]{"test.com", "foo.com"},true);
            mailGenerator.Mail("bob");
            mailGenerator.Mail("bob");
            Assert.Throws<Exception>(() => mailGenerator.Mail("bob"));
        }

        #endregion

        #region Mail With Two Strings

        [Test]
        public void Mail_OneDomain_TwoStrings_SecondNull() {
            var mailGenerator = new MailGenerator(new []{"test.com"},true);
            var result = mailGenerator.Mail("bob", null);
            const string expected = "<EMAIL>";
            Assert.AreEqual(expected, result);
        }

        [Test]
        public void Mail_OneDomain_TwoStrings_FirstNull() {
            var mailGenerator = new MailGenerator(new []{"test.com"},true);
            Assert.Throws<NullReferenceException>(() => mailGenerator.Mail(null, "bob"));
        }

        [Test]
        public void Mail_OneDomain_TwoStrings_CalledOneTime() {
            var mailGenerator = new MailGenerator(new []{"test.com"},true);
            const string expected = "<EMAIL>";
            var result = mailGenerator.Mail("bob", "cool");
            Assert.AreEqual(expected, result);
        }

        [Test]
        public void Mail_OneDomain_TwoStrings_CalledTwoTimes() {
            var mailGenerator = new MailGenerator(new []{"test.com"},true);
            mailGenerator.Mail("bob", "cool");
            var result = mailGenerator.Mail("bob", "cool");
            const string expected = "<EMAIL>";
            Assert.AreEqual(expected, result);
        }

        [Test]
        public void Mail_OneDomain_TwoStrings_CalledThreeTimes() {
            var mailGenerator = new MailGenerator(new []{"test.com"},true);
            mailGenerator.Mail("bob", "cool");
            mailGenerator.Mail("bob", "cool");
            var result = mailGenerator.Mail("bob", "cool");
            const string expected = "<EMAIL>";

            Assert.AreEqual(expected, result);
        }

        [Test]
        public void Mail_TwoStrings_CalledFourTimes() {
            var mailGenerator = new MailGenerator(new []{"test.com"},true);
            mailGenerator.Mail("bob", "cool");
            mailGenerator.Mail("bob", "cool");
            mailGenerator.Mail("bob", "cool");
            Assert.Throws<Exception>(() => mailGenerator.Mail("bob", "cool"));
        }

        #endregion

        #region Find Duplicates

        [Test]
        public void Mail_OneDomain_TwoStrings_NoDuplicates() {
            var mailGenerator = new MailGenerator(new []{"test.com"},true);
            var mails = Enumerable.Range(1, 3).Select(i => mailGenerator.Mail("john", "doe"));
            Assert.IsTrue(FindDuplicates(mails).Count == 0);
        }

        [Test]
        public void Mail_TwoDomain_TwoStrings_NoDuplicates() {
            var mailGenerator = new MailGenerator(new []{"test.com", "test2.com"},true);
            var mails = Enumerable.Range(1, 6).Select(i => mailGenerator.Mail("john", "doe"));
            Assert.IsTrue(FindDuplicates(mails).Count == 0);
        }

        [Test]
        public void Mail_ThreeDomain_TwoStrings_NoDuplicates() {
            var mailGenerator = new MailGenerator(new []{"test.com", "test2.com", "test3.com"},true);
            var mails = Enumerable.Range(1, 9).Select(i => mailGenerator.Mail("john", "doe"));
            Assert.IsTrue(FindDuplicates(mails).Count == 0);
        }

        [Test]
        public void Mail_FourDomain_TwoStrings_NoDuplicates() {
            var mailGenerator = new MailGenerator(new []{"test.com", "test2.com", "test3.com", "test4.com"},true);
            var mails = Enumerable.Range(1, 12).Select(i => mailGenerator.Mail("john", "doe"));
            Assert.IsTrue(FindDuplicates(mails).Count == 0);
        }

        #endregion

        private static List<string> FindDuplicates(IEnumerable<string> enumerable) {
            return enumerable.GroupBy(x => x)
                .Where(group => group.Count() > 1)
                .Select(group => group.Key).ToList();
        }
    }
}<commit_msg>updated test to secure expected behavious<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using DataGen.Types.Mail;
using NUnit.Framework;
using NUnit.Framework.Internal;

namespace Tests {
    [TestFixture]
    public class MailGeneratorTest {
        #region Mail With One String

        [Test]
        public void Mail_OneDomain_null_CalledOneTime() {
            var mailGenerator = new MailGenerator(new[] { "test.com" }, true);
            Assert.Throws<NullReferenceException>(() => mailGenerator.Mail(null));
        }

        [Test]
        public void Mail_OneDomain_OneString_CalledOneTime() {
            var mailGenerator = new MailGenerator(new[] { "test.com" }, true);
            const string expected = "<EMAIL>";
            var result = mailGenerator.Mail("bob");
            Assert.AreEqual(expected, result);
        }

        [Test]
        public void Mail_OneDomain_OneString_CalledTwoTimes() {
            var mailGenerator = new MailGenerator(new[] { "test.com" }, true);
            //Should not contain any numbers
            Assert.IsTrue(mailGenerator.Mail("bob").Any(c => !char.IsDigit(c)));
            //Should contain a number since all possible combinations have been used
            Assert.IsTrue(mailGenerator.Mail("bob").Any(char.IsDigit));
        }

        [Test]
        public void Mail_TwoDomain_OneString_CalledOneTime() {
            var mailGenerator = new MailGenerator(new[] { "test.com", "foo.com" }, true);
            const string expected = "<EMAIL>";
            var result = mailGenerator.Mail("bob");
            Assert.AreEqual(expected, result);
        }

        [Test]
        public void Mail_TwoDomain_OneString_CalledTwoTimes() {
            var mailGenerator = new MailGenerator(new[] { "test.com", "foo.com" }, true);
            const string expected = "<EMAIL>";
            mailGenerator.Mail("bob");
            var result = mailGenerator.Mail("bob");
            Assert.AreEqual(expected, result);
        }

        [Test]
        public void Mail_TwoDomain_OneString_CalledThreeTimes() {
            var mailGenerator = new MailGenerator(new[] { "test.com", "foo.com" }, true);
            Assert.IsTrue(mailGenerator.Mail("bob").Any(c => !char.IsDigit(c)));
            Assert.IsTrue(mailGenerator.Mail("bob").Any(c => !char.IsDigit(c)));
            // All possible combinations have been used now needs a number
            Assert.IsTrue(mailGenerator.Mail("bob").Any(char.IsDigit));
        }

        #endregion

        #region Mail With Two Strings

        [Test]
        public void Mail_OneDomain_TwoStrings_SecondNull() {
            var mailGenerator = new MailGenerator(new[] { "test.com" }, true);
            var result = mailGenerator.Mail("bob", null);
            const string expected = "<EMAIL>";
            Assert.AreEqual(expected, result);
        }

        [Test]
        public void Mail_OneDomain_TwoStrings_FirstNull() {
            var mailGenerator = new MailGenerator(new[] { "test.com" }, true);
            Assert.Throws<NullReferenceException>(() => mailGenerator.Mail(null, "bob"));
        }

        [Test]
        public void Mail_OneDomain_TwoStrings_CalledOneTime() {
            var mailGenerator = new MailGenerator(new[] { "test.com" }, true);
            const string expected = "<EMAIL>";
            var result = mailGenerator.Mail("bob", "cool");
            Assert.AreEqual(expected, result);
        }

        [Test]
        public void Mail_OneDomain_TwoStrings_CalledTwoTimes() {
            var mailGenerator = new MailGenerator(new[] { "test.com" }, true);
            mailGenerator.Mail("bob", "cool");
            var result = mailGenerator.Mail("bob", "cool");
            const string expected = "<EMAIL>";
            Assert.AreEqual(expected, result);
        }

        [Test]
        public void Mail_OneDomain_TwoStrings_CalledThreeTimes() {
            var mailGenerator = new MailGenerator(new[] { "test.com" }, true);
            mailGenerator.Mail("bob", "cool");
            mailGenerator.Mail("bob", "cool");
            var result = mailGenerator.Mail("bob", "cool");
            const string expected = "<EMAIL>";

            Assert.AreEqual(expected, result);
        }

        [Test]
        public void Mail_TwoStrings_CalledFourTimes() {
            var mailGenerator = new MailGenerator(new[] { "test.com" }, true);
            Assert.IsTrue(mailGenerator.Mail("bob", "cool").Any(c => !char.IsDigit(c)));
            Assert.IsTrue(mailGenerator.Mail("bob", "cool").Any(c => !char.IsDigit(c)));
            Assert.IsTrue(mailGenerator.Mail("bob", "cool").Any(c => !char.IsDigit(c)));
            // All combinations have been reached now needs a number
            Assert.IsTrue(mailGenerator.Mail("bob", "cool").Any(char.IsDigit));
        }

        #endregion

        #region Find Duplicates

        [Test]
        public void Mail_OneDomain_TwoStrings_NoDuplicates() {
            var mailGenerator = new MailGenerator(new[] { "test.com" }, true);
            var mails = Enumerable.Range(1, 3).Select(i => mailGenerator.Mail("john", "doe"));
            Assert.IsTrue(FindDuplicates(mails).Count == 0);
        }

        [Test]
        public void Mail_TwoDomain_TwoStrings_NoDuplicates() {
            var mailGenerator = new MailGenerator(new[] { "test.com", "test2.com" }, true);
            var mails = Enumerable.Range(1, 6).Select(i => mailGenerator.Mail("john", "doe"));
            Assert.IsTrue(FindDuplicates(mails).Count == 0);
        }

        [Test]
        public void Mail_ThreeDomain_TwoStrings_NoDuplicates() {
            var mailGenerator = new MailGenerator(new[] { "test.com", "test2.com", "test3.com" }, true);
            var mails = Enumerable.Range(1, 9).Select(i => mailGenerator.Mail("john", "doe"));
            Assert.IsTrue(FindDuplicates(mails).Count == 0);
        }

        [Test]
        public void Mail_FourDomain_TwoStrings_NoDuplicates() {
            var mailGenerator = new MailGenerator(new[] { "test.com", "test2.com", "test3.com", "test4.com" }, true);
            var mails = Enumerable.Range(1, 12).Select(i => mailGenerator.Mail("john", "doe"));
            Assert.IsTrue(FindDuplicates(mails).Count == 0);
        }

        #endregion

        private static List<string> FindDuplicates(IEnumerable<string> enumerable) {
            return enumerable.GroupBy(x => x)
                .Where(group => group.Count() > 1)
                .Select(group => group.Key).ToList();
        }
    }
}
{'fraction_non_alphanumeric': 0.13245670301475304, 'fraction_numerical': 0.003207184092366902, 'mean_word_length': 2.378385698808234, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 57, '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': '7526433', 'n_tokens_mistral': 3520, 'n_tokens_neox': 3386, 'n_words': 713}