コード例 #1
0
        public void returns_empty_when_no_items()
        {
            var meetings = new Meeting[0];
            var result   = sut.Merge(meetings).ToArray();

            Assert.That(result, Has.Length.EqualTo(0));
        }
コード例 #2
0
        public IEnumerable <Tuple <DifferenceType, SyntaxToken> > GetTokenDiff(IDefinition def1, IDefinition def2)
        {
            SyntaxToken[] t1 = GetTokenList(def1).ToArray();
            SyntaxToken[] t2 = GetTokenList(def2).ToArray();

            int t1Start = 0;
            int t2Start = 0;

            List <Tuple <DifferenceType, SyntaxToken> > merged = new List <Tuple <DifferenceType, SyntaxToken> >();

            //TODO: Consider splitting by lines as well to help with the attribute diffing

            // Split the token list at identifiers to help with the merge line up so that we don't get large
            // diffing churn in the output.
            while (t1Start < t1.Length && t2Start < t2.Length)
            {
                int t1End = Array.FindIndex(t1, t1Start, s => s.Type == SyntaxTokenType.Identifier);
                int t2End = Array.FindIndex(t2, t2Start, s => s.Type == SyntaxTokenType.Identifier);

                if (t1End < 0 || t2End < 0)
                {
                    break;
                }

                merged.AddRange(ListMerger.Merge(t1, t1Start, t1End + 1, t2, t2Start, t2End + 1));

                t1Start = t1End + 1;
                t2Start = t2End + 1;
            }

            // Finish any leftover work from either side.
            merged.AddRange(ListMerger.Merge(t1, t1Start, t1.Length, t2, t2Start, t2.Length));
            return(merged);
        }
コード例 #3
0
        public void return_last_since_everything_overlaps()
        {
            var m1 = MeetingHelper.CreateMeeting(1, 1);
            var m2 = MeetingHelper.CreateMeeting(1, 1);
            var m3 = MeetingHelper.CreateMeeting(1, 1);

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

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

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

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

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

            Assert.That(result, Has.Length.EqualTo(1));
            Assert.That(result[0], Is.EqualTo(m3));
        }
コード例 #4
0
ファイル: FeedManager.cs プロジェクト: huomm23/waf
        public void Merge(FeedManager newFeedManager)
        {
            ItemLifetime  = newFeedManager.ItemLifetime;
            MaxItemsLimit = newFeedManager.MaxItemsLimit;

            ListMerger.Merge(newFeedManager.Feeds, Feeds, FeedEqualityComparer.Default);

            foreach (var feed in Feeds)
            {
                var newFeed = newFeedManager.Feeds.Single(x => x.Uri == feed.Uri);
                feed.UpdateItems(newFeed.Items, cloneItemsBeforeInsert: true);
            }
        }
コード例 #5
0
        private void MergeTestCore <T>(IList <T> source, IList <T> target, ExpectedCollectionChange expectedCollectionChange, IEqualityComparer <T> comparer = null)
        {
            var             insertCounter = 0;
            var             removeCounter = 0;
            var             resetCounter  = 0;
            Action <int, T> insertAction  = (idx, item) => insertCounter++;
            Action <int>    removeAction  = idx => removeCounter++;
            Action          resetAction   = () => resetCounter++;

            ListMerger.Merge(new ReadOnlyCollection <T>(source), target, comparer, insertAction, removeAction, resetAction);
            Assert.AreEqual(expectedCollectionChange == ExpectedCollectionChange.Insert ? 1 : 0, insertCounter);
            Assert.AreEqual(expectedCollectionChange == ExpectedCollectionChange.Remove ? 1 : 0, removeCounter);
            Assert.AreEqual(expectedCollectionChange == ExpectedCollectionChange.Reset ? 1 : 0, resetCounter);
        }
コード例 #6
0
        public void MergeTestWithDefaultArguments()
        {
            var targetList = new List <string>()
            {
                "2", "3"
            };

            ListMerger.Merge(new[] { "1", "2" }, targetList);
            Assert.IsTrue(new[] { "1", "2" }.SequenceEqual(targetList));

            ListMerger.Merge(new[] { "1", "2" }, targetList);
            Assert.IsTrue(new[] { "1", "2" }.SequenceEqual(targetList));

            ListMerger.Merge(new[] { "1", "3" }, targetList);
            Assert.IsTrue(new[] { "1", "3" }.SequenceEqual(targetList));

            ListMerger.Merge(new[] { "1", "2", "3" }, targetList);
            Assert.IsTrue(new[] { "1", "2", "3" }.SequenceEqual(targetList));

            ListMerger.Merge(new[] { "1", "2", "c", "d" }, targetList);
            Assert.IsTrue(new[] { "1", "2", "c", "d" }.SequenceEqual(targetList));

            ListMerger.Merge(new[] { "a", "b", "c" }, targetList);
            Assert.IsTrue(new[] { "a", "b", "c" }.SequenceEqual(targetList));

            ListMerger.Merge(new[] { "a", "b" }, targetList);
            Assert.IsTrue(new[] { "a", "b" }.SequenceEqual(targetList));

            ListMerger.Merge(new[] { "1" }, targetList);
            Assert.IsTrue(new[] { "1" }.SequenceEqual(targetList));

            ListMerger.Merge(new string[0], targetList);
            Assert.IsTrue(new string[0].SequenceEqual(targetList));

            ListMerger.Merge(Array.AsReadOnly(new[] { "1" }), targetList);
            Assert.IsTrue(new[] { "1" }.SequenceEqual(targetList));
        }
コード例 #7
0
 public void throws_when_input_is_null()
 {
     Assert.That(() => sut.Merge(null),
                 Throws.ArgumentNullException.With.Property("ParamName").EqualTo("items"));
 }