Пример #1
0
        public void return_all_since_nothing_overlaps()
        {
            var m1 = MeetingHelper.CreateMeeting(1, 1);
            var m2 = MeetingHelper.CreateMeeting(2, 2);
            var m3 = MeetingHelper.CreateMeeting(3, 3);

            var inputItems = new[] { m1, m2, m3 };

            var m4 = MeetingHelper.CreateMeeting(4, 4);

            var merge1And2 = new[] { new SplitItem <Meeting>(m1, m1), new SplitItem <Meeting>(m2, m2) };
            var merge1And3 = new[] { new SplitItem <Meeting>(m1, m1), new SplitItem <Meeting>(m3, m3) };
            var merge2And3 = new[] { new SplitItem <Meeting>(m2, m2), new SplitItem <Meeting>(m3, m3) };

            A.CallTo(() => _splitter.Split(m1, m2)).Returns(merge1And2);
            A.CallTo(() => _splitter.Split(m1, m3)).Returns(merge1And3);
            A.CallTo(() => _splitter.Split(m2, m3)).Returns(merge2And3);

            var result = sut.Merge(inputItems).ToArray();

            Assert.That(result, Has.Length.EqualTo(3));
            Assert.That(result[0], Is.EqualTo(m1));
            Assert.That(result[1], Is.EqualTo(m2));
            Assert.That(result[2], Is.EqualTo(m3));
        }
Пример #2
0
        public void return_newItem_if_newItem_has_same_start_stop_as_oldItem()
        {
            var oldItem = MeetingHelper.CreateMeeting(0, 0);
            var newItem = MeetingHelper.CreateMeeting(0, 0);
            var result  = _splitter.Split(oldItem, newItem).ToArray();

            Assert.That(result.Length, Is.EqualTo(1));
            Assert.That(result[0].Value, Is.EqualTo(newItem));
        }
Пример #3
0
        public void returns_input_when_single_item()
        {
            var m1       = MeetingHelper.CreateMeeting(0, 0);
            var meetings = new[] { m1 };
            var result   = sut.Merge(meetings).ToArray();

            Assert.That(result, Has.Length.EqualTo(1));
            Assert.That(result[0], Is.EqualTo(m1));
        }
Пример #4
0
        public void return_newItem_if_newItem_is_longer_and_stops_when_oldItem_stops()
        {
            var oldItem = MeetingHelper.CreateMeeting(3, 6);
            var newItem = MeetingHelper.CreateMeeting(0, 6);
            var result  = _splitter.Split(oldItem, newItem).ToArray();

            Assert.That(result.Length, Is.EqualTo(1));
            Assert.That(result[0].Value, Is.EqualTo(newItem));
        }
Пример #5
0
        public void return_newItem_if_newItem_starts_before_oldItem_starts_and_ends_after_oldItem_ends()
        {
            var oldItem = MeetingHelper.CreateMeeting(3, 6);
            var newItem = MeetingHelper.CreateMeeting(0, 9);
            var result  = _splitter.Split(oldItem, newItem).ToArray();

            Assert.That(result.Length, Is.EqualTo(1));
            Assert.That(result[0].Value, Is.EqualTo(newItem));
        }
Пример #6
0
        public void return_both_if_newItem_starts_when_oldItem_ends()
        {
            var oldItem = MeetingHelper.CreateMeeting(0, 3);
            var newItem = MeetingHelper.CreateMeeting(3, 6);
            var result  = _splitter.Split(oldItem, newItem).ToArray();

            Assert.That(result.Length, Is.EqualTo(2));
            Assert.That(result[0].Value, Is.EqualTo(oldItem));
            Assert.That(result[1].Value, Is.EqualTo(newItem));
        }
Пример #7
0
        public void Throws_when_newItem_isNull()
        {
            var     oldItem = MeetingHelper.CreateMeeting(0, 3);
            Meeting newItem = null;

            Assert.That(
                () => _splitter.Split(oldItem, newItem).ToArray(),
                Throws.ArgumentNullException.With.Property("ParamName").EqualTo("newItem")
                );
        }
