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