-
Notifications
You must be signed in to change notification settings - Fork 4
add stresstesting scripts #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
73c7b81
f93e0e6
5eaa0fb
863adf7
2129424
5fb6c33
8add517
eae35e2
d9d44d0
fe1db82
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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} | ||||||
\subsubsection{Compare two solutions} | ||||||
\texttt{compare.sh wrong slow generator numTests} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
\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} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
\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} |
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 |
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 |
There was a problem hiding this comment.
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