Skip to content

Commit

Permalink
Update Generate Test Vector Example
Browse files Browse the repository at this point in the history
Use different size output to reiterate that the output is first in the results of :dumptests.

Some minor rewording and wordsmithing.
  • Loading branch information
mccleeary-galois committed Oct 2, 2024
1 parent ce8e3f1 commit 75a61ec
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
Binary file modified docs/ProgrammingCryptol.pdf
Binary file not shown.
22 changes: 11 additions & 11 deletions docs/ProgrammingCryptol/highAssurance/HighAssurance.tex
Original file line number Diff line number Diff line change
Expand Up @@ -179,30 +179,30 @@ \subsection{Generating test vectors}
\label{sec:gentestvec}

Cryptol has the ability to generate test vectors for non-polymorphic functions (there is limited support for polymorphic types) using the \texttt{:dumptests} REPL command.
When \texttt{:dumptests} is given a file to dump the output and a function in scope, it will randomly generate inputs for the function and run them for you.
The \texttt{:dumptests} command takes a file and an in-scope function; it randomly generates inputs for the function, executes the function on those inputs, and prints the output and inputs to the file.
\begin{Verbatim}
:dumptests <results file> <function>
:dumptests results.txt myFunction
\end{Verbatim}
The results file will contain a tab delimited file in which the first column contains the output, and each column after contains the inputs to the function in order.
You can set the number of tests you want to generate in your test vector by using the \texttt{:set tests=100} command. Additionally, you can also change base using \texttt{:set base=2}.
The results file will contain a tab delimited table in which the first column contains the output, and each column after contains the inputs to the function in order.
You can set the number of tests you want to generate in your test vector by using the \texttt{:set tests=100} command. Additionally, you can also change the base used to print to the results file using \texttt{:set base=2}.
This is because the command \texttt{:dumptests} uses the same settings for random generation that is used in \ref{sec:quickcheck}.
The example below shows \texttt{:dumptests} run on an instance of a function polymorphic \texttt{f} which has two inputs.
\begin{code}
f : {n} (fin n, n >= 2) => [n] -> [n] -> [n]
f x y = x + 2 * y
f : {n} (fin n, n >= 2) => [n] -> [n] -> [2 * n]
f x y = x # (2 * y)
\end{code}
\begin{Verbatim}
Cryptol> :set tests = 5
Cryptol> :set base = 2
Cryptol> :dumptests result.txt f`{8}
Cryptol> :dumptests result.txt f`{4}
Cryptol> :quit
% cat result.txt
0b11011110 0b10010010 0b00100110
0b10101111 0b01010011 0b00101110
0b10100001 0b01001001 0b10101100
0b10111110 0b11101100 0b01101001
0b00110000 0b11111100 0b10011010
0b10100000 0b1010 0b0000
0b10111100 0b1011 0b0110
0b11111010 0b1111 0b0101
0b10000010 0b1000 0b1001
0b00001000 0b0000 0b0100
\end{Verbatim}


Expand Down

0 comments on commit 75a61ec

Please sign in to comment.