microsoft/qdk

Public

mirrored fromhttps://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
b78246135c3ebcd60e93cf5818db290c2f2e2bf2

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

samples/testing/classical_values/README.md

23lines · modecode

1# Testing Classical Return Values
2
3This sample project demonstrates testing Q# code that returns classical values.
4
5## Testing Methods
6
7There are two primary ways to test classical values in Q#:
8
91. **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
122. **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
16This 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