Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions content/basics.tex
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,30 @@ \subsection{Compiling with sanitize options}
\begin{lstlisting}[breakatwhitespace=true]
g++ -std=gnu++17 -g -fsanitize=address -fsanitize=undefined -fno-sanitize-recover file.cpp -o file
\end{lstlisting}

\subsection{Stress test}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd move this section to the end of the booklet, since it's not something we're going to use in all contests or at the start of one. We could add a misc section containing this code and potentially more in the future

\subsubsection{Compare two solutions}
\texttt{compare.sh wrong slow generator numTests}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
\texttt{compare.sh wrong slow generator numTests}
\texttt{./compare.sh wrong slow generator numTests}


\begin{itemize}
\item \texttt{wrong}, \texttt{slow} and \texttt{generator} are respectively the executables of the two solutions and of the testcases generator
\item compare the outputs of two solutions of a problem, checking if they give the same outputs
\end{itemize}

\lstinputlisting{source/stresstest/compare.sh}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would \snippet not work here?


\subsubsection{Validate a solution}
\texttt{validate.sh solution validator generator numTests}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
\texttt{validate.sh solution validator generator numTests}
\texttt{./validate.sh solution validator generator numTests}

\begin{itemize}
\item \texttt{solution}, \texttt{validator} and \texttt{generator} are respectively the executables of the solution, validator of a solution and of the testcases generator
\item \texttt{validator} should return the string \texttt{"OK"} or the string that explains the error
\item \texttt{validator} first take in input the \texttt{generator} input and next the program output
\end{itemize}

\lstinputlisting{source/stresstest/validate.sh}

to generate a test case use \texttt{uid(a, b)} that generates a random number in $[a, b]$
\begin{lstlisting}[breakatwhitespace=true]
#define uid(a, b) uniform_int_distribution(a, b)(rng)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
\end{lstlisting}
24 changes: 24 additions & 0 deletions source/stresstest/compare.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

for ((testNum=0;testNum<$4;testNum++))
do
./$3 > input
./$2 < input > out2
./$1 < input > out1
echo $testNum
if !(cmp -s "out1" "out2")
then
echo "Error found!"
echo "Input:"
cat input
echo $1 output:
cat out1
echo $2 output:
cat out2
rm input out1 out2
exit
fi
done
echo ""
echo Passed $4 tests
rm input out1 out2
26 changes: 26 additions & 0 deletions source/stresstest/validate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

for ((testNum=0;testNum<$4;testNum++))
do
./$3 > input
./$1 < input > out
cat input out > data
./$2 < data > res
result=$(cat res)
echo $testNum
if [ "${result:0:2}" != "OK" ];
then
echo "Error found!"
echo "Input:"
cat input
echo "Output:"
cat out
echo "Validator result:"
cat res
rm input out res data
exit
fi
done
echo ""
echo Passed $4 tests
rm input out res data