/
valuetype-equals.cs
135 lines (106 loc) · 3.95 KB
/
valuetype-equals.cs
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
124
125
126
127
128
129
130
131
132
133
134
135
using System;
struct BoolStruct {
bool x;
public BoolStruct (bool x) { this.x = x; }
}
struct CharStruct {
char x;
public CharStruct (char x) { this.x = x; }
}
struct Int8Struct {
sbyte x;
public Int8Struct (sbyte x) { this.x = x; }
}
struct UInt8Struct {
byte x;
public UInt8Struct (byte x) { this.x = x; }
}
struct Int16Struct {
short x;
public Int16Struct (short x) { this.x = x; }
}
struct UInt16Struct {
ushort x;
public UInt16Struct (ushort x) { this.x = x; }
}
struct Int32Struct {
int x;
public Int32Struct (int x) { this.x = x; }
}
struct UInt32Struct {
uint x;
public UInt32Struct (uint x) { this.x = x; }
}
struct Int64Struct {
long x;
public Int64Struct (long x) { this.x = x; }
}
struct UInt64Struct {
ulong x;
public UInt64Struct (ulong x) { this.x = x; }
}
struct FloatStruct {
float x;
public FloatStruct (float x) { this.x = x; }
}
struct DoubleStruct {
double x;
public DoubleStruct (double x) { this.x = x; }
}
public class Driver {
static void AssertEqual (object a, object b) {
if (!a.Equals (b))
throw new Exception (String.Format ("must be equal {0} {1}", a, b));
}
static void AssertNotEqual (object a, object b) {
if (a.Equals (b))
throw new Exception (String.Format ("must not be equal {0} {1}", a, b));
}
public static int Main () {
AssertEqual (new BoolStruct (true), new BoolStruct (true));
AssertNotEqual (new BoolStruct (false), new BoolStruct (true));
AssertEqual (new CharStruct ('c'), new CharStruct ('c'));
AssertNotEqual (new CharStruct ('d'), new CharStruct ('c'));
AssertEqual (new Int8Struct (13), new Int8Struct (13));
AssertEqual (new Int8Struct (0), new Int8Struct (0));
AssertNotEqual (new Int8Struct (44), new Int8Struct (1));
AssertNotEqual (new Int8Struct (0), new Int8Struct (55));
AssertEqual (new UInt8Struct (13), new UInt8Struct (13));
AssertEqual (new UInt8Struct (0), new UInt8Struct (0));
AssertNotEqual (new UInt8Struct (44), new UInt8Struct (1));
AssertNotEqual (new UInt8Struct (0), new UInt8Struct (55));
AssertEqual (new Int16Struct (13), new Int16Struct (13));
AssertEqual (new Int16Struct (0), new Int16Struct (0));
AssertNotEqual (new Int16Struct (44), new Int16Struct (1));
AssertNotEqual (new Int16Struct (0), new Int16Struct (55));
AssertEqual (new UInt16Struct (13), new UInt16Struct (13));
AssertEqual (new UInt16Struct (0), new UInt16Struct (0));
AssertNotEqual (new UInt16Struct (44), new UInt16Struct (1));
AssertNotEqual (new UInt16Struct (0), new UInt16Struct (55));
AssertEqual (new Int32Struct (13), new Int32Struct (13));
AssertEqual (new Int32Struct (0), new Int32Struct (0));
AssertNotEqual (new Int32Struct (44), new Int32Struct (1));
AssertNotEqual (new Int32Struct (0), new Int32Struct (55));
AssertEqual (new UInt32Struct (13), new UInt32Struct (13));
AssertEqual (new UInt32Struct (0), new UInt32Struct (0));
AssertNotEqual (new UInt32Struct (44), new UInt32Struct (1));
AssertNotEqual (new UInt32Struct (0), new UInt32Struct (55));
AssertEqual (new Int64Struct (13), new Int64Struct (13));
AssertEqual (new Int64Struct (0), new Int64Struct (0));
AssertNotEqual (new Int64Struct (44), new Int64Struct (1));
AssertNotEqual (new Int64Struct (0), new Int64Struct (55));
AssertEqual (new UInt64Struct (13), new UInt64Struct (13));
AssertEqual (new UInt64Struct (0), new UInt64Struct (0));
AssertNotEqual (new UInt64Struct (44), new UInt64Struct (1));
AssertNotEqual (new UInt64Struct (0), new UInt64Struct (55));
AssertEqual (new FloatStruct (13), new FloatStruct (13));
AssertEqual (new FloatStruct (0), new FloatStruct (0));
AssertNotEqual (new FloatStruct (44), new FloatStruct (1));
AssertNotEqual (new FloatStruct (0), new FloatStruct (55));
AssertEqual (new DoubleStruct (13), new DoubleStruct (13));
AssertEqual (new DoubleStruct (0), new DoubleStruct (0));
AssertNotEqual (new DoubleStruct (44), new DoubleStruct (1));
AssertNotEqual (new DoubleStruct (0), new DoubleStruct (55));
return 0;
}
}