Lab 3: add description

This commit is contained in:
Akemi Izuko 2024-05-02 19:45:08 -06:00
commit 7155aa5a6e
Signed by: akemi
GPG key ID: 8DE0764E1809E9FC
2 changed files with 306 additions and 0 deletions

138
lab-3/check.sh Executable file
View file

@ -0,0 +1,138 @@
#!/usr/bin/env bash
declare -r program="$1"
declare -r tmp1=tmp1 #"$(mktemp)"
declare -r tmp2=tmp2 #"$(mktemp)"
declare -ri case_1_a1=1
declare -ri case_1_a2=4
declare -r case_1="$(mktemp)"
cat <<'EOM' > "$case_1"
$$$$
$$$$
$$$$
$$$$
EOM
declare -ri case_2_a1=1
declare -ri case_2_a2=10
declare -r case_2="$(mktemp)"
cat <<'EOM' > "$case_2"
$$$$$$$$$$
$$$$$$$$$$
$$$$$$$$$$
$$$$$$$$$$
$$$$$$$$$$
$$$$$$$$$$
$$$$$$$$$$
$$$$$$$$$$
$$$$$$$$$$
$$$$$$$$$$
EOM
declare -ri case_3_a1=2
declare -ri case_3_a2=6
declare -r case_3="$(mktemp)"
cat <<'EOM' > "$case_3"
$$
$$$$
$$$$$$
EOM
declare -ri case_4_a1=2
declare -ri case_4_a2=7
declare -r case_4="$(mktemp)"
cat <<'EOM' > "$case_4"
$
$$$
$$$$$
$$$$$$$
EOM
declare -ri case_5_a1=3
declare -ri case_5_a2=14
declare -r case_5="$(mktemp)"
cat <<'EOM' > "$case_5"
$$$$$$$$$$$$$$
$$$$$$$$$$$$
$$$$$$$$$$
$$$$$$$$
$$$$$$
$$$$
$$
EOM
declare -ri case_6_a1=4
declare -ri case_6_a2=14
declare -r case_6="$(mktemp)"
cat <<'EOM' > "$case_6"
$$
$$$$
$$$$$$
$$$$$$$$
$$$$$$$$$$
$$$$$$$$$$$$
$$$$$$$$$$$$$$
$$$$$$$$$$$$
$$$$$$$$$$
$$$$$$$$
$$$$$$
$$$$
$$
EOM
declare -ri case_7_a1=4
declare -ri case_7_a2=15
declare -r case_7="$(mktemp)"
cat <<'EOM' > "$case_7"
$
$$$
$$$$$
$$$$$$$
$$$$$$$$$
$$$$$$$$$$$
$$$$$$$$$$$$$
$$$$$$$$$$$$$$$
$$$$$$$$$$$$$
$$$$$$$$$$$
$$$$$$$$$
$$$$$$$
$$$$$
$$$
$
EOM
if ! gcc -Wall -Wextra -Werror -std=c99 "$program"; then
echo "Program compiled with errors. Did NOT pass check"
exit 1
fi
run_case() {
local a1="$1"
local a2="$2"
local tmp="$3"
local comp="$4"
local case="$5"
if ! ./a.out $a1 $a2 > "$tmp"; then
echo "Error at runtime on case $case"
exit 2
fi
sed -i 's#\s*$##' "$tmp"
if ! diff -qy "$tmp" "$comp"; then
echo "Input does not match for case $case"
exit 2
fi
}
# Case 1
run_case "$case_1_a1" "$case_1_a2" "$tmp1" "$case_1" 1
run_case "$case_2_a1" "$case_2_a2" "$tmp1" "$case_2" 2
run_case "$case_3_a1" "$case_3_a2" "$tmp1" "$case_3" 3
run_case "$case_4_a1" "$case_4_a2" "$tmp1" "$case_4" 4
run_case "$case_5_a1" "$case_5_a2" "$tmp1" "$case_5" 5
run_case "$case_6_a1" "$case_6_a2" "$tmp1" "$case_6" 6
run_case "$case_7_a1" "$case_7_a2" "$tmp1" "$case_7" 7
echo "You passed! Commit to git before the deadline"

168
lab-3/lab_3_description.md Normal file
View file

@ -0,0 +1,168 @@
# Lab 3 - Fancy shapes
In this lab we'll be focusing on the C programming aspect. This will cover
for-loops and if-statements. To practice these we'll be drawing some shapes in
the terminal!
The input will be one of the following numbers, passed through argv:
1. A square
2. A triangle
3. An inverted triangle (upside down)
4. A diamond
Your program will take in 2 arguments. The first is a number between 1 and 4,
indicating which of the shapes listed above you'll be printing. The second
argument is a number indicating the _largest horizontal width_ of the shape. For
example, for a triangle, this'll be the width of the base.
Your program will print the indicated shape at the indicated dimensions. Write
your code in a `main.c` file, then run `bash check.sh main.c` to test your code.
## Examples
#### Example 1
```
./a.out 1 4
```
Output:
```
$$$$
$$$$
$$$$
$$$$
```
#### Example 2
```
./a.out 1 10
```
Output:
```
$$$$$$$$$$
$$$$$$$$$$
$$$$$$$$$$
$$$$$$$$$$
$$$$$$$$$$
$$$$$$$$$$
$$$$$$$$$$
$$$$$$$$$$
$$$$$$$$$$
$$$$$$$$$$
```
#### Example 3
```
./a.out 2 6
```
Output:
```
$$
$$$$
$$$$$$
```
Notice how with an even number for the width, will result with 2 at the top, not
one.
#### Example 4
```
./a.out 2 7
```
Output:
```
$
$$$
$$$$$
$$$$$$$
```
#### Example 5
```
./a.out 3 14
```
Output:
```
$$$$$$$$$$$$$$
$$$$$$$$$$$$
$$$$$$$$$$
$$$$$$$$
$$$$$$
$$$$
$$
```
#### Example 6
```
./a.out 4 14
```
Output:
```
$$
$$$$
$$$$$$
$$$$$$$$
$$$$$$$$$$
$$$$$$$$$$$$
$$$$$$$$$$$$$$
$$$$$$$$$$$$
$$$$$$$$$$
$$$$$$$$
$$$$$$
$$$$
$$
```
#### Example 7
```
./a.out 4 15
```
Output:
```
$
$$$
$$$$$
$$$$$$$
$$$$$$$$$
$$$$$$$$$$$
$$$$$$$$$$$$$
$$$$$$$$$$$$$$$
$$$$$$$$$$$$$
$$$$$$$$$$$
$$$$$$$$$
$$$$$$$
$$$$$
$$$
$
```
## Testing
Run the following command to test your work:
```
bash check.sh main.c
```
If the output doesn't say you passed, your program has a bug. Fix it and then
try again.