Пример #8
0
        public void return_both_if_newItem_is_before_oldItem()
        {
            var oldItem = MeetingHelper.CreateMeeting(1, 1);
            var newItem = MeetingHelper.CreateMeeting(0, 0);
            var result  = _splitter.Split(oldItem, newItem).ToArray();

            Assert.That(result.Length, Is.EqualTo(2));
            Assert.That(result[0].Value, Is.EqualTo(newItem));
            Assert.That(result[1].Value, Is.EqualTo(oldItem));
        }
Пример #9
0
        public void Throws_when_newItem_has_end_before_start()
        {
            var oldItem = MeetingHelper.CreateMeeting(0, 0);
            var newItem = MeetingHelper.CreateMeeting(3, 0);

            Assert.That(
                () => _splitter.Split(oldItem, newItem).ToArray(),
                Throws.ArgumentException.With.Property("ParamName").EqualTo("newItem")
                .And.Message.StartsWith("End cannot occur before start")
                );
        }
Пример #10
0
        public void throws_because_it_does_not_capture_exceptions()
        {
            var m1       = MeetingHelper.CreateMeeting(0, 0);
            var m2       = MeetingHelper.CreateMeeting(1, 1);
            var meetings = new[] { m1, m2 };

            var fakeException = new Exception();

            A.CallTo(() => _splitter.Split(m1, m2)).Throws(fakeException);

            Assert.That(() => sut.Merge(meetings).ToArray(), Throws.Exception.SameAs(fakeException));
        }
Пример #11
0
        public void move_start_of_oldItem_when_newItem_ends_in_oldItem()
        {
            var oldItem = MeetingHelper.CreateMeeting(3, 9);
            var newItem = MeetingHelper.CreateMeeting(0, 6);
            var result  = _splitter.Split(oldItem, newItem).ToArray();

            Assert.That(result.Length, Is.EqualTo(2));
            Assert.That(result[0].Value, Is.EqualTo(newItem));
            Assert.That(result[1].Value.Start, Is.EqualTo(6));
            Assert.That(result[1].Value.End, Is.EqualTo(9));
            Assert.That(result[1].Value.OriginalMeeting, Is.EqualTo(oldItem));
        }
Пример #12
0
        public void throws_when_merger_does_not_return_newItem()
        {
            // Arrange
            var m1       = MeetingHelper.CreateMeeting(0, 0);
            var m2       = MeetingHelper.CreateMeeting(1, 1);
            var meetings = new[] { m1, m2 };

            var m3            = MeetingHelper.CreateMeeting(2, 2);
            var mergeResults1 = new[] { new SplitItem <Meeting>(m3, m3) };

            A.CallTo(() => _splitter.Split(m1, m2)).Returns(mergeResults1);
            Assert.That(() => sut.Merge(meetings).ToArray(), Throws.Exception.With.Message.EqualTo("The splitter must return the newItem"));
        }
Пример #13
0
        public void throws_when_merger_returns_nothing()
        {
            // Arrange
            var m1       = MeetingHelper.CreateMeeting(0, 0);
            var m2       = MeetingHelper.CreateMeeting(1, 1);
            var meetings = new[] { m1, m2 };

            var emptyMerge = new SplitItem <Meeting>[] { };

            A.CallTo(() => _splitter.Split(m1, m2)).Returns(emptyMerge);

            Assert.That(() => sut.Merge(meetings).ToArray(),
                        Throws.Exception.Message.EqualTo("The merger must not provided an empty result"));
        }
Пример #14
0
        public void return_three_items_when_newItem_splits_oldItem()
        {
            var oldItem = MeetingHelper.CreateMeeting(0, 9);
            var newItem = MeetingHelper.CreateMeeting(3, 6);
            var result  = _splitter.Split(oldItem, newItem).ToArray();

            Assert.That(result.Length, Is.EqualTo(3));
            Assert.That(result[0].Value.Start, Is.EqualTo(0));
            Assert.That(result[0].Value.End, Is.EqualTo(3));
            Assert.That(result[0].Value.OriginalMeeting, Is.EqualTo(oldItem));
            Assert.That(result[1].Value, Is.EqualTo(newItem));
            Assert.That(result[2].Value.Start, Is.EqualTo(6));
            Assert.That(result[2].Value.End, Is.EqualTo(9));
            Assert.That(result[2].Value.OriginalMeeting, Is.EqualTo(oldItem));
        }
