···
8
+
NC='\033[0m' # No Color
10
+
# Test configuration
11
+
temp_file="lab66.output"
12
+
program="../build/lab66"
20
+
rm -f "$temp_file" verses.txt
24
+
trap cleanup EXIT ERR
26
+
# Function to print test results
28
+
local test_name="$1"
32
+
total_tests=$((total_tests + 1))
34
+
if [ "$result" = "PASS" ]; then
35
+
echo -e "${GREEN}[PASS]${NC} $test_name: $message"
36
+
passed_tests=$((passed_tests + 1))
38
+
echo -e "${RED}[FAIL]${NC} $test_name: $message"
42
+
# Function to print test section header
44
+
echo -e "\n${BLUE}=== $1 ===${NC}"
47
+
# Build program if needed
48
+
if [ ! -f "$program" ]; then
49
+
print_section "Building Program"
50
+
cd .. && make lab66 > /dev/null 2>&1
53
+
if [ $build_result -ne 0 ]; then
54
+
print_result "Program Build" "FAIL" "Could not build $program"
57
+
print_result "Program Build" "PASS" "Program built successfully"
60
+
# Test 1: Program compilation/existence
61
+
if [ ! -f "$program" ]; then
62
+
print_section "Test 1: Program Availability"
63
+
print_result "Program Existence" "FAIL" "Program $program not found"
67
+
# Test 2: Basic Bible Verse Lookup Test (Genesis 1:1)
68
+
print_section "Basic Bible Verse Lookup Test"
70
+
# Test with known valid verse
71
+
basic_input="Genesis\n1\n1"
72
+
resp=$(echo -e "$basic_input" | "$program" 2>&1)
76
+
if [ -n "$resp" ]; then
79
+
echo "(No output produced)"
83
+
if [ $exit_code -ne 0 ]; then
84
+
print_result "Basic Execution" "FAIL" "Program exited with code $exit_code"
87
+
print_result "Basic Execution" "PASS" "Program executed successfully"
90
+
# Check if output contains required prompts
91
+
if [[ "$resp" == *"Please enter the reference of the verse you would like"* ]]; then
92
+
print_result "Initial Prompt" "PASS" "Program shows initial prompt"
94
+
print_result "Initial Prompt" "FAIL" "Program missing initial prompt"
97
+
if [[ "$resp" == *"the book:"* ]]; then
98
+
print_result "Book Prompt" "PASS" "Program prompts for book"
100
+
print_result "Book Prompt" "FAIL" "Program missing book prompt"
103
+
if [[ "$resp" == *"the chapter:"* ]]; then
104
+
print_result "Chapter Prompt" "PASS" "Program prompts for chapter"
106
+
print_result "Chapter Prompt" "FAIL" "Program missing chapter prompt"
109
+
if [[ "$resp" == *"the verse:"* ]]; then
110
+
print_result "Verse Prompt" "PASS" "Program prompts for verse"
112
+
print_result "Verse Prompt" "FAIL" "Program missing verse prompt"
115
+
# Check for verse output format
116
+
if [[ "$resp" == *"GENESIS 1:1"* ]]; then
117
+
print_result "Verse Format" "PASS" "Program outputs verse in correct format"
119
+
print_result "Verse Format" "FAIL" "Program missing or incorrect verse format"
122
+
# Check if verses.txt file was created
123
+
if [ -f "verses.txt" ]; then
124
+
verses_content=$(cat verses.txt)
125
+
if [[ "$verses_content" == *"In the beginning God created the heaven and the earth"* ]]; then
126
+
print_result "File Output" "PASS" "verses.txt created with correct content"
128
+
print_result "File Output" "FAIL" "verses.txt has incorrect content"
131
+
print_result "File Output" "FAIL" "verses.txt file not created"
134
+
# Function to run verse lookup test
136
+
local test_name="$1"
140
+
local expected_pattern="$5"
141
+
local should_create_file="$6"
143
+
# Clean up previous test
146
+
input="$book\n$chapter\n$verse"
147
+
output=$(echo -e "$input" | "$program" 2>&1)
150
+
if [ $exit_code -ne 0 ]; then
151
+
print_result "$test_name" "FAIL" "Program crashed (exit code $exit_code)"
155
+
# Check if expected pattern is found in output
156
+
pattern_found=false
157
+
if [[ "$output" == *"$expected_pattern"* ]]; then
161
+
# For tests expecting specific output, pattern must be found
162
+
if [ -n "$expected_pattern" ] && [ "$pattern_found" = "false" ]; then
163
+
print_result "$test_name" "FAIL" "Expected '$expected_pattern' not found in output"
167
+
# Check file creation expectations
168
+
if [ "$should_create_file" = "true" ]; then
169
+
if [ -f "verses.txt" ] && [ "$pattern_found" = "true" ]; then
170
+
print_result "$test_name" "PASS" "Expected output found and file created"
171
+
elif [ ! -f "verses.txt" ]; then
172
+
print_result "$test_name" "FAIL" "Expected file verses.txt not created"
174
+
print_result "$test_name" "FAIL" "File created but expected output not found"
177
+
if [ ! -f "verses.txt" ] && [ "$pattern_found" = "true" ]; then
178
+
print_result "$test_name" "PASS" "Expected error output and no file created"
179
+
elif [ -f "verses.txt" ]; then
180
+
print_result "$test_name" "FAIL" "verses.txt file should not be created for error cases"
182
+
print_result "$test_name" "FAIL" "Expected error message not found"
187
+
# Valid Verse Tests
188
+
print_section "Valid Verse Tests"
190
+
run_verse_test "Exodus 20:3" "Exodus" "20" "3" "EXODUS 20:3" true
191
+
run_verse_test "Psalm 23:1" "Psalm" "23" "1" "PSALM 23:1" true
194
+
print_section "Error Case Tests"
196
+
run_verse_test "Invalid Book" "Matthew" "1" "1" "Matthew does not exist in the Old Testament" false
197
+
run_verse_test "Invalid Chapter" "Esther" "18" "3" "Chapter 18 does not exist in Esther" false
198
+
run_verse_test "Invalid Verse" "Psalm" "117" "5" "Verse 5 does not exist in Psalm 117" false
200
+
# Adversarial Testing Section
201
+
print_section "Adversarial Tests"
204
+
run_verse_test "Empty Book Name" "" "1" "1" "Please enter the reference" false
205
+
run_verse_test "Non-numeric Chapter" "Genesis" "abc" "1" "Please enter the reference" false
206
+
run_verse_test "Non-numeric Verse" "Genesis" "1" "xyz" "Please enter the reference" false
207
+
run_verse_test "Zero Chapter" "Genesis" "0" "1" "Please enter the reference" false
208
+
run_verse_test "Zero Verse" "Genesis" "1" "0" "Please enter the reference" false
209
+
run_verse_test "Negative Chapter" "Genesis" "-1" "1" "Please enter the reference" false
210
+
run_verse_test "Negative Verse" "Genesis" "1" "-1" "Please enter the reference" false
211
+
run_verse_test "Very Large Chapter" "Genesis" "999999" "1" "Please enter the reference" false
212
+
run_verse_test "Very Large Verse" "Genesis" "1" "999999" "Please enter the reference" false
214
+
# Test case sensitivity
215
+
run_verse_test "Lowercase Book" "genesis" "1" "1" "genesis does not exist in the Old Testament" false
216
+
run_verse_test "Mixed Case Book" "GEnesis" "1" "1" "GEnesis does not exist in the Old Testament" false
218
+
# Test two-word books
219
+
run_verse_test "First Samuel" "First Samuel" "1" "1" "FIRST SAMUEL 1:1" true
220
+
run_verse_test "Second Kings" "Second Kings" "1" "1" "SECOND KINGS 1:1" true
223
+
print_section "Test Summary"
224
+
echo -e "${BLUE}Tests passed: $passed_tests/$total_tests${NC}"
226
+
if [ $passed_tests -eq $total_tests ]; then
227
+
echo -e "${GREEN}All tests passed!${NC}"
230
+
echo -e "${RED}Some tests failed!${NC}"