Add tests for evaluation of repeated value in sized array expressions (#976)
This commit is contained in:
Родитель
8d305b9345
Коммит
f789b023d9
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"msbuild-sdks": {
|
||||
"Microsoft.Quantum.Sdk": "0.24.201332"
|
||||
"Microsoft.Quantum.Sdk": "0.24.203411-beta"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Quantum.Compiler" Version="0.24.201332" />
|
||||
<PackageReference Include="Microsoft.Quantum.Compiler" Version="0.24.203411-beta" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.6.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
@ -4,12 +4,12 @@
|
|||
namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits {
|
||||
open Microsoft.Quantum.Diagnostics;
|
||||
open Microsoft.Quantum.Intrinsic;
|
||||
open Microsoft.Quantum.Math;
|
||||
|
||||
operation MapF<'T, 'U>(mapper : ('T -> 'U), source : 'T[]) : 'U[] {
|
||||
mutable result = new 'U[Length(source)];
|
||||
for (i in 0 .. Length(source) - 1) {
|
||||
let m = mapper(source[i]);
|
||||
set result = result w/ i <- m;
|
||||
operation MapF<'T, 'U>(mapper : 'T -> 'U, source : 'T[]) : 'U[] {
|
||||
mutable result = [];
|
||||
for x in source {
|
||||
set result += [mapper(x)];
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -18,11 +18,10 @@ namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits {
|
|||
operation LengthTest() : Unit {
|
||||
let a1 = [One, Zero];
|
||||
let a2 = [Zero, Zero, Zero];
|
||||
|
||||
AssertEqual(2, Length(a1));
|
||||
AssertEqual(3, Length(a2));
|
||||
|
||||
let values = MapF(Length<Result>, [a1, a2]);
|
||||
let values = MapF(Length, [a1, a2]);
|
||||
AssertEqual(2, values[0]);
|
||||
AssertEqual(3, values[1]);
|
||||
}
|
||||
|
@ -77,7 +76,28 @@ namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits {
|
|||
function ArrayOfArraysShouldCopyOnUpdate() : Unit {
|
||||
mutable items = [[1], size = 2];
|
||||
set items w/= 0 <- items[0] w/ 0 <- 2;
|
||||
|
||||
AssertEqual([[2], [1]], items);
|
||||
}
|
||||
|
||||
@Test("QuantumSimulator")
|
||||
operation RepeatedValueIsEvaluatedOnceSize0() : Unit {
|
||||
RepeatedValueIsEvaluatedOnce(0);
|
||||
}
|
||||
|
||||
@Test("QuantumSimulator")
|
||||
operation RepeatedValueIsEvaluatedOnceSize1() : Unit {
|
||||
RepeatedValueIsEvaluatedOnce(1);
|
||||
}
|
||||
|
||||
@Test("QuantumSimulator")
|
||||
operation RepeatedValueIsEvaluatedOnceSize2() : Unit {
|
||||
RepeatedValueIsEvaluatedOnce(2);
|
||||
}
|
||||
|
||||
operation RepeatedValueIsEvaluatedOnce(size : Int) : Unit {
|
||||
use q = Qubit();
|
||||
let _ = [H(q), size = size];
|
||||
AssertMeasurement([PauliX], [q], Zero, "");
|
||||
Reset(q);
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче