Skip to content

Latest commit

 

History

History
 
 

UnitTesting

Unit Testing Sample

This sample set illustrates techniques for testing the correctness of the circuits and computing metrics describing circuits such as number of qubits used, gate counts and depth. We implement, test and compute metrics for the circuits from the following categories

Each file illustrating the category is accompanied with the file ending "Tests" with test for the circuits. The list of the test files is below:

Functions from Microsoft.Quantum.Canon used for testing

The correctness of all the circuits in this sample is tested using the following function from Microsoft.Quantum.Canon:

  • AssertOperationsEqualReferenced
  • AssertOperationsEqualInPlace
  • AssertQubitState

Test harness

This sample uses Microsoft.Quantum.Xunit extension to xUnit.net framework to automatically discover Q# tests. The tests are all the operations with signature "() => ()" with suffix "Test". The test harness located in QuantumSimulatorTestTargets.cs.

Metrics calculation

In addition to testing the correctness of the circuit we also compute their metrics such as gate counts, depth and number of qubit used. Metrics calculation is illustrated in files ending "Metrics":

File MetricCalculationUtils.cs contains the function that creates QCTraceSimulator configured for metric calculation.

Sample dependencies

This samples uses Microsoft.Quantum.Canon library and depends on the following NuGet packages:

  • Microsoft.Quantum.Development.Kit: Q# runtime framework
  • Microsoft.Quantum.Xunit: xUnit.net extension for discovering Q# tests
  • xunit: xUnit.net testing framework for .NET