microsoft/qdk
Publicmirrored from https://github.com/microsoft/qdkAvailable
katas/content/deutsch_jozsa/implement_bv/Verification.qs
26lines · modecode
| 1 | namespace Kata.Verification { |
| 2 | import KatasUtils.*; |
| 3 | import Std.Math.*; |
| 4 | |
| 5 | operation CheckSolution() : Bool { |
| 6 | for (n, oracle, expected, name) in [ |
| 7 | (2, qs => (), [0, 0], "f(x) = 0"), |
| 8 | (3, qs => (), [0, 0, 0], "f(x) = 0"), |
| 9 | (2, ApplyToEach(Z, _), [1, 1], "f(x) = parity of x"), |
| 10 | (3, ApplyToEach(Z, _), [1, 1, 1], "f(x) = parity of x"), |
| 11 | (2, qs => Z(qs[0]), [1, 0], "f(x) = most significant bit of x"), |
| 12 | (3, qs => Z(qs[2]), [0, 0, 1], "f(x) = least significant bit of x"), |
| 13 | (3, qs => Z(qs[1]), [0, 1, 0], "f(x) = middle bit of x") |
| 14 | ] { |
| 15 | let actual = Kata.BernsteinVaziraniAlgorithm(n, oracle); |
| 16 | if actual != expected { |
| 17 | Message("Incorrect."); |
| 18 | Message($"The bit string for {name} for {n} bits identified as {actual} but it is {expected}."); |
| 19 | return false; |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | Message("Correct!"); |
| 24 | true |
| 25 | } |
| 26 | } |