Skip to content

Commit

Permalink
update bash functions
Browse files Browse the repository at this point in the history
  • Loading branch information
iagorrr committed Aug 8, 2024
1 parent e8dc1de commit 1e3a29f
Showing 1 changed file with 57 additions and 54 deletions.
111 changes: 57 additions & 54 deletions settings-and-macros/.bashrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,80 +2,79 @@
alias clip="xclip -sel clip"

# compile the $1 parameter, if a $2 is provided
# the name will be the the binary output, if
# none is provided the binary name will be
# the name will be the the binary output, if
# none is provided the binary name will be
# 'a.out'
comp() {
echo ">> COMPILING $1 <<" 1>&2
echo ">> COMPILING $1 <<" 1>&2

if [ $# -gt 1 ]; then
outfile="${2}"
else
outfile="a.out"
fi
if [ $# -gt 1 ]; then
outfile="${2}"
else
outfile="a.out"
fi

time g++ -std=c++20 \
-O2 \
-g3 \
-Wall \
-fsanitize=address,undefined \
-fno-sanitize-recover \
-D LOCAL \
-o "${outfile}" \
"$1"
time g++ -std=c++20 \
-O2 \
-g3 \
-Wall \
-fsanitize=address,undefined \
-fno-sanitize-recover \
-D LOCAL \
-o "${outfile}" \
"$1"

if [ $? -ne 0 ]; then
echo ">> FAILED <<" 1>&2
return 1
fi
echo ">> DONE << " 1>&2
if [ $? -ne 0 ]; then
echo ">> FAILED <<" 1>&2
return 1
fi
echo ">> DONE << " 1>&2
}

# run the binary given in $1, if none is
# run the binary given in $1, if none is
# given it will try to run the 'a.out'
# binary
run() {
to_run=./a.out
if [ -n "$1" ]; then
to_run="$1"
fi
time $to_run
to_run=./a.out
if [ -n "$1" ]; then
to_run="$1"
fi
time $to_run
}

# just comp and run your cpp file
# accpets <in1 >out and everything else
comprun() {
comp "$1" "a"
run ./a ${@:2}
comp "$1" "a" && run ./a ${@:2}
}

testall() {
comp "$1" generator
comp "$2" brute
comp "$3" main
comp "$1" generator
comp "$2" brute
comp "$3" main

input_counter=1
input_counter=1

while true; do
echo "$input_counter"
run ./generator > input
run ./main < input > main_output.txt
run ./brute < input > brute_output.txt
while true; do
echo "$input_counter"
run ./generator >input
run ./main <input >main_output.txt
run ./brute <input >brute_output.txt

diff brute_output.txt main_output.txt
if [ $? -ne 0 ]; then
echo "Outputs differ at input $input_counter"
echo "Brute file output:"
cat brute_output.txt
echo "Main file output:"
cat main_output.txt
echo "input used: "
cat input
break
fi
diff brute_output.txt main_output.txt
if [ $? -ne 0 ]; then
echo "Outputs differ at input $input_counter"
echo "Brute file output:"
cat brute_output.txt
echo "Main file output:"
cat main_output.txt
echo "input used: "
cat input
break
fi

((input_counter++))
done
((input_counter++))
done
}

# Creates a contest with hame $2
Expand All @@ -88,9 +87,13 @@ prepare_contest() {
cp "$1"/debug.cpp .
cp "$1"/macro.cpp .

for i in {a..z}
do
for i in {a..z}; do
cp macro.cpp "$i".cpp
cp macro.cpp "$i".py
done
}

touch_macro() {
cp "$1"/macro.cpp "$2"
cp "$1"/debug.cpp .
}

0 comments on commit 1e3a29f

Please sign in to comment.