1 using System; 2 using System.Collections; 3 using NUnit.Framework; 4 5 namespace NUnit.TestUtilities 6 { 7 public class UniqueValues 8 { Count(IEnumerable actual)9 public static int Count(IEnumerable actual) 10 { 11 NUnit.ObjectList list = new NUnit.ObjectList(); 12 13 foreach (object o1 in actual) 14 if (!list.Contains(o1)) 15 list.Add(o1); 16 17 return list.Count; 18 } 19 Check(IEnumerable values, int minExpected)20 public static void Check(IEnumerable values, int minExpected) 21 { 22 int count = Count(values); 23 Assert.That(count, Is.Not.EqualTo(1), "All values were the same!"); 24 // TODO: Change to an actual warning once we implement them 25 Assert.That(count, Is.GreaterThanOrEqualTo(minExpected), "WARNING: The number of unique values less than expected."); 26 } 27 28 #region Self-test 29 30 [TestCase(1, 2, 3, 4, 5, ExpectedResult = 5)] 31 [TestCase(1, 2, 3, 4, 3, ExpectedResult = 4)] 32 [TestCase(1, 1, 1, 1, 1, ExpectedResult = 1)] 33 [TestCase(1, 2, 1, 2, 1, ExpectedResult = 2)] 34 [TestCase(1, 1, 1, 2, 2, ExpectedResult = 2)] 35 #if !NET_1_1 36 [TestCase(ExpectedResult = 0)] 37 #endif CountUniqueValuesTest(params int[] values)38 public static int CountUniqueValuesTest(params int[] values) 39 { 40 return UniqueValues.Count(values); 41 } 42 43 #endregion 44 } 45 } 46