Skip to content

Commit 59e6c49

Browse files
committed
TableColumnMetadata tests.
1 parent b038fd4 commit 59e6c49

2 files changed

Lines changed: 115 additions & 0 deletions

File tree

SQLitePCL.pretty.tests/TableColumnMetadataTests.cs

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,121 @@ public class TableColumnMetadataTests
99
[Test]
1010
public void TestEquality()
1111
{
12+
Tuple<string, string, bool, bool, bool>[] tests =
13+
{
14+
Tuple.Create("", "", false, false, false),
15+
Tuple.Create("a", "", false, false, false),
16+
Tuple.Create("a", "b", false, false, false),
17+
Tuple.Create("a", "b", true, false, false),
18+
Tuple.Create("a", "b", true, true, false),
19+
Tuple.Create("a", "b", true, true, true),
20+
};
21+
22+
Assert.False(new TableColumnMetadata("", "", false, false, false).Equals(null));
23+
Assert.False(new TableColumnMetadata("", "", false, false, false).Equals(new Object()));
24+
25+
for (int i = 0; i < tests.Length; i++)
26+
{
27+
for (int j = 0; j < tests.Length; j++)
28+
{
29+
var fst = new TableColumnMetadata(tests[i].Item1, tests[i].Item2, tests[i].Item3, tests[i].Item4, tests[i].Item5);
30+
var snd = new TableColumnMetadata(tests[j].Item1, tests[j].Item2, tests[j].Item3, tests[j].Item4, tests[j].Item5);
31+
32+
if (i == j)
33+
{
34+
Assert.True(fst.Equals(fst));
35+
Assert.True(snd.Equals(snd));
36+
Assert.AreEqual(fst, snd);
37+
Assert.True(fst == snd);
38+
Assert.False(fst != snd);
39+
}
40+
else
41+
{
42+
Assert.AreNotEqual(fst, snd);
43+
Assert.False(fst == snd);
44+
Assert.True(fst != snd);
45+
}
46+
}
47+
}
1248
}
1349

1450
[Test]
1551
public void TestGetHashcode()
1652
{
53+
Tuple<string, string, bool, bool, bool>[] tests =
54+
{
55+
Tuple.Create("", "", false, false, false),
56+
Tuple.Create("a", "", false, false, false),
57+
Tuple.Create("a", "b", false, false, false),
58+
Tuple.Create("a", "b", true, false, false),
59+
Tuple.Create("a", "b", true, true, false),
60+
Tuple.Create("a", "b", true, true, true),
61+
};
62+
63+
foreach (var test in tests)
64+
{
65+
var fst = new TableColumnMetadata(test.Item1, test.Item2, test.Item3, test.Item4, test.Item5);
66+
var snd = new TableColumnMetadata(test.Item1, test.Item2, test.Item3, test.Item4, test.Item5);
67+
68+
Assert.AreEqual(fst.GetHashCode(), snd.GetHashCode());
69+
}
1770
}
1871

1972
[Test]
2073
public void TestComparison()
2174
{
75+
TableColumnMetadata[] tests =
76+
{
77+
new TableColumnMetadata("", "", false, false, false),
78+
new TableColumnMetadata("a", "", false, false, false),
79+
new TableColumnMetadata("a", "b", false, false, false),
80+
new TableColumnMetadata("a", "b", true, false, false),
81+
new TableColumnMetadata("a", "b", true, true, false),
82+
new TableColumnMetadata("a", "b", true, true, true),
83+
};
84+
85+
for (int i = 0; i < tests.Length; i++)
86+
{
87+
for (int j = 0; j < tests.Length; j++)
88+
{
89+
if (i < j)
90+
{
91+
Assert.Less(tests[i].CompareTo(tests[j]), 0);
92+
Assert.Less(((IComparable)tests[i]).CompareTo(tests[j]), 0);
93+
94+
Assert.True(tests[i] < tests[j]);
95+
Assert.True(tests[i] <= tests[j]);
96+
Assert.False(tests[i] > tests[j]);
97+
Assert.False(tests[i] >= tests[j]);
98+
}
99+
else if (i == j)
100+
{
101+
Assert.AreEqual(tests[i].CompareTo(tests[j]), 0);
102+
Assert.AreEqual(((IComparable)tests[i]).CompareTo(tests[j]), 0);
103+
104+
Assert.True(tests[i] >= tests[j]);
105+
Assert.True(tests[i] <= tests[j]);
106+
Assert.False(tests[i] > tests[j]);
107+
Assert.False(tests[i] < tests[j]);
108+
}
109+
else
110+
{
111+
Assert.Greater(tests[i].CompareTo(tests[j]), 0);
112+
Assert.Greater(((IComparable)tests[i]).CompareTo(tests[j]), 0);
113+
114+
Assert.True(tests[i] > tests[j]);
115+
Assert.True(tests[i] >= tests[j]);
116+
Assert.False(tests[i] < tests[j]);
117+
Assert.False(tests[i] <= tests[j]);
118+
}
119+
}
120+
}
121+
122+
TableColumnMetadata nullColumnInfo = null;
123+
Assert.AreEqual(new TableColumnMetadata("", "", false, false, false).CompareTo(nullColumnInfo), 1);
124+
125+
object nullObj = null;
126+
Assert.AreEqual(((IComparable)new TableColumnMetadata("", "", false, false, false)).CompareTo(nullObj), 1);
22127
}
23128
}
24129
}

SQLitePCL.pretty/TableColumnMetadata.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,16 @@ public bool IsAutoIncrement
147147
/// <inheritdoc/>
148148
public bool Equals(TableColumnMetadata other)
149149
{
150+
if (Object.ReferenceEquals(other, null))
151+
{
152+
return false;
153+
}
154+
155+
if (Object.ReferenceEquals(this, other))
156+
{
157+
return true;
158+
}
159+
150160
return this.DeclaredType == other.DeclaredType &&
151161
this.CollationSequence == other.CollationSequence &&
152162
this.HasNotNullConstraint == other.HasNotNullConstraint &&

0 commit comments

Comments
 (0)