예제 #1
0
        public void CountSequence()
        {
            Assert.ThrowsExact <ArgumentNullException>(() => Assert.Count(null as int[], 1));
            Assert.ThrowsExact <ArgumentException>(() => Assert.Count(new int[] { }, 1));
            Assert.ThrowsExact <ArgumentException>(() => Assert.Count(new int[] { 0 }, -1));

            Assert.DoesNotThrow(() => Assert.Count(new int[] { 1, 2, 3, 4, 5 }, 5));
            Assert.ThrowsExact <AssertionException>(() => Assert.Count(new int[] { 1, 2, 3, 4, 5 }, 4));
            Assert.ThrowsExact <AssertionException>(() => Assert.Count(new int[] { 1, 2, 3, 4, 5 }, 6));
        }
예제 #2
0
        public void CountElement()
        {
            Assert.ThrowsExact <ArgumentNullException>(() => Assert.Count(null as int[], 1, 1));
            Assert.ThrowsExact <ArgumentNullException>(() => Assert.Count("ABC", 1, 'c', null as IEqualityComparer <char>));
            Assert.ThrowsExact <ArgumentException>(() => Assert.Count(new int[] { }, 1, 1));
            Assert.ThrowsExact <ArgumentException>(() => Assert.Count(new int[] { 0 }, -1, 0));

            Assert.DoesNotThrow(() => Assert.Count(new int[] { 1, 2, 3, 4, 5 }, 1, 1));
            Assert.ThrowsExact <AssertionException>(() => Assert.Count(new int[] { 1, 4, 3, 4, 5 }, 2, 3));
            Assert.ThrowsExact <AssertionException>(() => Assert.Count(new int[] { 1, 4, 3, 4, 5 }, 3, 4));
            Assert.DoesNotThrow(() => Assert.Count("ABC", 1, 'c', new CharCaseInvariantComparer()));
            Assert.ThrowsExact <AssertionException>(() => Assert.Count("ABC", 2, 'c', new CharCaseInvariantComparer()));
            Assert.ThrowsExact <AssertionException>(() => Assert.Count("ABC", 0, 'c', new CharCaseInvariantComparer()));
        }