1
|
/*
|
2
|
Copyright (c) 2003-2006 Niels Kokholm and Peter Sestoft
|
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
of this software and associated documentation files (the "Software"), to deal
|
5
|
in the Software without restriction, including without limitation the rights
|
6
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
copies of the Software, and to permit persons to whom the Software is
|
8
|
furnished to do so, subject to the following conditions:
|
9
|
|
10
|
The above copyright notice and this permission notice shall be included in
|
11
|
all copies or substantial portions of the Software.
|
12
|
|
13
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
SOFTWARE.
|
20
|
*/
|
21
|
|
22
|
using System;
|
23
|
using C5;
|
24
|
using NUnit.Framework;
|
25
|
using SCG = System.Collections.Generic;
|
26
|
|
27
|
namespace C5UnitTests.RecordsTests
|
28
|
{
|
29
|
[TestFixture]
|
30
|
public class Basic
|
31
|
{
|
32
|
[SetUp]
|
33
|
public void Init()
|
34
|
{
|
35
|
}
|
36
|
[Test]
|
37
|
public void FourElement()
|
38
|
{
|
39
|
Rec<string, string, int, int> rec1, rec2, rec3;
|
40
|
rec1 = new Rec<string, string, int, int>("abe", null, 0, 1);
|
41
|
rec2 = new Rec<string, string, int, int>("abe", null, 0, 1);
|
42
|
rec3 = new Rec<string, string, int, int>("abe", "kat", 0, 1);
|
43
|
Assert.IsTrue(rec1 == rec2);
|
44
|
Assert.IsFalse(rec1 != rec2);
|
45
|
Assert.IsFalse(rec1 == rec3);
|
46
|
Assert.IsTrue(rec1 != rec3);
|
47
|
Assert.IsTrue(rec1.Equals(rec2));
|
48
|
Assert.IsFalse(rec1.Equals(rec3));
|
49
|
//
|
50
|
Assert.IsFalse(rec1.Equals(null));
|
51
|
Assert.IsFalse(rec1.Equals("bamse"));
|
52
|
//
|
53
|
Assert.IsTrue(rec1.GetHashCode() == rec2.GetHashCode());
|
54
|
Assert.IsFalse(rec1.GetHashCode() == rec3.GetHashCode());
|
55
|
//
|
56
|
Assert.AreEqual("abe", rec1.X1);
|
57
|
Assert.IsNull(rec1.X2);
|
58
|
Assert.AreEqual(0, rec1.X3);
|
59
|
Assert.AreEqual(1, rec1.X4);
|
60
|
}
|
61
|
|
62
|
|
63
|
[Test]
|
64
|
public void ThreeElement()
|
65
|
{
|
66
|
Rec<string, string, int> rec1, rec2, rec3;
|
67
|
rec1 = new Rec<string, string, int>("abe", null, 0);
|
68
|
rec2 = new Rec<string, string, int>("abe", null, 0);
|
69
|
rec3 = new Rec<string, string, int>("abe", "kat", 0);
|
70
|
Assert.IsTrue(rec1 == rec2);
|
71
|
Assert.IsFalse(rec1 != rec2);
|
72
|
Assert.IsFalse(rec1 == rec3);
|
73
|
Assert.IsTrue(rec1 != rec3);
|
74
|
Assert.IsTrue(rec1.Equals(rec2));
|
75
|
Assert.IsFalse(rec1.Equals(rec3));
|
76
|
//
|
77
|
Assert.IsFalse(rec1.Equals(null));
|
78
|
Assert.IsFalse(rec1.Equals("bamse"));
|
79
|
//
|
80
|
Assert.IsTrue(rec1.GetHashCode() == rec2.GetHashCode());
|
81
|
Assert.IsFalse(rec1.GetHashCode() == rec3.GetHashCode());
|
82
|
//
|
83
|
Assert.AreEqual("abe", rec1.X1);
|
84
|
Assert.IsNull(rec1.X2);
|
85
|
Assert.AreEqual(0, rec1.X3);
|
86
|
|
87
|
}
|
88
|
|
89
|
[Test]
|
90
|
public void TwoElement()
|
91
|
{
|
92
|
Rec<string, string> rec1, rec2, rec3;
|
93
|
rec1 = new Rec<string, string>("abe", null);
|
94
|
rec2 = new Rec<string, string>("abe", null);
|
95
|
rec3 = new Rec<string, string>("abe", "kat");
|
96
|
Assert.IsTrue(rec1 == rec2);
|
97
|
Assert.IsFalse(rec1 != rec2);
|
98
|
Assert.IsFalse(rec1 == rec3);
|
99
|
Assert.IsTrue(rec1 != rec3);
|
100
|
Assert.IsTrue(rec1.Equals(rec2));
|
101
|
Assert.IsFalse(rec1.Equals(rec3));
|
102
|
//
|
103
|
Assert.IsFalse(rec1.Equals(null));
|
104
|
Assert.IsFalse(rec1.Equals("bamse"));
|
105
|
//
|
106
|
Assert.IsTrue(rec1.GetHashCode() == rec2.GetHashCode());
|
107
|
Assert.IsFalse(rec1.GetHashCode() == rec3.GetHashCode());
|
108
|
//
|
109
|
Assert.AreEqual("abe", rec1.X1);
|
110
|
Assert.IsNull(rec1.X2);
|
111
|
}
|
112
|
|
113
|
[TearDown]
|
114
|
public void Dispose()
|
115
|
{
|
116
|
}
|
117
|
}
|
118
|
|
119
|
}
|