|
5 | 5 | import OpenAttributeGraphCxx_Private.Util |
6 | 6 | import Testing |
7 | 7 |
|
| 8 | +@Suite("Heap tests") |
8 | 9 | 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) |
18 | 23 | } |
19 | 24 |
|
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) |
30 | 36 | } |
31 | | - |
32 | | - @Test |
33 | | - func heapWithInitialBuffer() { |
| 37 | + |
| 38 | + @Test("Creating heap with initial buffer") |
| 39 | + func createWithInitialBuffer() { |
34 | 40 | var buffer = Array<UInt8>(repeating: 0, count: 1024) |
35 | 41 |
|
36 | 42 | let heap = buffer.withUnsafeMutableBytes { bufferPtr in |
37 | 43 | let charPtr = bufferPtr.bindMemory(to: CChar.self) |
38 | 44 | return util.Heap.create(charPtr.baseAddress, 1024, 2048) |
39 | 45 | } |
40 | | - defer { util.Heap.destroy(heap) } |
| 46 | + defer { |
| 47 | + util.Heap.destroy(heap) |
| 48 | + } |
41 | 49 |
|
42 | 50 | #expect(heap.capacity() == 1024) |
43 | 51 | #expect(heap.increment() == 2048) |
| 52 | + #expect(heap.num_nodes() == 0) |
44 | 53 | } |
45 | | - |
46 | | - @Test |
47 | | - func heapReset() { |
| 54 | + |
| 55 | + @Test("Reset heap functionality") |
| 56 | + func resetHeap() { |
48 | 57 | let heap = util.Heap.create(nil, 0, 1024) |
49 | | - defer { util.Heap.destroy(heap) } |
| 58 | + defer { |
| 59 | + util.Heap.destroy(heap) |
| 60 | + } |
50 | 61 |
|
51 | | - // Reset heap |
| 62 | + // Reset heap to different configuration |
52 | 63 | heap.reset(nil, 0) |
53 | 64 |
|
54 | | - // Verify heap is still operational after reset |
| 65 | + // Verify heap properties after reset |
55 | 66 | #expect(heap.increment() == 1024) |
56 | | - #expect(heap.num_nodes() >= 0) |
| 67 | + #expect(heap.capacity() == 0) |
| 68 | + #expect(heap.num_nodes() == 0) |
57 | 69 | } |
58 | | - |
59 | | - @Test |
60 | | - func heapPrint() { |
| 70 | + |
| 71 | + @Test("Print heap debug information") |
| 72 | + func printHeapInfo() { |
61 | 73 | let heap = util.Heap.create(nil, 0, 1024) |
62 | | - defer { util.Heap.destroy(heap) } |
| 74 | + defer { |
| 75 | + util.Heap.destroy(heap) |
| 76 | + } |
63 | 77 |
|
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 |
66 | 79 | heap.print() |
67 | 80 |
|
68 | 81 | // Verify heap is still functional after print |
69 | 82 | #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) |
72 | 85 | } |
73 | 86 | } |
0 commit comments