Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGonzalo Paniagua Javier <gonzalo.mono@gmail.com>2009-07-15 05:05:07 +0400
committerGonzalo Paniagua Javier <gonzalo.mono@gmail.com>2009-07-15 05:05:07 +0400
commitc8fd06fbe8f7fbdf2ad566a31d8bf57859d008d2 (patch)
tree38674e6b22edd2e8113314db456c71784f207f6e /mcs/class/System/Test
parent05f367e52ddd8ad3c19488dede863a1b65efbb30 (diff)
2009-07-14 Gonzalo Paniagua Javier <gonzalo@novell.com>
* SortedListTest.cs: new tests for bug #521750 provided by Kevin Fitzgerald. svn path=/trunk/mcs/; revision=137916
Diffstat (limited to 'mcs/class/System/Test')
-rw-r--r--mcs/class/System/Test/System.Collections.Generic/ChangeLog5
-rw-r--r--mcs/class/System/Test/System.Collections.Generic/SortedListTest.cs138
2 files changed, 143 insertions, 0 deletions
diff --git a/mcs/class/System/Test/System.Collections.Generic/ChangeLog b/mcs/class/System/Test/System.Collections.Generic/ChangeLog
index fe162abaf29..9901e47c71b 100644
--- a/mcs/class/System/Test/System.Collections.Generic/ChangeLog
+++ b/mcs/class/System/Test/System.Collections.Generic/ChangeLog
@@ -1,3 +1,8 @@
+2009-07-14 Gonzalo Paniagua Javier <gonzalo@novell.com>
+
+ * SortedListTest.cs: new tests for bug #521750 provided by
+ Kevin Fitzgerald.
+
2009-05-10 Andrés G. Aragoneses <aaragoneses@novell.com>
* LinkedListTest.cs: Added test for #481621,
diff --git a/mcs/class/System/Test/System.Collections.Generic/SortedListTest.cs b/mcs/class/System/Test/System.Collections.Generic/SortedListTest.cs
index 7b90220a0c7..ced822e6ed1 100644
--- a/mcs/class/System/Test/System.Collections.Generic/SortedListTest.cs
+++ b/mcs/class/System/Test/System.Collections.Generic/SortedListTest.cs
@@ -325,6 +325,144 @@ namespace MonoTests.System.Collections.Generic
list.RemoveAt (0);
en.MoveNext ();
}
+
+ sealed class StartsWithComparator : IComparer<string> {
+ private readonly static Comparer<string> _stringComparer = Comparer<string>.Default;
+ public static readonly StartsWithComparator Instance = new StartsWithComparator();
+
+ public int Compare(string part, string whole)
+ {
+ // let the default string comparer deal with null or when part is not smaller then whole
+ if (part == null || whole == null || part.Length >= whole.Length)
+ return _stringComparer.Compare(part, whole);
+
+ // loop through all characters that part and whole have in common
+ int pos = 0;
+ bool match;
+ do {
+ match = (part[pos] == whole[pos]);
+ } while (match && ++pos < part.Length);
+
+ // return result of last comparison
+ return match ? 0 : (part[pos] < whole[pos] ? -1 : 1);
+ }
+ }
+
+ sealed class StartsWithComparatorPartWholeCheck : IComparer<string>
+ {
+ private readonly static Comparer<string> _stringComparer = Comparer<string>.Default;
+
+ public static readonly StartsWithComparator Instance = new StartsWithComparator();
+
+ public int Compare(string part, string whole)
+ {
+ Assert.IsTrue(part == "Part", "#PWC0");
+ Assert.IsTrue(whole == "Whole", "#PWC1");
+
+ // let the default string comparer deal with null or when part is not smaller then whole
+ if (part == null || whole == null || part.Length >= whole.Length)
+ return _stringComparer.Compare(part, whole);
+
+ // loop through all characters that part and whole have in common
+ int pos = 0;
+ bool match;
+ do {
+ match = (part[pos] == whole[pos]);
+ } while (match && ++pos < part.Length);
+
+ // return result of last comparison
+ return match ? 0 : (part[pos] < whole[pos] ? -1 : 1);
+ }
+ }
+
+ [Test]
+ public void ComparatorUsageTest()
+ {
+ SortedList<string, string> sl = new SortedList<string, string>(StartsWithComparator.Instance);
+
+ sl.Add("Apples", "Value-Apples");
+ sl.Add("Bananas", "Value-Bananas");
+ sl.Add("Oranges", "Value-Oranges");
+
+ // Ensure 3 objects exist in the collection
+ Assert.IsTrue(sl.Count == 3, "Count");
+
+ // Complete Match Test Set
+ Assert.IsTrue(sl.ContainsKey("Apples"), "#A0");
+ Assert.IsTrue(sl.ContainsKey("Bananas"), "#A1");
+ Assert.IsTrue(sl.ContainsKey("Oranges"), "#A2");
+
+ // Partial Match Test Set
+ Assert.IsTrue(sl.ContainsKey("Apples are great fruit!"), "#B0");
+ Assert.IsTrue(sl.ContainsKey("Bananas are better fruit."), "#B1");
+ Assert.IsTrue(sl.ContainsKey("Oranges are fun to peel."), "#B2");
+
+ // Reversed Match Test Set
+ Assert.IsFalse(sl.ContainsKey("Value"), "#C0");
+
+ // No match tests
+ Assert.IsFalse(sl.ContainsKey("I forgot to bring my bananas."), "#D0");
+ Assert.IsFalse(sl.ContainsKey("My apples are on vacation."), "#D0");
+ Assert.IsFalse(sl.ContainsKey("The oranges are not ripe yet."), "#D0");
+
+ }
+
+ [Test]
+ public void ComparatorPartWholeCheck()
+ {
+ SortedList<string, string> sl = new SortedList<string, string>(StartsWithComparatorPartWholeCheck.Instance);
+ sl.Add("Part", "Value-Part");
+ Assert.IsFalse(sl.ContainsKey("Whole"), "#PWC2");
+ }
+
+ [Test]
+ public void NonComparatorStringCheck()
+ {
+ SortedList<string, string> sl = new SortedList<string, string>();
+
+ sl.Add("Oranges", "Value-Oranges");
+ sl.Add("Apples", "Value-Apples");
+ sl.Add("Bananas", "Value-Bananas");
+
+ int i = 0;
+ Assert.IsTrue(sl.Count == 3, "NCSC #A0");
+
+ Assert.IsTrue(sl.ContainsKey("Apples"), "NCSC #B1");
+ Assert.IsTrue(sl.ContainsKey("Bananas"), "NCSC #B2");
+ Assert.IsTrue(sl.ContainsKey("Oranges"), "NCSC #B3");
+
+ Assert.IsFalse(sl.ContainsKey("XApples"), "NCSC #C1");
+ Assert.IsFalse(sl.ContainsKey("XBananas"), "NCSC #C2");
+ Assert.IsFalse(sl.ContainsKey("XOranges"), "NCSC #C3");
+
+ Assert.IsTrue(sl.Keys[0] == "Apples", "NCSC #D1");
+ Assert.IsTrue(sl.Keys[1] == "Bananas", "NCSC #D2");
+ Assert.IsTrue(sl.Keys[2] == "Oranges", "NCSC #D3");
+ }
+
+ [Test]
+ public void NonComparatorIntCheck()
+ {
+ SortedList<int, string> sl = new SortedList<int, string>();
+
+ sl.Add(3, "Value-Oranges");
+ sl.Add(2, "Value-Bananas");
+ sl.Add(1, "Value-Apples");
+
+ Assert.IsTrue(sl.Count == 3, "NCIC #A0");
+
+ Assert.IsTrue(sl.ContainsKey(1), "NCIC #B1");
+ Assert.IsTrue(sl.ContainsKey(2), "NCIC #B2");
+ Assert.IsTrue(sl.ContainsKey(3), "NCIC #B3");
+
+ Assert.IsFalse(sl.ContainsKey(11), "NCIC #C1");
+ Assert.IsFalse(sl.ContainsKey(22), "NCIC #C2");
+ Assert.IsFalse(sl.ContainsKey(33), "NCIC #C3");
+
+ Assert.IsTrue(sl.Keys[0] == 1, "NCIC #D1");
+ Assert.IsTrue(sl.Keys[1] == 2, "NCIC #D2");
+ Assert.IsTrue(sl.Keys[2] == 3, "NCIC #D3");
+ }
}
}