File: ComparerTest.cs

package info (click to toggle)
mono 6.14.1%2Bds2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,282,732 kB
  • sloc: cs: 11,182,461; xml: 2,850,281; ansic: 699,123; cpp: 122,919; perl: 58,604; javascript: 30,841; asm: 21,845; makefile: 19,602; sh: 10,973; python: 4,772; pascal: 925; sql: 859; sed: 16; php: 1
file content (112 lines) | stat: -rw-r--r-- 2,713 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// ComparerTest

using System;
using System.Collections;
using System.Globalization;
using System.Runtime.Serialization;

using NUnit.Framework;

namespace MonoTests.System.Collections {

	[TestFixture]
	public class ComparerTest {

		[Test]
		public void TestDefaultInstance ()
		{
			// Make sure the instance returned by Default
			// is really a Comparer.
			Assert.IsNotNull (Comparer.Default as Comparer);
		}

		[Test]
		public void TestCompare ()
		{
			Comparer c = Comparer.Default;
			Assert.IsTrue (c.Compare (1, 2) < 0, "1,2");
			Assert.IsTrue (c.Compare (2, 2) == 0, "2,2");
			Assert.IsTrue (c.Compare (3, 2) > 0, "3,2");
		}

		[Test]
		[ExpectedException (typeof (ArgumentException))]
		public void Compare_FirstIComparer ()
		{
			Assert.IsTrue (Comparer.Default.Compare (1, new object ()) > 0, "int,object");
		}

		[Test]
		[ExpectedException (typeof (ArgumentException))]
		public void Compare_SecondIComparer ()
		{
			Assert.IsTrue (Comparer.Default.Compare (new object (), 1) > 0, "object,int");
		}

		[Test]
		[ExpectedException (typeof (ArgumentException))]
		public void Compare_BothNonIComparer ()
		{
			Comparer.Default.Compare (new object (), new object ());
		}

		[Test]
		[Category ("ManagedCollator")]
		public void Invariant ()
		{
			Comparer c = Comparer.DefaultInvariant;
			Assert.IsTrue (c.Compare ("a", "A") < 0);
		}

		[Test]
		public void Invariant2 ()
		{
			Assert.IsTrue (CultureInfo.InvariantCulture.CompareInfo.Compare ("a", "A", CompareOptions.Ordinal) > 0);
		}

		[Test]
		[ExpectedException (typeof (ArgumentNullException))]
		public void Constructor_Null ()
		{
			new Comparer (null);
		}

		[Test]
		[Category ("ManagedCollator")]
		public void Constructor ()
		{
			Comparer c = new Comparer (CultureInfo.InvariantCulture);
			Assert.IsTrue (c.Compare ("a", "A") < 0);
		}

		[Test]
		[ExpectedException (typeof (ArgumentNullException))]
		public void GetObjectData_Null ()
		{
			Comparer c = Comparer.DefaultInvariant;
			c.GetObjectData (null, new StreamingContext ());
		}

		[Test]
		public void GetObjectData ()
		{
			Comparer c = Comparer.DefaultInvariant;
			SerializationInfo si = new SerializationInfo (typeof (Comparer), new FormatterConverter ());
			c.GetObjectData (si, new StreamingContext ());
			foreach (SerializationEntry se in si) {
				switch (se.Name) {
				case "CompareInfo":
					CompareInfo ci = (se.Value as CompareInfo);
					Assert.IsNotNull (ci, "CompareInfo");
					Assert.AreEqual (127, ci.LCID, "LCID");
					break;
				default:
					string msg = String.Format ("Unexpected {0} information of type {1} with value '{2}'.",
						se.Name, se.ObjectType, se.Value);
					Assert.Fail (msg);
					break;
				}
			}
		}
	}
}