File: ComparerTest.cs

package info (click to toggle)
mono 2.6.7-5.1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 327,344 kB
  • ctags: 413,649
  • sloc: cs: 2,471,883; xml: 1,768,594; ansic: 350,665; sh: 13,644; makefile: 8,640; perl: 1,784; asm: 717; cpp: 209; python: 146; sql: 81; sed: 16
file content (110 lines) | stat: -rw-r--r-- 2,647 bytes parent folder | download | duplicates (10)
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
// 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]
		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]
		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;
				}
			}
		}
	}
}