Skip to content

Instantly share code, notes, and snippets.

@0xJchen
Created September 27, 2023 19:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0xJchen/5998c53f0cd5cd84dc9dccd247a6aa92 to your computer and use it in GitHub Desktop.
Save 0xJchen/5998c53f0cd5cd84dc9dccd247a6aa92 to your computer and use it in GitHub Desktop.
hw2-testcase
#!/bin/bash
# Initialize a variable to store the maximum percentage
max_percentage=0.0
# Iterate over all n.png files in the hw2img/move/ directory
for file in hw2img/*.png; do
# Extract the base filename without extension
base_name=$(basename "$file" .png)
# Check if the base filename is a number between 0 and 50 inclusive
if [[ "$base_name" =~ ^[0-9]+$ && "$base_name" -ge 0 && "$base_name" -le 50 ]]; then
continue # Skip the current iteration and proceed to the next file
fi
# Execute the pngtest command (output is ignored)
./pngtest "$file" > /dev/null 2>&1
# Execute the gcov command and store its output in a variable
output=$(gcov *.c)
# Remove the specified files
rm *.gcda pngout.png
# Extract the percentage from the last line of the gcov output
percentage=$(echo "$output" | tail -n 1 | awk -F':' '{print $2}' | awk -F'%' '{print $1}' | tr -d ' ')
# Compare the extracted percentage with the max_percentage
if (( $(echo "$percentage > $max_percentage" | bc -l) )); then
max_percentage=$percentage
fi
done
# Print the largest percentage
echo "The largest percentage is: $max_percentage%"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment