-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlinix_test.sh
executable file
·44 lines (36 loc) · 1.03 KB
/
linix_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
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
# Check for the correct number of arguments
if [ "$#" -lt 1 ]; then
echo "Usage: $0 <text_file> <num_tests>"
exit 1
fi
text_file=$1
num_tests=$2
index_file="${text_file}.lidx"
if [[ -z $num_tests ]]; then
num_tests=20
fi
# Create the index file if it doesn't exist
if [ ! -f "$index_file" ]; then
linix "$text_file"
fi
# Get the total number of lines in the text file
total_lines=$(wc -l < "$text_file")
# Run the specified number of tests
for ((i = 0; i < num_tests; i++)); do
# Generate a random line number
line_num=$(( RANDOM % total_lines + 1 ))
# Get the line using the linix script
#echo ".. checking line $line_num"
linix_line=$(linix "$text_file" "$line_num")
# Get the line using sed
sed_line=$(sed -n "${line_num}p" "$text_file")
# Compare the outputs
if [ "$linix_line" == "$sed_line" ]; then
echo "Test $((i + 1)): Pass"
else
echo "Test $((i + 1)): FAIL (line $line_num)"
echo "linix: $linix_line"
echo "sed: $sed_line"
fi
done