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