Skip to content

Commit 0200489

Browse files
committed
🎉
1 parent 5713b27 commit 0200489

File tree

3 files changed

+37
-27
lines changed

3 files changed

+37
-27
lines changed

Extra/prob05/tests/7.out

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
1082401: 100001000010000100001
1515
1084961: 100001000111000100001
1616
1086753: 100001001010100100001
17-
1089313: 100001001111100100001
18-
1090721: 100001010010010100001
19-
1093281: 100001010111010100001
20-
1095073: 100001011010110100001
21-
1097633: 100001011111110100001
22-
1098849: 100001100010001100001
23-
1101409: 100001100111001100001
24-
1103201: 100001101010101100001
25-
1105761: 100001101111101100001
17+
1089313: 100001001111100110001
18+
1090721: 100001010010010110001
19+
1093281: 100001010111010110001
20+
1095073: 100001011010110110001
21+
1097633: 100001011111110110001
22+
1098849: 100001100010001110001
23+
1101409: 100001100111001110001
24+
1103201: 100001101010101110001
25+
1105761: 100001101111101110001
2626
1107169: 100001110010011100001
2727
1109729: 100001110111011100001
2828
1111521: 100001111010111100001

README.md

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ gcc -O2 -std=c99 -pedantic -Wall -o a.out myprogram.c -lm
4141

4242
## Testing
4343

44-
You can test your own code with the [test script](https://github.com/pl3onasm/Imperative-programming/blob/main/ctest.sh). It will try to compile your code and run it on all the test cases. It will also compare your output with the expected output, and check for memory leaks by running a Valgrind test.
44+
You can test your own code with the [test script](https://github.com/pl3onasm/Imperative-programming/blob/main/ctest.sh). It will try to compile your code and run it on all the test cases. It will also compare your output with the expected output, and check for memory leaks by running a Valgrind test. If a test fails, the script will display the line number where there was a mismatch between the expected and the actual output, and the corresponding lines, so you can easily find the error. In order to avoid too much clutter, the script will only display the first 6 lines where mismatches were found.
4545

4646
In order to use it, you basically have two options:
4747

@@ -81,26 +81,25 @@ Now you can run the script from the directory containing your program and the fo
8181
ctest.sh myprogram.c
8282
```
8383

84-
      
85-
86-
Note that if you want to use ```less```, you should add the -R flag:
87-
88-
```linux
89-
ctest.sh myprogram.c | less -R
90-
```
84+
   
9185

9286
You may also choose to redirect the output to a file, in which case the color codes will be removed automatically to render a plain text file:
9387

9488
```linux
9589
ctest.sh myprogram.c > results.txt
9690
```
9791

98-
      
99-
An output example of the test script:
100-
      
92+
## Notes
93+
94+
All commands were given with Ubuntu in mind. If you are using a different Linux distribution, you may need to change the commands accordingly.
95+
96+
The script was tested on Ubuntu 22.04 LTS, using GCC 13.1.0, Valgrind 3.18.1, and GNU bash 5.1.16(1)-release.
97+
98+
## Output example of the script
10199

102100
<p align="center" width="60%">
103101
<img src="example.jpg"
104102
alt="Example output"
105-
style="float: left; padding-top:200px" />
106-
</p>
103+
style="float: left; padding-top:25px" />
104+
</p>
105+

ctest.sh

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/bash
22
# Author: David De Potter
3+
# Developed and tested on Ubuntu 22.04 LTS, with GNU bash, version 5.1.16
4+
35
# This script will try to compile your program and test its correctness
46
# by running it on all the test cases for the current problem.
57
# It will also perform a test for memory leaks.
@@ -93,23 +95,32 @@ for INFILE in "${INFILES[@]}"; do
9395
if [ -n "$DIF" ]; then
9496
if [ -t 1 ]; then echo -e $(red "Test failed.")
9597
else echo -e "Test failed."; fi
96-
I=0; J=0
97-
echo "$DIF" | while [[ $I -lt 6 ]] && read -r line; do
98+
EXP=0; GOT=0
99+
echo "$DIF" | (while [[ $EXP -lt 6 ]] && read -r line; do
98100
if [[ $line == "<"* ]]; then
99101
if [ -t 1 ]; then echo -e " $(green "$line")"
100102
else echo -e " $line"; fi
101-
J=$((J+1))
103+
EXP=$((EXP + 1))
102104
elif [[ $line == ">"* ]]; then
103105
if [ -t 1 ]; then echo -e " $(red "$line")"
104106
else echo -e " $line"; fi
105-
I=$((I+1))
107+
GOT=$((GOT + 1))
106108
elif [[ $line == *"c"* ]]; then
107109
OUT=$(echo "$line" | cut -d "c" -f 1)
108110
OUT=$(echo "$OUT" | sed 's/,/-/g')
109111
echo -e "\n line "$OUT""
110112
fi
111113
done
112-
echo
114+
while [[ $GOT -ne $EXP ]]; do
115+
# get the next > lines until EXP == GOT
116+
read -r line
117+
if [[ $line == ">"* ]]; then
118+
if [ -t 1 ]; then echo -e " $(red "$line")"
119+
else echo -e " $line"; fi
120+
GOT=$((GOT + 1))
121+
fi
122+
done
123+
echo)
113124
else
114125
if [ -t 1 ]; then
115126
echo -e $(green "PASSED!")

0 commit comments

Comments
 (0)