From 86959038abba1a46fbf0a98b5792ce6d7be1d4df Mon Sep 17 00:00:00 2001 From: Alexander Chocron Date: Thu, 15 Apr 2021 12:55:59 -0700 Subject: [PATCH] Restructure test --- .../QirDriverGenerationTests.fs | 128 ++++-------------- .../UseBoolArgWithValues.txt | 1 + .../UseBoolArrayArgWithValues.txt | 1 + .../UseDoubleArgWithValues.txt | 1 + .../UseDoubleArrayArgWithValues.txt | 1 + .../UseIntegerArgWithValues.txt | 1 + .../UseIntegerArrayArgWithValues.txt | 1 + .../UseManyArgsWithValues.json | 122 +++++++++++++++++ .../UseManyArgsWithValues.txt | 1 + .../UsePauliArgWithValues.txt | 1 + .../UsePauliArrayArgWithValues.txt | 1 + .../UseRangeArgWithValues.txt | 1 + .../UseRangeArrayArgWithValues.txt | 1 + .../UseResultArgWithValues.txt | 1 + .../UseResultArrayArgWithValues.txt | 1 + .../UseStringArgWithValues.txt | 1 + .../Tests.Compiler/Tests.Compiler.fsproj | 49 ++++++- 17 files changed, 209 insertions(+), 104 deletions(-) create mode 100644 src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseBoolArgWithValues.txt create mode 100644 src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseBoolArrayArgWithValues.txt create mode 100644 src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseDoubleArgWithValues.txt create mode 100644 src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseDoubleArrayArgWithValues.txt create mode 100644 src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseIntegerArgWithValues.txt create mode 100644 src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseIntegerArrayArgWithValues.txt create mode 100644 src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseManyArgsWithValues.json create mode 100644 src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseManyArgsWithValues.txt create mode 100644 src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UsePauliArgWithValues.txt create mode 100644 src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UsePauliArrayArgWithValues.txt create mode 100644 src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseRangeArgWithValues.txt create mode 100644 src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseRangeArrayArgWithValues.txt create mode 100644 src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseResultArgWithValues.txt create mode 100644 src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseResultArrayArgWithValues.txt create mode 100644 src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseStringArgWithValues.txt diff --git a/src/QsCompiler/Tests.Compiler/QirDriverGenerationTests.fs b/src/QsCompiler/Tests.Compiler/QirDriverGenerationTests.fs index 931ceb1afc..60abaa9e4c 100644 --- a/src/QsCompiler/Tests.Compiler/QirDriverGenerationTests.fs +++ b/src/QsCompiler/Tests.Compiler/QirDriverGenerationTests.fs @@ -7,108 +7,32 @@ open Xunit open Xunit.Abstractions open Microsoft.Quantum.QsCompiler open Microsoft.Quantum.QsCompiler.BondSchemas.EntryPoint +open System.IO +open System.Text type QirDriverGenerationTests(output: ITestOutputHelper) = - [] - member this.GenerateCommandLineArguments() = - let expectedArguments = - "--int-value 1 --integer-array 1 2 3 4 5 --double-value 0.5 --double-array 0.1 0.2 0.3 0.4 0.5 --bool-value true --bool-array true true false --pauli-value paulii --pauli-array paulix paulii pauliy pauliz --range-value 1 2 10 --range-array 1 2 10 5 5 50 10 1 20 --result-value 1 --result-array 1 0 1 1 --string-value \"a sample string\" --string-array \"String A\" \"String B\" \"StringC\"" - - // Initialize arguments array - let argList = new ResizeArray() - let numArguments = 13 - - for i = 0 to numArguments do - let arg = new Argument() - arg.Position <- i - arg.Values <- new ResizeArray() - arg.Values.Add(new ArgumentValue()) - argList.Add(arg) - argList.Item(0).Name <- "int-value" - argList.Item(0).Type <- DataType.IntegerType - argList.Item(0).Values.Item(0).Integer <- new System.Nullable(1L) - argList.Item(1).Name <- "integer-array" - argList.Item(1).Type <- DataType.ArrayType - argList.Item(1).ArrayType <- new System.Nullable(DataType.IntegerType) - let array1 = new ArrayValue() - array1.Integer <- [| 1L; 2L; 3L; 4L; 5L |] |> ResizeArray - argList.Item(1).Values.Item(0).Array <- array1 - argList.Item(2).Name <- "double-value" - argList.Item(2).Type <- DataType.DoubleType - argList.Item(2).Values.Item(0).Double <- new System.Nullable(0.5) - argList.Item(3).Name <- "double-array" - argList.Item(3).Type <- DataType.ArrayType - argList.Item(3).ArrayType <- new System.Nullable(DataType.DoubleType) - let array3 = new ArrayValue() - array3.Double <- [| 0.1; 0.2; 0.3; 0.4; 0.5 |] |> ResizeArray - argList.Item(3).Values.Item(0).Array <- array3 - argList.Item(4).Name <- "bool-value" - argList.Item(4).Type <- DataType.BoolType - argList.Item(4).Values.Item(0).Bool <- new System.Nullable(true) - argList.Item(5).Name <- "bool-array" - argList.Item(5).Type <- DataType.ArrayType - argList.Item(5).ArrayType <- new System.Nullable(DataType.BoolType) - let array5 = new ArrayValue() - array5.Bool <- [| true; true; false |] |> ResizeArray - argList.Item(5).Values.Item(0).Array <- array5 - argList.Item(6).Name <- "pauli-value" - argList.Item(6).Type <- DataType.PauliType - argList.Item(6).Values.Item(0).Pauli <- new System.Nullable(PauliValue.PauliI) - argList.Item(7).Name <- "pauli-array" - argList.Item(7).Type <- DataType.ArrayType - argList.Item(7).ArrayType <- new System.Nullable(DataType.PauliType) - let array7 = new ArrayValue() - array7.Pauli <- [| PauliValue.PauliX; PauliValue.PauliI; PauliValue.PauliY; PauliValue.PauliZ |] |> ResizeArray - argList.Item(7).Values.Item(0).Array <- array7 - argList.Item(8).Name <- "range-value" - argList.Item(8).Type <- DataType.RangeType - let range8 = new RangeValue() - range8.Start <- 1L - range8.Step <- 2L - range8.End <- 10L - argList.Item(8).Values.Item(0).Range <- range8 - argList.Item(9).Name <- "range-array" - argList.Item(9).Type <- DataType.ArrayType - argList.Item(9).ArrayType <- new System.Nullable(DataType.RangeType) - let range9_0 = new RangeValue() - range9_0.Start <- 1L - range9_0.Step <- 2L - range9_0.End <- 10L - let range9_1 = new RangeValue() - range9_1.Start <- 5L - range9_1.Step <- 5L - range9_1.End <- 50L - let range9_2 = new RangeValue() - range9_2.Start <- 10L - range9_2.Step <- 1L - range9_2.End <- 20L - let array9 = new ArrayValue() - array9.Range <- [| range9_0; range9_1; range9_2 |] |> ResizeArray - argList.Item(9).Values.Item(0).Array <- array9 - argList.Item(10).Name <- "result-value" - argList.Item(10).Type <- DataType.ResultType - argList.Item(10).Values.Item(0).Result <- new System.Nullable(ResultValue.One) - argList.Item(11).Name <- "result-array" - argList.Item(11).Type <- DataType.ArrayType - argList.Item(11).ArrayType <- new System.Nullable(DataType.ResultType) - let array11 = new ArrayValue() - array11.Result <- [| ResultValue.One; ResultValue.Zero; ResultValue.One; ResultValue.One |] |> ResizeArray - argList.Item(11).Values.Item(0).Array <- array11 - argList.Item(12).Name <- "string-value" - argList.Item(12).Type <- DataType.StringType - argList.Item(12).Values.Item(0).String <- "a sample string" - argList.Item(13).Name <- "string-array" - argList.Item(13).Type <- DataType.ArrayType - argList.Item(13).ArrayType <- new System.Nullable(DataType.StringType) - let array13 = new ArrayValue() - array13.String <- [| "String A"; "String B"; "StringC" |] |> ResizeArray - argList.Item(13).Values.Item(0).Array <- array13 - - let actualArguments = QirDriverGeneration.GenerateCommandLineArguments(argList) - Assert.Equal(expectedArguments, actualArguments) - - // Now reverse values in the argument list and ensure that the same result is obtained. - argList.Reverse() - let actualArguments = QirDriverGeneration.GenerateCommandLineArguments(argList) - Assert.Equal(expectedArguments, actualArguments) + let testCasesDirectory = Path.Combine("TestCases", "QirEntryPointTests") + + [] + [] + [] + [] + [] + [] + [] + [] + [] + [] + [] + [] + [] + [] + [] + member this.GenerateArgs(testFileName: string) = + let expectedArgs = (Path.Join(testCasesDirectory, (testFileName + ".txt")) |> File.ReadAllText).Trim() + let entryPointOperationJson = Path.Join(testCasesDirectory, (testFileName + ".json")) |> File.ReadAllText + let entryPointOperationMs = new MemoryStream(Encoding.UTF8.GetBytes(entryPointOperationJson)) + let entryPointOperation = Protocols.DeserializeFromJson(entryPointOperationMs) + let generatedArgs = QirDriverGeneration.GenerateCommandLineArguments(entryPointOperation.Arguments) + Assert.Equal(expectedArgs, generatedArgs) diff --git a/src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseBoolArgWithValues.txt b/src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseBoolArgWithValues.txt new file mode 100644 index 0000000000..bd91fe72f2 --- /dev/null +++ b/src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseBoolArgWithValues.txt @@ -0,0 +1 @@ +--BoolArg true diff --git a/src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseBoolArrayArgWithValues.txt b/src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseBoolArrayArgWithValues.txt new file mode 100644 index 0000000000..936994fb7e --- /dev/null +++ b/src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseBoolArrayArgWithValues.txt @@ -0,0 +1 @@ +--BoolArrayArg true false true diff --git a/src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseDoubleArgWithValues.txt b/src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseDoubleArgWithValues.txt new file mode 100644 index 0000000000..7b527243da --- /dev/null +++ b/src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseDoubleArgWithValues.txt @@ -0,0 +1 @@ +--DoubleArg 0.1 diff --git a/src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseDoubleArrayArgWithValues.txt b/src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseDoubleArrayArgWithValues.txt new file mode 100644 index 0000000000..e6d05c46c5 --- /dev/null +++ b/src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseDoubleArrayArgWithValues.txt @@ -0,0 +1 @@ +--DoubleArrayArg 3.14159 0.55 1024.333 -8192.667 diff --git a/src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseIntegerArgWithValues.txt b/src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseIntegerArgWithValues.txt new file mode 100644 index 0000000000..b14bba6c9e --- /dev/null +++ b/src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseIntegerArgWithValues.txt @@ -0,0 +1 @@ +--IntegerArg 11 diff --git a/src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseIntegerArrayArgWithValues.txt b/src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseIntegerArrayArgWithValues.txt new file mode 100644 index 0000000000..ef587ed0ee --- /dev/null +++ b/src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseIntegerArrayArgWithValues.txt @@ -0,0 +1 @@ +--IntegerArrayArg 999 -1 11 diff --git a/src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseManyArgsWithValues.json b/src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseManyArgsWithValues.json new file mode 100644 index 0000000000..88f8c9bbe4 --- /dev/null +++ b/src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseManyArgsWithValues.json @@ -0,0 +1,122 @@ +{ + "Name": "UseManyArgsWithValues", + "Arguments": [ + { + "Type": 1, + "Name": "intValue", + "Position": 0, + "Values": [ { "Integer": [ 42 ] } ] + }, + { + "Type": 7, + "Name": "intArray", + "Position": 1, + "ArrayType": [ 1 ], + "Values": [ { "Array": [ { "Integer": [ [ 9223372036854775807, 4, 4, 2, 3 ] ] } ] } ] + }, + { + "Type": 2, + "Name": "doubleValue", + "Position": 1, + "Values": [ { "Double": [ 3.14 ] } ] + }, + { + "Type": 7, + "Name": "doubleArray", + "Position": 2, + "ArrayType": [ 2 ], + "Values": [ { "Array": [ { "Double": [ [ 0.6, 0.4, 43.2 ] ] } ] } ] + }, + { + "Type": 0, + "Name": "boolValue", + "Position": 3, + "Values": [ { "Bool": [ true ] } ] + }, + { + "Type": 7, + "Name": "boolArray", + "Position": 4, + "ArrayType": [ 0 ], + "Values": [ { "Array": [ { "Bool": [ [ true, false, true, true, false ] ] } ] } ] + }, + { + "Type": 3, + "Name": "pauliValue", + "Position": 5, + "Values": [ { "Pauli": [ 3 ] } ] + }, + { + "Type": 7, + "Name": "pauliArray", + "Position": 6, + "ArrayType": [ 3 ], + "Values": [ { "Array": [ { "Pauli": [ [ 1, 0, 2, 2, 3 ] ] } ] } ] + }, + { + "Type": 4, + "Name": "rangeValue", + "Position": 7, + "Values": [ + { + "Range": [ + { + "Start": 3, + "Step": 12, + "End": 27 + } + ] + } + ] + }, + { + "Type": 7, + "Name": "rangeArray", + "Position": 8, + "ArrayType": [ 4 ], + "Values": [ + { + "Array": [ + { + "Range": [ + [ + { + "Start": 3, + "Step": 12, + "End": 27 + } + ] + ] + } + ] + } + ] + }, + { + "Type": 5, + "Name": "resultValue", + "Position": 9, + "Values": [ { "Result": [ 1 ] } ] + }, + { + "Type": 7, + "Name": "resultArray", + "Position": 10, + "ArrayType": [ 5 ], + "Values": [ { "Array": [ { "Result": [ [ 1, 1, 0, 1 ] ] } ] } ] + }, + { + "Type": 6, + "Name": "stringValue", + "Position": 11, + "Values": [ { "String": [ "string value" ] } ] + }, + { + "Type": 7, + "Name": "stringArray", + "Position": 12, + "ArrayType": [ 6 ], + "Values": [ { "Array": [ { "String": [ [ " String A", "String B", "String C" ] ] } ] } ] + } + ] +} diff --git a/src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseManyArgsWithValues.txt b/src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseManyArgsWithValues.txt new file mode 100644 index 0000000000..ff8c4b9c08 --- /dev/null +++ b/src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseManyArgsWithValues.txt @@ -0,0 +1 @@ +--intValue 42 --intArray 9223372036854775807 4 4 2 3 --doubleValue 3.14 --doubleArray 0.6 0.4 43.2 --boolValue true --boolArray true false true true false --pauliValue pauliz --pauliArray paulix paulii pauliy pauliy pauliz --rangeValue 3 12 27 --rangeArray 3 12 27 --resultValue 1 --resultArray 1 1 0 1 --stringValue "string value" --stringArray " String A" "String B" "String C" diff --git a/src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UsePauliArgWithValues.txt b/src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UsePauliArgWithValues.txt new file mode 100644 index 0000000000..820ad6032f --- /dev/null +++ b/src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UsePauliArgWithValues.txt @@ -0,0 +1 @@ +--PauliArg paulix diff --git a/src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UsePauliArrayArgWithValues.txt b/src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UsePauliArrayArgWithValues.txt new file mode 100644 index 0000000000..2ce5058433 --- /dev/null +++ b/src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UsePauliArrayArgWithValues.txt @@ -0,0 +1 @@ +--PauliArrayArg paulix pauliy pauliz diff --git a/src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseRangeArgWithValues.txt b/src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseRangeArgWithValues.txt new file mode 100644 index 0000000000..3d90ff2ded --- /dev/null +++ b/src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseRangeArgWithValues.txt @@ -0,0 +1 @@ +--RangeArg 1 1 10 diff --git a/src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseRangeArrayArgWithValues.txt b/src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseRangeArrayArgWithValues.txt new file mode 100644 index 0000000000..5ebe7a232a --- /dev/null +++ b/src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseRangeArrayArgWithValues.txt @@ -0,0 +1 @@ +--RangeArrayArg 1 1 10 10 5 100 diff --git a/src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseResultArgWithValues.txt b/src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseResultArgWithValues.txt new file mode 100644 index 0000000000..22446419a5 --- /dev/null +++ b/src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseResultArgWithValues.txt @@ -0,0 +1 @@ +--ResultArg 0 diff --git a/src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseResultArrayArgWithValues.txt b/src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseResultArrayArgWithValues.txt new file mode 100644 index 0000000000..387bcf74ea --- /dev/null +++ b/src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseResultArrayArgWithValues.txt @@ -0,0 +1 @@ +--ResultArrayArg 0 1 diff --git a/src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseStringArgWithValues.txt b/src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseStringArgWithValues.txt new file mode 100644 index 0000000000..6c9b47112d --- /dev/null +++ b/src/QsCompiler/Tests.Compiler/TestCases/QirEntryPointTests/UseStringArgWithValues.txt @@ -0,0 +1 @@ +--StringArg "StringA" diff --git a/src/QsCompiler/Tests.Compiler/Tests.Compiler.fsproj b/src/QsCompiler/Tests.Compiler/Tests.Compiler.fsproj index 9d68311225..31f6199715 100644 --- a/src/QsCompiler/Tests.Compiler/Tests.Compiler.fsproj +++ b/src/QsCompiler/Tests.Compiler/Tests.Compiler.fsproj @@ -24,6 +24,48 @@ + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + Always @@ -48,10 +90,10 @@ Always - + Always - + Always @@ -105,6 +147,9 @@ Always + + Always + Always