Skip to content

Commit c1b8ce3

Browse files
committed
Add ForwardListTests
1 parent 8122524 commit c1b8ce3

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

Package.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ let openAttributeGraphCxxTestsTarget = Target.testTarget(
176176
"OpenAttributeGraphCxx",
177177
],
178178
exclude: ["README.md"],
179+
cSettings: sharedCSettings + [.define("SWIFT_TESTING")],
179180
swiftSettings: sharedSwiftSettings + [.interoperabilityMode(.Cxx)]
180181
)
181182
let openAttributeGraphShimsTestsTarget = Target.testTarget(
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//
2+
// ForwardListTests.swift
3+
// OpenAttributeGraphCxxTests
4+
5+
import OpenAttributeGraphCxx_Private.Util
6+
import Testing
7+
8+
struct ForwardListTests {
9+
@Test
10+
func forwardListBasicOperations() {
11+
let list = util.UInt64ForwardList.create()
12+
defer { util.UInt64ForwardList.destroy(list) }
13+
14+
// Test empty list
15+
#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+
38+
list.pop_front()
39+
#expect(list.empty())
40+
}
41+
42+
@Test
43+
func forwardListSequentialOperations() {
44+
let list = util.UInt64ForwardList.create()
45+
defer { util.UInt64ForwardList.destroy(list) }
46+
47+
// Add multiple elements
48+
for i in 0..<5 {
49+
list.push_front(UInt64(i))
50+
}
51+
52+
// Remove all elements and verify order (LIFO - last in, first out)
53+
for i in (0..<5).reversed() {
54+
#expect(!list.empty())
55+
#expect(list.front() == UInt64(i))
56+
list.pop_front()
57+
}
58+
59+
#expect(list.empty())
60+
}
61+
}

0 commit comments

Comments
 (0)