-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·34 lines (27 loc) · 1.11 KB
/
test.sh
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
#!/bin/bash
TEST_DIR="tests"
COMPRESSED_FILE="compressed"
DECOMPRESSED_FILE="decompressed.txt"
INPUT_FILES=($(find "$TEST_DIR" -type f -name "*.txt"))
echo "----- Running tests -----"
for INPUT_FILE in "${INPUT_FILES[@]}"; do
./huffman compress "$INPUT_FILE" "$COMPRESSED_FILE" > /dev/null 2>&1
./huffman decompress "$COMPRESSED_FILE" "$DECOMPRESSED_FILE" > /dev/null 2>&1
if cmp -s "$INPUT_FILE" "$DECOMPRESSED_FILE"; then
INPUT_SIZE=$(stat -f%z "$INPUT_FILE")
COMPRESSED_SIZE=$(stat -f%z "$COMPRESSED_FILE")
if [ "$INPUT_SIZE" -ne 0 ]; then
COMPRESSION_RATIO=$(echo "scale=3; $COMPRESSED_SIZE / $INPUT_SIZE" | bc)
else
COMPRESSION_RATIO="N/A"
fi
echo "PASS: $(basename "$INPUT_FILE") successfully compressed and decompressed - ratio: 0$COMPRESSION_RATIO"
else
echo "FAIL: $(basename "$INPUT_FILE") did not match after decompression."
echo "----- Exiting -----"
rm -f $COMPRESSED_FILE $DECOMPRESSED_FILE
exit 1
fi
rm -f $COMPRESSED_FILE $DECOMPRESSED_FILE
done
echo "----- All tests passed -----"