Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 47 additions & 2 deletions src/Simulation/CsharpGeneration.Tests/Circuits/EntryPointTests.qs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ namespace Microsoft.Quantum.CsharpGeneration.Testing.EntryPoint {

// ---

namespace Microsoft.Quantum.CsharpGeneration.Testing.EntryPoint {
@EntryPoint()
operation AcceptUnit(u : Unit) : Unit {
return u;
}
}

// ---

namespace Microsoft.Quantum.CsharpGeneration.Testing.EntryPoint {
@EntryPoint()
operation AcceptStringArray(xs : String[]) : String[] {
Expand All @@ -117,8 +126,44 @@ namespace Microsoft.Quantum.CsharpGeneration.Testing.EntryPoint {

namespace Microsoft.Quantum.CsharpGeneration.Testing.EntryPoint {
@EntryPoint()
operation AcceptUnit(u : Unit) : Unit {
return u;
operation AcceptBigIntArray(bs : BigInt[]) : BigInt[] {
return bs;
}
}

// ---

namespace Microsoft.Quantum.CsharpGeneration.Testing.EntryPoint {
@EntryPoint()
operation AcceptPauliArray(ps : Pauli[]) : Pauli[] {
return ps;
}
}

// ---

namespace Microsoft.Quantum.CsharpGeneration.Testing.EntryPoint {
@EntryPoint()
operation AcceptRangeArray(rs : Range[]) : Range[] {
return rs;
}
}

// ---

namespace Microsoft.Quantum.CsharpGeneration.Testing.EntryPoint {
@EntryPoint()
operation AcceptResultArray(rs : Result[]) : Result[] {
return rs;
}
}

// ---

namespace Microsoft.Quantum.CsharpGeneration.Testing.EntryPoint {
@EntryPoint()
operation AcceptUnitArray(us : Unit[]) : Unit[] {
return us;
}
}

Expand Down
90 changes: 71 additions & 19 deletions src/Simulation/CsharpGeneration.Tests/EntryPointTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ let ``Accepts Pauli`` () =
given ["-p"; "PauliX"] |> yields "PauliX"
given ["-p"; "PauliY"] |> yields "PauliY"
given ["-p"; "PauliZ"] |> yields "PauliZ"
given ["-p"; "paulii"] |> yields "PauliI"
given ["-p"; "paulix"] |> yields "PauliX"
given ["-p"; "pauliy"] |> yields "PauliY"
given ["-p"; "pauliz"] |> yields "PauliZ"
given ["-p"; "PauliW"] |> fails

[<Fact>]
Expand Down Expand Up @@ -266,39 +270,87 @@ let ``Accepts String`` () =
given ["-s"; "Hello, World!"] |> yields "Hello, World!"

[<Fact>]
let ``Accepts String array`` () =
let ``Accepts Unit`` () =
let given = test 12
given ["-u"; "()"] |> yields ""
given ["-u"; "42"] |> fails

[<Fact>]
let ``Accepts String array`` () =
let given = test 13
given ["--xs"; "foo"] |> yields "[foo]"
given ["--xs"; "foo"; "bar"] |> yields "[foo,bar]"
given ["--xs"; "foo bar"; "baz"] |> yields "[foo bar,baz]"
given ["--xs"; "foo"; "bar"; "baz"] |> yields "[foo,bar,baz]"
given ["--xs"] |> fails

[<Fact>]
let ``Accepts Unit`` () =
let ``Accepts BigInt array`` () =
let given = test 14
given ["--bs"; "9223372036854775808"] |> yields "[9223372036854775808]"
given ["--bs"; "1"; "2"; "9223372036854775808"] |> yields "[1,2,9223372036854775808]"
given ["--bs"; "1"; "2"; "4.2"] |> fails

[<Fact>]
let ``Accepts Pauli array`` () =
let given = test 15
given ["--ps"; "PauliI"] |> yields "[PauliI]"
given ["--ps"; "PauliZ"; "PauliX"] |> yields "[PauliZ,PauliX]"
given ["--ps"; "PauliY"; "PauliY"; "PauliY"] |> yields "[PauliY,PauliY,PauliY]"
given ["--ps"; "PauliY"; "PauliZ"; "PauliW"] |> fails

[<Fact>]
let ``Accepts Range array`` () =
let given = test 16
given ["--rs"; "1..10"] |> yields "[1..1..10]"
given ["--rs"; "1..10"; "2..4..20"] |> yields "[1..1..10,2..4..20]"
given ["--rs"; "1 ..10"; "2 ..4 ..20"] |> yields "[1..1..10,2..4..20]"
given ["--rs"; "1 .. 10"; "2 .. 4 .. 20"] |> yields "[1..1..10,2..4..20]"
given ["--rs"; "1 .. 1o"; "2 .. 4 .. 20"] |> fails

[<Fact>]
let ``Accepts Result array`` () =
let given = test 17
given ["--rs"; "One"] |> yields "[One]"
given ["--rs"; "One"; "Zero"] |> yields "[One,Zero]"
given ["--rs"; "Zero"; "One"; "Two"] |> fails

[<Fact>]
let ``Accepts Unit array`` () =
let given = test 18
given ["--us"; "()"] |> yields "[()]"
given ["--us"; "()"; "()"] |> yields "[(),()]"
given ["--us"; "()"; "()"; "()"] |> yields "[(),(),()]"
given ["--us"; "()"; "unit"; "()"] |> fails

[<Fact>]
let ``Supports repeat-name array syntax`` () =
let given = test 13
given ["-u"; "()"] |> yields ""
given ["-u"; "42"] |> fails
given ["--xs"; "Hello"; "--xs"; "World"] |> yields "[Hello,World]"
given ["--xs"; "foo"; "bar"; "--xs"; "baz"] |> yields "[foo,bar,baz]"
given ["--xs"; "foo"; "--xs"; "bar"; "--xs"; "baz"] |> yields "[foo,bar,baz]"
given ["--xs"; "foo bar"; "--xs"; "baz"] |> yields "[foo bar,baz]"


// Multiple Options

[<Fact>]
let ``Accepts two options`` () =
let given = test 14
let given = test 19
given ["-n"; "7"; "-b"; "true"] |> yields "7 True"
given ["-b"; "true"; "-n"; "7"] |> yields "7 True"

[<Fact>]
let ``Accepts three options`` () =
let given = test 15
let given = test 20
given ["-n"; "7"; "-b"; "true"; "--xs"; "foo"] |> yields "7 True [foo]"
given ["--xs"; "foo"; "-n"; "7"; "-b"; "true"] |> yields "7 True [foo]"
given ["-n"; "7"; "--xs"; "foo"; "-b"; "true"] |> yields "7 True [foo]"
given ["-b"; "true"; "-n"; "7"; "--xs"; "foo"] |> yields "7 True [foo]"

[<Fact>]
let ``Requires all options`` () =
let given = test 15
let given = test 20
given ["-b"; "true"; "--xs"; "foo"] |> fails
given ["-n"; "7"; "--xs"; "foo"] |> fails
given ["-n"; "7"; "-b"; "true"] |> fails
Expand All @@ -312,13 +364,13 @@ let ``Requires all options`` () =

[<Fact>]
let ``Uses kebab-case`` () =
let given = test 16
let given = test 21
given ["--camel-case-name"; "foo"] |> yields "foo"
given ["--camelCaseName"; "foo"] |> fails

[<Fact>]
let ``Uses single-dash short names`` () =
let given = test 17
let given = test 22
given ["-x"; "foo"] |> yields "foo"
given ["--x"; "foo"] |> fails

Expand All @@ -327,22 +379,22 @@ let ``Uses single-dash short names`` () =

[<Fact>]
let ``Shadows --simulator`` () =
let given = test 18
let given = test 23
given ["--simulator"; "foo"] |> yields "foo"
given ["--simulator"; AssemblyConstants.ResourcesEstimator] |> yields AssemblyConstants.ResourcesEstimator
given ["-s"; AssemblyConstants.ResourcesEstimator; "--simulator"; "foo"] |> fails
given ["-s"; "foo"] |> fails

[<Fact>]
let ``Shadows -s`` () =
let given = test 19
let given = test 24
given ["-s"; "foo"] |> yields "foo"
given ["--simulator"; AssemblyConstants.ToffoliSimulator; "-s"; "foo"] |> yields "foo"
given ["--simulator"; "bar"; "-s"; "foo"] |> fails

[<Fact>]
let ``Shadows --version`` () =
let given = test 20
let given = test 25
given ["--version"; "foo"] |> yields "foo"


Expand All @@ -361,38 +413,38 @@ BorrowedWidth 0"

[<Fact>]
let ``Supports QuantumSimulator`` () =
let given = test 21
let given = test 26
given ["--simulator"; AssemblyConstants.QuantumSimulator; "--use-h"; "false"] |> yields "Hello, World!"
given ["--simulator"; AssemblyConstants.QuantumSimulator; "--use-h"; "true"] |> yields "Hello, World!"

[<Fact>]
let ``Supports ToffoliSimulator`` () =
let given = test 21
let given = test 26
given ["--simulator"; AssemblyConstants.ToffoliSimulator; "--use-h"; "false"] |> yields "Hello, World!"
given ["--simulator"; AssemblyConstants.ToffoliSimulator; "--use-h"; "true"] |> fails

[<Fact>]
let ``Supports ResourcesEstimator`` () =
let given = test 21
let given = test 26
given ["--simulator"; AssemblyConstants.ResourcesEstimator; "--use-h"; "false"] |> yields resourceSummary
given ["--simulator"; AssemblyConstants.ResourcesEstimator; "--use-h"; "true"] |> yields resourceSummary

[<Fact>]
let ``Rejects unknown simulator`` () =
let given = test 21
let given = test 26
given ["--simulator"; "FooSimulator"; "--use-h"; "false"] |> fails

[<Fact>]
let ``Supports default standard simulator`` () =
let given = testWith 21 AssemblyConstants.ResourcesEstimator
let given = testWith 26 AssemblyConstants.ResourcesEstimator
given ["--use-h"; "false"] |> yields resourceSummary
given ["--simulator"; AssemblyConstants.QuantumSimulator; "--use-h"; "false"] |> yields "Hello, World!"

[<Fact>]
let ``Supports default custom simulator`` () =
// This is not really a "custom" simulator, but the driver does not recognize the fully-qualified name of the
// standard simulators, so it is treated as one.
let given = testWith 21 typeof<ToffoliSimulator>.FullName
let given = testWith 26 typeof<ToffoliSimulator>.FullName
given ["--use-h"; "false"] |> yields "Hello, World!"
given ["--use-h"; "true"] |> fails
given ["--simulator"; typeof<ToffoliSimulator>.FullName; "--use-h"; "false"] |> yields "Hello, World!"
Expand Down Expand Up @@ -425,7 +477,7 @@ Options:
Commands:
simulate (default) Run the program using a local simulator."

let given = test 22
let given = test 27
given ["--help"] |> yields message
given ["-h"] |> yields message
given ["-?"] |> yields message
Loading