microsoft/qdk
Publicmirrored fromhttps://github.com/microsoft/qdkAvailable
katas/content/grovers_search/prefix_oracle/Verification.qs
32lines · modecode
| 1 | namespace Kata.Verification { |
| 2 | open Microsoft.Quantum.Katas; |
| 3 | |
| 4 | function F_StartsWith(args : Bool[], p : Bool[]) : Bool { |
| 5 | for i in 0 .. Length(p) - 1 { |
| 6 | if p[i] != args[i] { |
| 7 | return false; |
| 8 | } |
| 9 | } |
| 10 | return true; |
| 11 | } |
| 12 | |
| 13 | @EntryPoint() |
| 14 | operation CheckSolution() : Bool { |
| 15 | for (n, p) in [ |
| 16 | (2, []), |
| 17 | (2, [true]), |
| 18 | (2, [true, false]), |
| 19 | (3, [false, true]), |
| 20 | (4, [true, true, false]), |
| 21 | (5, [false]) |
| 22 | ] { |
| 23 | if not CheckOracleImplementsFunction(n, Kata.Oracle_StartsWith(_, _, p), F_StartsWith(_, p)) { |
| 24 | Message($"Test failed for N = {n}, p = {p}"); |
| 25 | return false; |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | Message("Correct!"); |
| 30 | true |
| 31 | } |
| 32 | } |
| 33 | |