Skip to content

Commit 535c9d8

Browse files
committed
Update Util tests to follow reference implementation patterns
1 parent f432e49 commit 535c9d8

File tree

2 files changed

+109
-69
lines changed

2 files changed

+109
-69
lines changed

Tests/OpenAttributeGraphCxxTests/Util/ForwardListTests.swift

Lines changed: 58 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,44 +5,71 @@
55
import OpenAttributeGraphCxx_Private.Util
66
import Testing
77

8+
@Suite("List tests")
89
struct ForwardListTests {
9-
@Test
10-
func forwardListBasicOperations() {
10+
11+
@Test("Initialize empty list")
12+
func initEmpty() {
1113
let list = util.UInt64ForwardList.create()
12-
defer { util.UInt64ForwardList.destroy(list) }
13-
14-
// Test empty list
14+
defer {
15+
util.UInt64ForwardList.destroy(list)
16+
}
17+
1518
#expect(list.empty())
16-
17-
// Test push_front and empty state
18-
list.push_front(42)
19-
#expect(!list.empty())
20-
21-
// Test front access
22-
#expect(list.front() == 42)
23-
24-
// Test multiple push_front operations
25-
list.push_front(100)
26-
#expect(list.front() == 100)
27-
28-
list.push_front(200)
29-
#expect(list.front() == 200)
30-
31-
// Test pop_front
32-
list.pop_front()
33-
#expect(list.front() == 100)
34-
35-
list.pop_front()
36-
#expect(list.front() == 42)
37-
19+
}
20+
21+
@Test("Push element")
22+
func pushElement() {
23+
let list = util.UInt64ForwardList.create()
24+
defer {
25+
util.UInt64ForwardList.destroy(list)
26+
}
27+
28+
list.push_front(1)
29+
30+
#expect(list.empty() == false)
31+
32+
let front = list.front()
33+
#expect(front == 1)
34+
}
35+
36+
@Test("Push multiple elements")
37+
func pushMultipleElements() {
38+
let list = util.UInt64ForwardList.create()
39+
defer {
40+
util.UInt64ForwardList.destroy(list)
41+
}
42+
43+
list.push_front(1)
44+
list.push_front(2)
45+
list.push_front(3)
46+
47+
let front = list.front()
48+
#expect(front == 3)
49+
}
50+
51+
@Test("Remove element")
52+
func removeElement() {
53+
let list = util.UInt64ForwardList.create()
54+
defer {
55+
util.UInt64ForwardList.destroy(list)
56+
}
57+
58+
list.push_front(1)
59+
list.push_front(2)
60+
list.push_front(3)
3861
list.pop_front()
39-
#expect(list.empty())
62+
63+
let front = list.front()
64+
#expect(front == 2)
4065
}
4166

42-
@Test
43-
func forwardListSequentialOperations() {
67+
@Test("Sequential operations")
68+
func sequentialOperations() {
4469
let list = util.UInt64ForwardList.create()
45-
defer { util.UInt64ForwardList.destroy(list) }
70+
defer {
71+
util.UInt64ForwardList.destroy(list)
72+
}
4673

4774
// Add multiple elements
4875
for i in 0..<5 {

Tests/OpenAttributeGraphCxxTests/Util/HeapTests.swift

Lines changed: 51 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,69 +5,82 @@
55
import OpenAttributeGraphCxx_Private.Util
66
import Testing
77

8+
@Suite("Heap tests")
89
struct HeapTests {
9-
@Test
10-
func heapBasicOperations() {
11-
let heap = util.Heap.create(nil, 0, 1024)
12-
defer { util.Heap.destroy(heap) }
13-
14-
// Test heap creation and basic properties
15-
#expect(heap.increment() == 1024)
16-
#expect(heap.num_nodes() >= 0)
17-
#expect(heap.capacity() >= 0)
10+
11+
let nodeSize = 16
12+
13+
@Test("Initializing with default arguments")
14+
func initDefault() {
15+
let heap = util.Heap.create(nil, 0, 0)
16+
defer {
17+
util.Heap.destroy(heap)
18+
}
19+
20+
#expect(heap.capacity() == 0)
21+
#expect(heap.increment() == 0x2000)
22+
#expect(heap.num_nodes() == 0)
1823
}
1924

20-
@Test
21-
func heapMinimumIncrement() {
22-
// Test with minimum increment constant (0x400 = 1024 bytes)
23-
let minimumIncrement = 0x400
24-
25-
// Create heap with minimum increment
26-
let heap = util.Heap.create(nil, 0, minimumIncrement)
27-
defer { util.Heap.destroy(heap) }
28-
29-
#expect(heap.increment() == minimumIncrement)
25+
@Test("Initializing with custom increment")
26+
func initWithCustomIncrement() {
27+
let customIncrement = 4096
28+
let heap = util.Heap.create(nil, 0, customIncrement)
29+
defer {
30+
util.Heap.destroy(heap)
31+
}
32+
33+
#expect(heap.capacity() == 0)
34+
#expect(heap.increment() == customIncrement)
35+
#expect(heap.num_nodes() == 0)
3036
}
31-
32-
@Test
33-
func heapWithInitialBuffer() {
37+
38+
@Test("Creating heap with initial buffer")
39+
func createWithInitialBuffer() {
3440
var buffer = Array<UInt8>(repeating: 0, count: 1024)
3541

3642
let heap = buffer.withUnsafeMutableBytes { bufferPtr in
3743
let charPtr = bufferPtr.bindMemory(to: CChar.self)
3844
return util.Heap.create(charPtr.baseAddress, 1024, 2048)
3945
}
40-
defer { util.Heap.destroy(heap) }
46+
defer {
47+
util.Heap.destroy(heap)
48+
}
4149

4250
#expect(heap.capacity() == 1024)
4351
#expect(heap.increment() == 2048)
52+
#expect(heap.num_nodes() == 0)
4453
}
45-
46-
@Test
47-
func heapReset() {
54+
55+
@Test("Reset heap functionality")
56+
func resetHeap() {
4857
let heap = util.Heap.create(nil, 0, 1024)
49-
defer { util.Heap.destroy(heap) }
58+
defer {
59+
util.Heap.destroy(heap)
60+
}
5061

51-
// Reset heap
62+
// Reset heap to different configuration
5263
heap.reset(nil, 0)
5364

54-
// Verify heap is still operational after reset
65+
// Verify heap properties after reset
5566
#expect(heap.increment() == 1024)
56-
#expect(heap.num_nodes() >= 0)
67+
#expect(heap.capacity() == 0)
68+
#expect(heap.num_nodes() == 0)
5769
}
58-
59-
@Test
60-
func heapPrint() {
70+
71+
@Test("Print heap debug information")
72+
func printHeapInfo() {
6173
let heap = util.Heap.create(nil, 0, 1024)
62-
defer { util.Heap.destroy(heap) }
74+
defer {
75+
util.Heap.destroy(heap)
76+
}
6377

64-
// Test print method doesn't crash and can be called
65-
// This method prints debug information to stdout
78+
// Test that print method can be called without crashing
6679
heap.print()
6780

6881
// Verify heap is still functional after print
6982
#expect(heap.increment() == 1024)
70-
#expect(heap.num_nodes() >= 0)
71-
#expect(heap.capacity() >= 0)
83+
#expect(heap.num_nodes() == 0)
84+
#expect(heap.capacity() == 0)
7285
}
7386
}

0 commit comments

Comments
 (0)