microsoft/qdk
Publicmirrored fromhttps://github.com/microsoft/qdkAvailable
katas/content/complex_arithmetic/complex_conjugate/Verification.qs
27lines · modecode
| 1 | namespace Kata.Verification { |
| 2 | open Microsoft.Quantum.Math; |
| 3 | |
| 4 | function ComplexConjugate_Reference(x : Complex) : Complex { |
| 5 | // Return the complex conjugate |
| 6 | Complex(x::Real, -x::Imag) |
| 7 | } |
| 8 | |
| 9 | @EntryPoint() |
| 10 | operation CheckSolution() : Bool { |
| 11 | for _ in 0 .. 24 { |
| 12 | let x = DrawRandomComplex(); |
| 13 | |
| 14 | let expected = ComplexConjugate_Reference(x); |
| 15 | let actual = Kata.ComplexConjugate(x); |
| 16 | |
| 17 | if not ComplexEqual(expected, actual) { |
| 18 | Message("Incorrect"); |
| 19 | Message($"For x = {ComplexAsString(x)} expected return {ComplexAsString(expected)}, actual return {ComplexAsString(actual)}."); |
| 20 | return false; |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | Message("Correct!"); |
| 25 | return true; |
| 26 | } |
| 27 | } |