Ejemplo n.º 1
0
        public void SortAccordingTo_NullKeySelector_ReturnsException()
        {
            var sourceCollection = new[] {"A", "B", "C", "D"};
            var templateCollection = new[] {"A", "B", "C", "D"};

            Assert.Throws<ArgumentNullException>(() => sourceCollection.SortAccordingTo(templateCollection, null));
        }
Ejemplo n.º 2
0
        public void SortAccordingTo_EmptyTemplateCollection_ReturnsSameSourceCollection()
        {
            var sourceCollection = new[] {"A", "B", "C", "D"};
            var templateCollection = Enumerable.Empty<string>();

            var result = sourceCollection.SortAccordingTo(templateCollection);

            Assert.AreEqual(sourceCollection, result);
        }
Ejemplo n.º 3
0
        public void SortAccordingTo_TemplateCollectionThatContainsAllValuesInSourceCollection_ReturnsCorrectSequence()
        {
            var sourceCollection = new[] {"A", "B", "C", "B", "A", "C", "D", "D"};
            var templateCollection = new[] {"B", "A", "D", "C"};

            var result = sourceCollection.SortAccordingTo(templateCollection);

            var expected = new[] {"B", "B", "A", "A", "D", "D", "C", "C"};

            Assert.AreEqual(expected, result);
        }
Ejemplo n.º 4
0
        public void SortAccordingTo_UsingIntegers_ReturnsCorrectSequence()
        {
            var sourceCollection = new[] {2, 3, 9, 4, 1, 6};
            var templateCollection = Enumerable.Range(0, 10);

            var result = sourceCollection.SortAccordingTo(templateCollection);

            var expected = new[] {1, 2, 3, 4, 6, 9};

            Assert.AreEqual(expected, result);
        }
Ejemplo n.º 5
0
        public void SortAccordingTo_UseComparer_ReturnsCorrectSequence()
        {
            var sourceCollection = new[] {"A", "b", "c", "C", "B", "a", "D", "E", "a", "B"};
            var templateCollection = new[] {"B", "c", "A"};

            var result = sourceCollection.SortAccordingTo(templateCollection, comparer: StringComparer.CurrentCultureIgnoreCase);

            var expected = new[] {"b", "B", "B", "c", "C", "A", "a", "a", "D", "E"};

            Assert.AreEqual(expected, result);
        }
Ejemplo n.º 6
0
        public void SortAccordingTo_TemplateCollectionDoesNotContainAllValuesInSourceCollection_DoNotIncludeNoMatches_ReturnsCorrectSequence()
        {
            var sourceCollection = new[] {"A", "B", "C", "B", "A", "C", "D", "D"};
            var templateCollection = new[] {"B", "D", "C"};

            var result = sourceCollection.SortAccordingTo(templateCollection, false);

            // Since "A" does not exist in the template collection they are placed at the end of the sequence
            var expected = new[] {"B", "B", "D", "D", "C", "C"};

            Assert.AreEqual(expected, result);
        }
Ejemplo n.º 7
0
        public void SortAccordingTo_TemplateCollectionDoesNotContainAllValuesInSourceCollection_ReturnsCorrectSequence2()
        {
            var sourceCollection = new[] {"X", "A", "B", "C", "Y", "B", "A", "C", "Z", "D", "D"};
            var templateCollection = new[] {"B", "D", "C"};

            var result = sourceCollection.SortAccordingTo(templateCollection);

            // Slightly more complicated than the previous test
            // NOTE: no matches get sorted amongst themselves in the order they appear in the list.
            var expected = new[] {"B", "B", "D", "D", "C", "C", "X", "A", "A", "Y", "Z"};

            Assert.AreEqual(expected, result);
        }
Ejemplo n.º 8
0
        public void SortAccordingTo_TemplateCollectionSomeValuesInSourceCollection_ReturnsCorrectSequence()
        {
            var sourceCollection = new[] {"A", "B", "C", "B", "A", "C", "D", "D"};
            var templateCollection = new[] {"B", "D", "C"};

            var result = sourceCollection.SortAccordingTo(templateCollection);

            // Since "A" does not exist int he template collection they are placed at the end of the sequence
            var expected = new[] {"B", "B", "D", "D", "C", "C", "A", "A"};

            Assert.AreEqual(expected, result);
        }