microsoft/qdk
Publicmirrored fromhttps://github.com/microsoft/qdkAvailable
katas/content/complex_arithmetic/polar_multiplication/Verification.qs
27lines · 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 | let y = DrawRandomComplex(); |
| 10 | let xp = ComplexAsComplexPolar(x); |
| 11 | let yp = ComplexAsComplexPolar(y); |
| 12 | |
| 13 | let expected = ComplexAsComplexPolar(TimesC(x, y)); |
| 14 | let actual = Kata.ComplexPolarMult(xp, yp); |
| 15 | |
| 16 | if not ComplexPolarEqual(expected, actual) { |
| 17 | Message("Incorrect"); |
| 18 | Message($"For x = {ComplexPolarAsString(xp)}, y = {ComplexPolarAsString(yp)} " + |
| 19 | $"expected return {ComplexPolarAsString(expected)}, actual return {ComplexPolarAsString(actual)}."); |
| 20 | return false; |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | Message("Correct!"); |
| 25 | return true; |
| 26 | } |
| 27 | } |
| 28 | |