-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAvlNodeTests.cs
More file actions
136 lines (121 loc) · 4.21 KB
/
Copy pathAvlNodeTests.cs
File metadata and controls
136 lines (121 loc) · 4.21 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
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
136
using XISOSharp.DataStructures;
using XISOSharp.Models;
namespace XISOSharp.Tests;
/// <summary>
/// Unit tests for the <see cref="AvlNode"/> data structure
/// and the <see cref="AvlSkew"/> enumeration.
/// </summary>
public class AvlNodeTests
{
/// <summary>
/// Verifies that <see cref="AvlSkew"/> enumeration values
/// are 0 (NoSkew), 1 (LeftSkew), and 2 (RightSkew).
/// </summary>
[Fact]
public void AvlSkew_Values()
{
Assert.Equal(0, (int)AvlSkew.NoSkew);
Assert.Equal(1, (int)AvlSkew.LeftSkew);
Assert.Equal(2, (int)AvlSkew.RightSkew);
}
/// <summary>
/// Verifies that a newly constructed <see cref="AvlNode"/>
/// has expected default values for all fields.
/// </summary>
[Fact]
public void New_AvlNode_HasDefaults()
{
AvlNode node = new();
Assert.Equal(0u, node.Offset);
Assert.Equal(0, node.DirStart);
Assert.Equal("", node.Filename);
Assert.Equal(0u, node.FileSize);
Assert.Equal(0u, node.StartSector);
Assert.Null(node.Subdirectory);
Assert.Equal(0u, node.OldStartSector);
Assert.Equal(AvlSkew.NoSkew, node.Skew);
Assert.Null(node.Left);
Assert.Null(node.Right);
}
/// <summary>
/// Verifies that all properties of an <see cref="AvlNode"/>
/// can be set via object initializer and read back correctly.
/// </summary>
[Fact]
public void AvlNode_FieldsCanBeSet()
{
AvlNode left = new();
AvlNode right = new();
AvlNode subdir = new();
AvlNode node = new()
{
Offset = 100,
DirStart = 0x1000,
Filename = "game.iso",
FileSize = 2048,
StartSector = 5,
Subdirectory = subdir,
OldStartSector = 3,
Skew = AvlSkew.LeftSkew,
Left = left,
Right = right
};
Assert.Equal(100u, node.Offset);
Assert.Equal(0x1000, node.DirStart);
Assert.Equal("game.iso", node.Filename);
Assert.Equal(2048u, node.FileSize);
Assert.Equal(5u, node.StartSector);
Assert.Same(subdir, node.Subdirectory);
Assert.Equal(3u, node.OldStartSector);
Assert.Equal(AvlSkew.LeftSkew, node.Skew);
Assert.Same(left, node.Left);
Assert.Same(right, node.Right);
}
/// <summary>
/// Verifies that <see cref="AvlNode.EmptySubdirectory"/>
/// is not null.
/// </summary>
[Fact]
public void EmptySubdirectory_IsNotNull() => Assert.NotNull(AvlNode.EmptySubdirectory);
/// <summary>
/// Verifies that <see cref="AvlNode.EmptySubdirectory"/>
/// always returns the same singleton instance.
/// </summary>
[Fact]
public void EmptySubdirectory_IsSingleton() => Assert.Same(AvlNode.EmptySubdirectory, AvlNode.EmptySubdirectory);
/// <summary>
/// Verifies that <see cref="AvlNode.EmptySubdirectory"/>
/// has default field values (empty filename, zero offset,
/// null left/right children).
/// </summary>
[Fact]
public void EmptySubdirectory_HasDefaults()
{
Assert.Equal("", AvlNode.EmptySubdirectory.Filename);
Assert.Equal(0u, AvlNode.EmptySubdirectory.Offset);
Assert.Null(AvlNode.EmptySubdirectory.Left);
Assert.Null(AvlNode.EmptySubdirectory.Right);
}
/// <summary>
/// Verifies that <see cref="AvlNode.EmptySubdirectory"/>
/// is a distinct instance, not the same as a newly
/// constructed <see cref="AvlNode"/>.
/// </summary>
[Fact]
public void EmptySubdirectory_IsDistinctFromNewNode() => Assert.NotSame(new AvlNode(), AvlNode.EmptySubdirectory);
/// <summary>
/// Verifies that the <see cref="AvlNode.Skew"/> property
/// can be set to all three <see cref="AvlSkew"/> values
/// (NoSkew, LeftSkew, RightSkew) and read back correctly.
/// </summary>
[Fact]
public void AvlNode_AllSkewValues_CanBeSet()
{
AvlNode node = new() { Skew = AvlSkew.NoSkew };
Assert.Equal(AvlSkew.NoSkew, node.Skew);
node.Skew = AvlSkew.LeftSkew;
Assert.Equal(AvlSkew.LeftSkew, node.Skew);
node.Skew = AvlSkew.RightSkew;
Assert.Equal(AvlSkew.RightSkew, node.Skew);
}
}