Пример #15
0
        public void return_first_and_last_when_second_splits()
        {
            var m1  = MeetingHelper.CreateMeeting(0, 9);
            var m1a = MeetingHelper.CreateMeeting(0, 3);
            var m1b = MeetingHelper.CreateMeeting(6, 9);
            var m2  = MeetingHelper.CreateMeeting(3, 6);
            var m3  = MeetingHelper.CreateMeeting(3, 6);

            var inputItems = new[] { m1, m2, m3 };

            var m4 = MeetingHelper.CreateMeeting(4, 4);

            var merge1And2 = new[]
            {
                SplitItemHelper.Create(m1, m1a),
                SplitItemHelper.Original(m2),
                SplitItemHelper.Create(m1, m1b),
            };

            var merge1aAnd3 = new[]
            {
                SplitItemHelper.Original(m1a),
                SplitItemHelper.Original(m3),
            };

            var merge2And3 = new[]
            {
                SplitItemHelper.Original(m3)
            };

            var merge1bAnd3 = new[]
            {
                SplitItemHelper.Original(m3),
                SplitItemHelper.Original(m1b),
            };

            A.CallTo(() => _splitter.Split(m1, m2)).Returns(merge1And2);
            A.CallTo(() => _splitter.Split(m1a, m3)).Returns(merge1aAnd3);
            A.CallTo(() => _splitter.Split(m2, m3)).Returns(merge2And3);
            A.CallTo(() => _splitter.Split(m1b, m3)).Returns(merge1bAnd3);

            var result = sut.Merge(inputItems).ToArray();

            Assert.That(result, Has.Length.EqualTo(3));
            Assert.That(result[0], Is.EqualTo(m1a));
            Assert.That(result[1], Is.EqualTo(m1b));
            Assert.That(result[2], Is.EqualTo(m3));
        }
Пример #16
0
        public void throws_when_merger_invents_an_item()
        {
            // Arrange
            var oldItem  = MeetingHelper.CreateMeeting(0, 0);
            var newItem  = MeetingHelper.CreateMeeting(1, 1);
            var meetings = new[] { oldItem, newItem };

            var inventedItem  = MeetingHelper.CreateMeeting(2, 2);
            var mergeResults1 = new[]
            {
                new SplitItem <Meeting>(newItem, newItem),
                new SplitItem <Meeting>(inventedItem, newItem),
            };

            A.CallTo(() => _splitter.Split(oldItem, newItem)).Returns(mergeResults1);
            Assert.That(() => sut.Merge(meetings).ToArray(), Throws.Exception.With.Message.EqualTo("The splitter should not invent new original items"));
        }
Пример #17
0
        public void throws_when_merger_returns_oldItem_more_two_times_before()
        {
            // Arrange
            var m1       = MeetingHelper.CreateMeeting(0, 0);
            var m2       = MeetingHelper.CreateMeeting(1, 1);
            var meetings = new[] { m1, m2 };

            var m3            = MeetingHelper.CreateMeeting(2, 2);
            var mergeResults1 = new[]
            {
                new SplitItem <Meeting>(m1, m1),
                new SplitItem <Meeting>(m1, m1),
                new SplitItem <Meeting>(m2, m2),
            };

            A.CallTo(() => _splitter.Split(m1, m2)).Returns(mergeResults1);
            Assert.That(() => sut.Merge(meetings).ToArray(), Throws.Exception.With.Message.EqualTo("The splitter can return oldItem only once before and/or once after newItem"));
        }
Пример #18
0
        public void should_not_throw_when_merger_returns_oldItem_once_before_and_once_after()
        {
            // Arrange
            var m1       = MeetingHelper.CreateMeeting(0, 0);
            var m2       = MeetingHelper.CreateMeeting(1, 1);
            var meetings = new[] { m1, m2 };

            var m3            = MeetingHelper.CreateMeeting(2, 2);
            var mergeResults1 = new[]
            {
                new SplitItem <Meeting>(m1, m1),
                new SplitItem <Meeting>(m2, m2),
                new SplitItem <Meeting>(m1, m1),
            };

            A.CallTo(() => _splitter.Split(m1, m2)).Returns(mergeResults1);
            Assert.That(() => sut.Merge(meetings).ToArray(), Throws.Nothing);
        }