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

gtest-142.cs « tests « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ce98c1637a68482aa2771fb4fc6a6bd8707662b6 (plain)
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
113
114
115
116
117
118
119
120
121
122
123
using System;

public static class Assert
{
	public static int Errors {
		get { return errors; }
	}

	static int errors = 0;

	static void Error (string method, string text)
	{
		Console.WriteLine ("Assert failed: {0} ({1})", method, text);
		errors++;
	}

	public static void IsTrue (string text, bool b)
	{
		if (!b)
			Error ("IsTrue", text);
	}

	public static void IsFalse (string text, bool b)
	{
		if (b)
			Error ("IsFalse", text);
	}

	public static void IsNull<T> (string text, Nullable<T> nullable)
		where T : struct
	{
		if (nullable.HasValue)
			Error ("IsNull", text);
	}

	public static void IsNotNull<T> (string text, Nullable<T> nullable)
		where T : struct
	{
		if (!nullable.HasValue)
			Error ("IsNotNull", text);
	}

	public static void IsTrue (string text, Nullable<bool> b)
	{
		if (!b.HasValue || !b.Value)
			Error ("IsTrue", text);
	}

	public static void IsFalse (string text, Nullable<bool> b)
	{
		if (!b.HasValue || b.Value)
			Error ("IsFalse", text);
	}
}

class X
{
	public static int Main ()
	{
		bool? a = null, b = false, c = true;
		bool? d = null, e = false, f = true;

		Assert.IsNull ("a", a);
		Assert.IsFalse ("b", b);
		Assert.IsTrue ("c", c);
		Assert.IsTrue ("a == d", a == d);
		Assert.IsTrue ("b == e", b == e);
		Assert.IsTrue ("c == f", c == f);

		Assert.IsFalse ("a != d", a != d);
		Assert.IsFalse ("a == b", a == b);
		Assert.IsTrue ("a != b", a != b);

		Assert.IsNull ("d & a", d & a);
		Assert.IsFalse ("d & b", d & b);
		Assert.IsNull ("d & c", d & c);
		Assert.IsFalse ("e & a", e & a);
		Assert.IsFalse ("e & b", e & b);
		Assert.IsFalse ("e & c", e & c);
		Assert.IsNull ("f & a", f & a);
		Assert.IsFalse ("f & b", f & b);
		Assert.IsTrue ("f & c", f & c);

		Assert.IsNull ("d | a", d | a);
		Assert.IsNull ("d | b", d | b);
		Assert.IsTrue ("d | c", d | c);
		Assert.IsNull ("e | a", e | a);
		Assert.IsFalse ("e | b", e | b);
		Assert.IsTrue ("e | c", e | c);
		Assert.IsTrue ("f | a", f | a);
		Assert.IsTrue ("f | b", f | b);
		Assert.IsTrue ("f | c", f | c);

		Assert.IsNull ("d ^ a", d ^ a);
		Assert.IsNull ("d ^ b", d ^ b);
		Assert.IsNull ("d ^ c", d ^ c);
		Assert.IsNull ("e ^ a", e ^ a);
		Assert.IsFalse ("e ^ b", e ^ b);
		Assert.IsTrue ("e ^ c", e ^ c);
		Assert.IsNull ("f ^ a", f ^ a);
		Assert.IsTrue ("f ^ b", f ^ b);
		Assert.IsFalse ("f ^ c", f ^ c);
		
		int? g = 3, h = null, i = 3, j = null;

		Assert.IsFalse ("g == null", g == null);
		Assert.IsTrue ("g != null", g != null);
		Assert.IsTrue ("h == null", h == null);
		Assert.IsFalse ("h != null", h != null);

		Assert.IsTrue ("g == i", g == i);
		Assert.IsFalse ("g != i", g != i);
		Assert.IsFalse ("g == j", g == j);
		Assert.IsTrue ("g != j", g != j);
		Assert.IsFalse ("h == i", h == i);
		Assert.IsTrue ("h != i", h != i);
		Assert.IsTrue ("h == j", h == j);
		Assert.IsFalse ("h != j", h != j);

		Console.WriteLine ("{0} errors.", Assert.Errors);
		return Assert.Errors;
	}
}