forked from YaccConstructor/QuickGraph
-
-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathUndirectedEdgeTests.cs
More file actions
77 lines (64 loc) · 2.65 KB
/
UndirectedEdgeTests.cs
File metadata and controls
77 lines (64 loc) · 2.65 KB
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
using System;
using NUnit.Framework;
namespace QuikGraph.Tests.Structures
{
/// <summary>
/// Tests for <see cref="UndirectedEdge{TVertex}"/>.
///</summary>
[TestFixture]
internal sealed class UndirectedEdgeTests : EdgeTestsBase
{
[Test]
public void Construction()
{
// Value type
CheckEdge(new UndirectedEdge<int>(1, 2), 1, 2);
CheckEdge(new UndirectedEdge<int>(1, 1), 1, 1);
// Reference type
var v1 = new ComparableTestVertex("v1");
var v2 = new ComparableTestVertex("v2");
CheckEdge(new UndirectedEdge<ComparableTestVertex>(v1, v2), v1, v2);
CheckEdge(new UndirectedEdge<ComparableTestVertex>(v1, v1), v1, v1);
// Order correctly on creation
CheckEdge(new UndirectedEdge<int>(2, 1), 1, 2);
// Comparable
var comparableV1 = new ComparableTestVertex("v1");
var comparableV2 = new ComparableTestVertex("v2");
CheckEdge(new UndirectedEdge<ComparableTestVertex>(comparableV2, comparableV1), comparableV1, comparableV2);
}
[Test]
public void Construction_Throws()
{
// ReSharper disable ObjectCreationAsStatement
// ReSharper disable AssignNullToNotNullAttribute
Assert.Throws<ArgumentNullException>(() => new UndirectedEdge<TestVertex>(null, new TestVertex("v1")));
Assert.Throws<ArgumentNullException>(() => new UndirectedEdge<TestVertex>(new TestVertex("v1"), null));
Assert.Throws<ArgumentNullException>(() => new UndirectedEdge<TestVertex>(null, null));
// ReSharper restore AssignNullToNotNullAttribute
// Not comparable
var v1 = new TestVertex("v1");
var v2 = new TestVertex("v2");
Assert.Throws<ArgumentException>(() => new UndirectedEdge<TestVertex>(v1, v2));
// ReSharper restore ObjectCreationAsStatement
}
[Test]
public void Equals()
{
var edge1 = new UndirectedEdge<int>(1, 2);
var edge2 = new UndirectedEdge<int>(1, 2);
Assert.AreEqual(edge1, edge1);
Assert.AreNotEqual(edge1, edge2);
Assert.AreNotEqual(edge2, edge1);
Assert.IsFalse(edge1.Equals(edge2));
Assert.IsFalse(edge2.Equals(edge1));
Assert.AreNotEqual(null, edge1);
Assert.IsFalse(edge1.Equals(null));
}
[Test]
public void ObjectToString()
{
var edge = new UndirectedEdge<int>(1, 2);
Assert.AreEqual("1 <-> 2", edge.ToString());
}
}
}