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