<commit_before>﻿#region Copyright and license
// <copyright file="HistoryTests.cs" company="<NAME>">
//     Copyright (c) 2015 <NAME>. All rights reserved.
// </copyright>
// <author><NAME></author>
// <license>
//     Licensed under the Apache License, Version 2.0 (the "License");
//     you may not use this file except in compliance with the License.
//     You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
//     Unless required by applicable law or agreed to in writing, software
//     distributed under the License is distributed on an "AS IS" BASIS,
//     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//     See the License for the specific language governing permissions and
//     limitations under the License.
// </license>
#endregion

namespace ImmutableUndoRedo
{
    using System.Collections.Generic;
    using System.Linq;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    [TestClass]
    public class HistoryTests
    {
        [TestMethod]
        public void Create__Should_Return_New_Instance_With_Neither_Done_Nor_Undone_Events()
        {
            var expectedDone = Enumerable.Empty<IEvent>();
            var expectedUndone = Enumerable.Empty<IEvent>();
            var expected = History.Create(expectedDone, expectedUndone);

            var actual = History.Create();

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void CreateEmpty__Should_Return_New_Instance_With_Neither_Done_Nor_Undone_Events()
        {
            var expectedDone = Enumerable.Empty<IEvent>();
            var expectedUndone = Enumerable.Empty<IEvent>();
            var expected = History.Create(expectedDone, expectedUndone);

            var actual = History.CreateEmpty();

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void ClearDone__With_Given_Done_And_Undone_Events__Should_Return_New_Instance_With_No_Done_And_Given_Undone_Events()
        {
            var done = new IEvent[] { new EventStub(1) };
            var undone = new IEvent[] { new EventStub(2) };
            var target = History.Create(done, undone);
            var expectedDone = Enumerable.Empty<IEvent>();
            var expectedUndone = new IEvent[] { new EventStub(2) };
            var expected = History.Create(expectedDone, expectedUndone);

            var actual = target.ClearDone();

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void ClearUndone__With_Given_Done_And_Undone_Events__Should_Return_New_Instance_With_Given_Done_And_No_Undone_Events()
        {
            var done = new IEvent[] { new EventStub(1) };
            var undone = new IEvent[] { new EventStub(2) };
            var target = History.Create(done, undone);
            var expectedDone = new IEvent[] { new EventStub(1) };
            var expectedUndone = Enumerable.Empty<IEvent>();

            var expected = History.Create(expectedDone, expectedUndone);

            var actual = target.ClearUndone();

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void CopyDoneTo__With_Collection__Should_Copy_The_Done_Events_In_Chronological_Order_To_The_Given_Collection()
        {
            var done = new IEvent[] { new EventStub(11), new EventStub(12), new EventStub(13) };
            var undone = new IEvent[] { new EventStub(21), new EventStub(22), new EventStub(23) };
            var target = History.Create(done, undone);
            var expected = new List<IEvent>(done);
            var actual = new List<IEvent>();

            target.CopyDoneTo(actual);

            CollectionAssert.AreEquivalent(expected, actual);
        }

        [TestMethod]
        public void CopyUndoneTo__With_Collection__Should_Copy_The_Undone_Events_In_Chronological_Order_To_The_Given_Collection()
        {
            var done = new IEvent[] { new EventStub(11), new EventStub(12), new EventStub(13) };
            var undone = new IEvent[] { new EventStub(21), new EventStub(22), new EventStub(23) };
            var target = History.Create(done, undone);
            var expected = new List<IEvent>(undone);
            var actual = new List<IEvent>();

            target.CopyUndoneTo(actual);

            CollectionAssert.AreEquivalent(expected, actual);
        }

        [TestMethod]
        public void Do__With_Event__Should_Return_New_Instance_Whose_History_Of_Done_Events_Is_Extended_By_The_Result_Of_Doing_The_Specified_Event_Without_Any_Events_To_Redo()
        {
            var target = History.Create();
            var @event = new EventStub(1);
            var expectedDone = new IEvent[] { new EventStub(1, 1, 0) };
            var expectedUndone = Enumerable.Empty<IEvent>();
            var expected = History.Create(expectedDone, expectedUndone);

            var actual = target.Do(@event);

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void Undo__With_Given_Done_Events__Should_Return_New_Instance_Whose_History_Of_Undone_Events_Is_Extended_By_The_Result_Of_Undoing_The_Recently_Done_Event_Having_The_History_Of_Done_Events_Truncated_By_The_Recently_Done_Event()
        {
            var done = new IEvent[] { new EventStub(1) };
            var undone = Enumerable.Empty<IEvent>();
            var target = History.Create(done, undone);
            var expectedDone = Enumerable.Empty<IEvent>();<commit_msg>Resolve #10: Unit tests for CopyXXXTo methods of History now assert for correct order<commit_after>﻿#region Copyright and license
// <copyright file="HistoryTests.cs" company="<NAME>">
//     Copyright (c) 2015 <NAME>. All rights reserved.
// </copyright>
// <author><NAME></author>
// <license>
//     Licensed under the Apache License, Version 2.0 (the "License");
//     you may not use this file except in compliance with the License.
//     You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
//     Unless required by applicable law or agreed to in writing, software
//     distributed under the License is distributed on an "AS IS" BASIS,
//     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//     See the License for the specific language governing permissions and
//     limitations under the License.
// </license>
#endregion

namespace ImmutableUndoRedo
{
    using System.Collections.Generic;
    using System.Linq;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    [TestClass]
    public class HistoryTests
    {
        [TestMethod]
        public void Create__Should_Return_New_Instance_With_Neither_Done_Nor_Undone_Events()
        {
            var expectedDone = Enumerable.Empty<IEvent>();
            var expectedUndone = Enumerable.Empty<IEvent>();
            var expected = History.Create(expectedDone, expectedUndone);

            var actual = History.Create();

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void CreateEmpty__Should_Return_New_Instance_With_Neither_Done_Nor_Undone_Events()
        {
            var expectedDone = Enumerable.Empty<IEvent>();
            var expectedUndone = Enumerable.Empty<IEvent>();
            var expected = History.Create(expectedDone, expectedUndone);

            var actual = History.CreateEmpty();

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void ClearDone__With_Given_Done_And_Undone_Events__Should_Return_New_Instance_With_No_Done_And_Given_Undone_Events()
        {
            var done = new IEvent[] { new EventStub(1) };
            var undone = new IEvent[] { new EventStub(2) };
            var target = History.Create(done, undone);
            var expectedDone = Enumerable.Empty<IEvent>();
            var expectedUndone = new IEvent[] { new EventStub(2) };
            var expected = History.Create(expectedDone, expectedUndone);

            var actual = target.ClearDone();

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void ClearUndone__With_Given_Done_And_Undone_Events__Should_Return_New_Instance_With_Given_Done_And_No_Undone_Events()
        {
            var done = new IEvent[] { new EventStub(1) };
            var undone = new IEvent[] { new EventStub(2) };
            var target = History.Create(done, undone);
            var expectedDone = new IEvent[] { new EventStub(1) };
            var expectedUndone = Enumerable.Empty<IEvent>();

            var expected = History.Create(expectedDone, expectedUndone);

            var actual = target.ClearUndone();

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void CopyDoneTo__With_Collection__Should_Copy_The_Done_Events_In_Chronological_Order_To_The_Given_Collection()
        {
            var done = new IEvent[] { new EventStub(11), new EventStub(12), new EventStub(13) };
            var undone = new IEvent[] { new EventStub(21), new EventStub(22), new EventStub(23) };
            var target = History.Create(done, undone);
            var expected = new List<IEvent>(done);
            var actual = new List<IEvent>();

            target.CopyDoneTo(actual);

            CollectionAssert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void CopyUndoneTo__With_Collection__Should_Copy_The_Undone_Events_In_Chronological_Order_To_The_Given_Collection()
        {
            var done = new IEvent[] { new EventStub(11), new EventStub(12), new EventStub(13) };
            var undone = new IEvent[] { new EventStub(21), new EventStub(22), new EventStub(23) };
            var target = History.Create(done, undone);
            var expected = new List<IEvent>(undone);
            var actual = new List<IEvent>();

            target.CopyUndoneTo(actual);

            CollectionAssert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void Do__With_Event__Should_Return_New_Instance_Whose_History_Of_Done_Events_Is_Extended_By_The_Result_Of_Doing_The_Specified_Event_Without_Any_Events_To_Redo()
        {
            var target = History.Create();
            var @event = new EventStub(1);
            var expectedDone = new IEvent[] { new EventStub(1, 1, 0) };
            var expectedUndone = Enumerable.Empty<IEvent>();
            var expected = History.Create(expectedDone, expectedUndone);

            var actual = target.Do(@event);

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void Undo__With_Given_Done_Events__Should_Return_New_Instance_Whose_History_Of_Undone_Events_Is_Extended_By_The_Result_Of_Undoing_The_Recently_Done_Event_Having_The_History_Of_Done_Events_Truncated_By_The_Recently_Done_Event()
        {
            var done = new IEvent[] { new EventStub(1) };
            var undone = Enumerable.Empty<IEvent>();
            var target = History.Create(done, undone);
            var expectedDone = Enumerable.Empty<IEvent>();
{'fraction_non_alphanumeric': 0.09097459917132049, 'fraction_numerical': 0.007926499729778418, 'mean_word_length': 2.701, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5820040', 'n_tokens_mistral': 3144, 'n_tokens_neox': 3058, 'n_words': 716}