<commit_before>﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Shience.Test
{
    [TestClass]
    public class ScienceTests
    {
        [TestInitialize]
        public void ScienceTestsInitialize()
        {
            var fp = new FakePublisher();
            Shience.SetPublisher(fp);
        }

        [TestMethod]
        public void DefaultComparerReturnsTrueWithSameResultOnPrimitives()
        {
            var science = Shience.New<bool>("DefaultComparerReturnsTrueWithSameResultOnPrimitives");

            var result = science.Test(control: (() => { return true; }), candidate: (() => { return true; }));

            Assert.AreEqual(true, PublishingResults.TestNamesWithResults["DefaultComparerReturnsTrueWithSameResultOnPrimitives"]);
        }

        [TestMethod]
        public void DefaultComparerReturnsFalseWithDifferentResultOnPrimitives()
        {
            var science = Shience.New<bool>("DefaultComparerReturnsFalseWithDifferentResultOnPrimitives");

            var result = science.Test(control: (() => { return true; }), candidate: (() => { return false; }));

            Assert.AreEqual(false, PublishingResults.TestNamesWithResults["DefaultComparerReturnsFalseWithDifferentResultOnPrimitives"]);
        }

        [TestMethod]
        public void DefaultComparerReturnsTrueWithSameResultOnObject()
        {
            var science = Shience.New<TestHelper>("DefaultComparerReturnsTrueWithSameResultOnObject");

            var result = science.Test(control: (() => { return new TestHelper {Number = 1}; }),
                candidate: (() => { return new TestHelper {Number = 1}; }));

            Assert.AreEqual(true, PublishingResults.TestNamesWithResults["DefaultComparerReturnsTrueWithSameResultOnObject"]);
        }

        [TestMethod]
        public void DefaultComparerReturnsFalseWithDifferentResultOnObject()
        {
            var science = Shience.New<TestHelper>("DefaultComparerReturnsFalseWithDifferentResultOnObject");

            var result = science.Test(control: (() => { return new TestHelper {Number = 1}; }),
                candidate: (() => { return new TestHelper {Number = 2}; }));

            Assert.AreEqual(false, PublishingResults.TestNamesWithResults["DefaultComparerReturnsFalseWithDifferentResultOnObject"]);
        }

        [TestMethod]
        public void ComparerFuncReturnsCorrectTrueResult()
        {
            var science = Shience.New<bool>("ComparerFuncReturnsCorrectTrueResult");

            var result = science.Test(control: (() => { return true; }),
                                      candidate: (() => { return true; }),
                                      comparer: (a, b) => { return a == b; });

            Assert.AreEqual(true, PublishingResults.TestNamesWithResults["ComparerFuncReturnsCorrectTrueResult"]);
        }

        [TestMethod]
        public void ComparerFuncReturnsCorrectFalseResult()
        {
            var science = Shience.New<bool>("ComparerFuncReturnsCorrectFalseResult");

            var result = science.Test(control: (() => { return true; }),
                                      candidate: (() => { return false; }),
                                      comparer: (a, b) => { return a == b; });

            Assert.AreEqual(false, PublishingResults.TestNamesWithResults["ComparerFuncReturnsCorrectFalseResult"]);
        }

        [TestMethod]
        public void InstantiatingScienceThrowsArgumentNullIfTestNameIsNull()
        {
            ArgumentNullException thrownException = null;

            try
            {
                var science = Shience.New<bool>(null);
            }
            catch (ArgumentNullException e)
            {
                thrownException = e;
            }

            Assert.IsNotNull(thrownException, thrownException == null ? string.Empty : thrownException.ToString());
        }

        [TestMethod]
        public void InstantiatingScienceThrowsArgumentNullIfTestNameIsEmptyString()
        {
            ArgumentNullException thrownException = null;

            try
            {
                var science = Shience.New<bool>(string.Empty);
            }
            catch (ArgumentNullException e)
            {
                thrownException = e;
            }

            Assert.IsNotNull(thrownException, thrownException == null ? string.Empty : thrownException.ToString());
        }

        [TestMethod]
        public void InstantiatingScienceThrowsArgumentNullIfPublisherIsNull()
        {
            Shience.SetPublisher(null);

            ArgumentNullException thrownException = null;

            try
            {
                var science = Shience.New<bool>(string.Empty);
            }
            catch (ArgumentNullException e)
            {
                thrownException = e;
            }

            Assert.IsNotNull(thrownException, thrownException == null ? string.Empty : thrownException.ToString());
        }

        [TestMethod]
        public void NoTestsAreRunIfCandidateIsNull()
        {
            var science = Shience.New<bool>("NotTestsAreRunIfCandidateIsNull");

            science.Test(() => true,
                            null);

            Assert.IsFalse(PublishingResults.TestNamesWithResults.ContainsKey("NotTestsAreRunIfCandidateIsNull"));
        }

        private class TestHelper
        {
            public int Number { get; set; }

            public override bool Equals(object obj)
            {
                var otherTestHelper = obj as TestHelper;
                if (otherTestHelper == null)
                {
                    return false;
                }

                if (otherTestHelper.Number == this.Number)
                {
                    return true;
                }

                return false;
            }

            public override int GetHashCode()
            {
                return base.GetHashCode() ^ Number;<commit_msg>Added test to ensure control is required<commit_after>﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Shience.Test
{
    [TestClass]
    public class ScienceTests
    {
        [TestInitialize]
        public void ScienceTestsInitialize()
        {
            var fp = new FakePublisher();
            Shience.SetPublisher(fp);
        }

        [TestMethod]
        public void DefaultComparerReturnsTrueWithSameResultOnPrimitives()
        {
            var science = Shience.New<bool>("DefaultComparerReturnsTrueWithSameResultOnPrimitives");

            var result = science.Test(control: (() => { return true; }), candidate: (() => { return true; }));

            Assert.AreEqual(true, PublishingResults.TestNamesWithResults["DefaultComparerReturnsTrueWithSameResultOnPrimitives"]);
        }

        [TestMethod]
        public void DefaultComparerReturnsFalseWithDifferentResultOnPrimitives()
        {
            var science = Shience.New<bool>("DefaultComparerReturnsFalseWithDifferentResultOnPrimitives");

            var result = science.Test(control: (() => { return true; }), candidate: (() => { return false; }));

            Assert.AreEqual(false, PublishingResults.TestNamesWithResults["DefaultComparerReturnsFalseWithDifferentResultOnPrimitives"]);
        }

        [TestMethod]
        public void DefaultComparerReturnsTrueWithSameResultOnObject()
        {
            var science = Shience.New<TestHelper>("DefaultComparerReturnsTrueWithSameResultOnObject");

            var result = science.Test(control: (() => { return new TestHelper {Number = 1}; }),
                candidate: (() => { return new TestHelper {Number = 1}; }));

            Assert.AreEqual(true, PublishingResults.TestNamesWithResults["DefaultComparerReturnsTrueWithSameResultOnObject"]);
        }

        [TestMethod]
        public void DefaultComparerReturnsFalseWithDifferentResultOnObject()
        {
            var science = Shience.New<TestHelper>("DefaultComparerReturnsFalseWithDifferentResultOnObject");

            var result = science.Test(control: (() => { return new TestHelper {Number = 1}; }),
                candidate: (() => { return new TestHelper {Number = 2}; }));

            Assert.AreEqual(false, PublishingResults.TestNamesWithResults["DefaultComparerReturnsFalseWithDifferentResultOnObject"]);
        }

        [TestMethod]
        public void ComparerFuncReturnsCorrectTrueResult()
        {
            var science = Shience.New<bool>("ComparerFuncReturnsCorrectTrueResult");

            var result = science.Test(control: (() => { return true; }),
                                      candidate: (() => { return true; }),
                                      comparer: (a, b) => { return a == b; });

            Assert.AreEqual(true, PublishingResults.TestNamesWithResults["ComparerFuncReturnsCorrectTrueResult"]);
        }

        [TestMethod]
        public void ComparerFuncReturnsCorrectFalseResult()
        {
            var science = Shience.New<bool>("ComparerFuncReturnsCorrectFalseResult");

            var result = science.Test(control: (() => { return true; }),
                                      candidate: (() => { return false; }),
                                      comparer: (a, b) => { return a == b; });

            Assert.AreEqual(false, PublishingResults.TestNamesWithResults["ComparerFuncReturnsCorrectFalseResult"]);
        }

        [TestMethod]
        public void InstantiatingScienceThrowsArgumentNullIfTestNameIsNull()
        {
            ArgumentNullException thrownException = null;

            try
            {
                var science = Shience.New<bool>(null);
            }
            catch (ArgumentNullException e)
            {
                thrownException = e;
            }

            Assert.IsNotNull(thrownException, thrownException == null ? string.Empty : thrownException.ToString());
        }

        [TestMethod]
        public void InstantiatingScienceThrowsArgumentNullIfTestNameIsEmptyString()
        {
            ArgumentNullException thrownException = null;

            try
            {
                var science = Shience.New<bool>(string.Empty);
            }
            catch (ArgumentNullException e)
            {
                thrownException = e;
            }

            Assert.IsNotNull(thrownException, thrownException == null ? string.Empty : thrownException.ToString());
        }

        [TestMethod]
        public void InstantiatingScienceThrowsArgumentNullIfPublisherIsNull()
        {
            Shience.SetPublisher(null);

            ArgumentNullException thrownException = null;

            try
            {
                var science = Shience.New<bool>(string.Empty);
            }
            catch (ArgumentNullException e)
            {
                thrownException = e;
            }

            Assert.IsNotNull(thrownException, thrownException == null ? string.Empty : thrownException.ToString());
        }

        [TestMethod]
        public void NoTestsAreRunIfCandidateIsNull()
        {
            var science = Shience.New<bool>("NotTestsAreRunIfCandidateIsNull");

            science.Test(() => true,
                            null);

            Assert.IsFalse(PublishingResults.TestNamesWithResults.ContainsKey("NotTestsAreRunIfCandidateIsNull"));
        }

        [TestMethod]
        public void ArgumentNullIsThrownIfControlIsNull()
        {
            ArgumentNullException thrownException = null;

            var science = Shience.New<bool>("ArgumentNullIsThrownIfControlIsNull");

            try
            {
                science.Test(null, null);
            }
            catch (ArgumentNullException e)
            {
                thrownException = e;
            }

            Assert.IsNotNull(thrownException);
        }

        private class TestHelper
        {
            public int Number { get; set; }

            public override bool Equals(object obj)
            {
                var otherTestHelper = obj as TestHelper;
                if (otherTestHelper == null)
                {
                    return false;
                }

                if (otherTestHelper.Number == this.Number)
                {
                    return true;
                }

                return false;
            }

            public override int GetHashCode()
            {
                return base.GetHashCode() ^ Number;
{'fraction_non_alphanumeric': 0.0918892822658513, 'fraction_numerical': 0.000643707756678468, 'mean_word_length': 1.9382978723404256, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 54, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3082048', 'n_tokens_mistral': 3021, 'n_tokens_neox': 2883, 'n_words': 538}