microsoft/qdk
Publicmirrored fromhttps://github.com/microsoft/qdkAvailable
samples/testing/classical_values/README.md
23lines · modecode
| 1 | # Testing Classical Return Values |
| 2 | |
| 3 | This sample project demonstrates testing Q# code that returns classical values. |
| 4 | |
| 5 | ## Testing Methods |
| 6 | |
| 7 | There are two primary ways to test classical values in Q#: |
| 8 | |
| 9 | 1. **Return them to Python and run checks in Python:** |
| 10 | Use the `eval` Python API to get the results of Q# code and check that they are as expected. |
| 11 | |
| 12 | 2. **Q# `Fact` Assertions:** |
| 13 | Use a `Fact` function in your Q# code that checks whether the classical value within it are correct. The `Fact` function asserts that the check returns `true`. |
| 14 | |
| 15 | ## Project Structure |
| 16 | This sample project is a multi-file Q# project that showcases both testing methods. The project structure is as follows: |
| 17 | |
| 18 | - src |
| 19 | - `ClassicalFunction.qs`: Q# file containing the classical function to be tested |
| 20 | - `Measurement.qs`: Q# file containing the operation with `Result[]` return type to be tested |
| 21 | - `TestCode.qs`: Q# file containing the test logic for the first two files to be called in Python wrapper |
| 22 | - `qsharp.json`: Q# project manifest file, instructing compiler to include all files in `src` directory. |
| 23 | - `test_classical_values.py`: Python wrapper containing tests. |
| 24 | |