Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions run_lz77_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
make -j$(nproc) check TESTS="test_compression_lz77 test_compression_lz77_edge_cases"
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

run_lz77_tests.sh is missing a shebang, so running it directly (e.g., ./run_lz77_tests.sh) will typically fail with an exec format error. Add a #!/bin/bash (or #!/usr/bin/env bash) header and consider set -e (or equivalent) so failures in make propagate reliably.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The script is missing a shebang (e.g., #!/bin/bash), which is necessary for the system to identify the correct interpreter. Additionally, nproc is a Linux-specific utility; providing a fallback ensures the script remains functional on other platforms (like macOS) and avoids potential issues if nproc is unavailable or fails.

Suggested change
make -j$(nproc) check TESTS="test_compression_lz77 test_compression_lz77_edge_cases"
#!/bin/bash
make -j$(nproc 2>/dev/null || echo 1) check TESTS="test_compression_lz77 test_compression_lz77_edge_cases"

22 changes: 22 additions & 0 deletions tests/test_compression_lz77.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,28 @@ int edge_case_tests() {
ASSERT_EQ(output[1], 0x42);
}


// 7. Exact Boundary Distance (Distance == Output Size + 1)
{
// Block 1: 8 Literals ('A'...'H') -> Output "ABCDEFGH" (size 8)
// Block 2: Ref (Dist 9, Len 3)
// Flags: 0 (all literals)
// Data: 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'
// Flags: 1 (Ref at bit 0)
// Data: Dist 9, Len 3. Dist 9 -> 0x009.
// b1 = (9 >> 4) = 0.
// b2 = ((9 & 0xF) << 4) | 0 = 0x90.
std::vector<uint8_t> input = {
0x00, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', // Block 1
0x01, 0x00, 0x90 // Block 2
};
auto output = decompressor.decompress(input.data(), input.size());

ASSERT_EQ(output.size(), 11);
std::string s(output.begin(), output.end());
ASSERT_EQ(s, "ABCDEFGHABC");
}

std::cout << "[EDGE] Passed.\n";
return 0;
}
Expand Down
26 changes: 26 additions & 0 deletions tests/test_compression_lz77_edge_cases.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,32 @@ int main() {
std::cout << "Passed.\n";
}


// Test 7: Exact Boundary Backreference (Distance == Output Size + 1)
// We need some initial data to be valid and a full block to reset flags.
// Block 1: 8 Literals [0x00, 'A'...'H'] -> Output "ABCDEFGH" (size 8)
// Block 2: Flags [0x01] (1st item Ref)
// Ref bytes [0x00, 0x90] -> Dist 9, Len 3.
//
// Distance 9 == Output Size 8 + 1.
// Implementation clamps distance to output.size() = 8.
// Start = 8 - 8 = 0.
// Copies output[0]...output[2] -> "ABC".
// Result: "ABCDEFGHABC".
{
std::cout << " Test 7: Exact Boundary Backreference... ";
std::vector<uint8_t> input = {
0x00, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', // Block 1
0x01, 0x00, 0x90 // Block 2
};
auto output = decompressor.decompress(input.data(), input.size());

ASSERT_EQ(output.size(), 11);
std::string s(output.begin(), output.end());
ASSERT_EQ(s, "ABCDEFGHABC");
std::cout << "Passed.\n";
}
Comment on lines +122 to +145
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This test case is identical to the one added in tests/test_compression_lz77.cpp. Maintaining duplicate test logic across multiple files increases the maintenance burden and the risk of tests diverging over time. Consider consolidating these edge cases into a single test file or using a shared utility to define common test scenarios.


std::cout << "[EDGE] All tests passed.\n";
return 0;
}
Loading