microsoft/qdk
Publicmirrored fromhttps://github.com/microsoft/qdkAvailable
katas/content/oracles/classical_oracles/Verification.qs
25lines · modecode
| 1 | namespace Kata.Verification { |
| 2 | open Microsoft.Quantum.Convert; |
| 3 | |
| 4 | function IsSeven_Reference(x : Bool[]) : Bool { |
| 5 | return BoolArrayAsInt(x) == 7; |
| 6 | } |
| 7 | |
| 8 | @EntryPoint() |
| 9 | function CheckSolution() : Bool { |
| 10 | let N = 3; |
| 11 | for k in 0 .. 2^N - 1 { |
| 12 | let x = IntAsBoolArray(k, N); |
| 13 | |
| 14 | let actual = Kata.IsSeven(x); |
| 15 | let expected = IsSeven_Reference(x); |
| 16 | |
| 17 | if actual != expected { |
| 18 | Message($"Failed on test case x = {x}: got {actual}, expected {expected}"); |
| 19 | return false; |
| 20 | } |
| 21 | } |
| 22 | Message("Correct!"); |
| 23 | true |
| 24 | } |
| 25 | } |
| 26 | |