This repository was archived by the owner on Jan 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathDisplayConverterTests.cs
More file actions
87 lines (78 loc) · 2.57 KB
/
Copy pathDisplayConverterTests.cs
File metadata and controls
87 lines (78 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Quantum.IQSharp.Jupyter;
using Microsoft.Quantum.Simulation.Simulators;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
namespace Tests.IQSharp
{
internal static class DisplayExtensions
{
internal static IEnumerable<(T, string)> WhereLabelIs<T>(
this IEnumerable<(T, string)> source,
string label
) =>
source.Where(
item =>
{
var (data, currentLabel) = item;
return label == currentLabel;
}
);
}
[TestClass]
public class DisplayConverterTests
{
private readonly CommonNativeSimulator.DisplayableState testState = new CommonNativeSimulator.DisplayableState
{
QubitIds = new[] {0, 1, 2},
NQubits = 3,
Amplitudes = new Dictionary<BigInteger, System.Numerics.Complex>(Enumerable
.Range(0, 8)
.Select(idx => new KeyValuePair<BigInteger, System.Numerics.Complex>(
new BigInteger(idx), new System.Numerics.Complex(0, idx)))
)
};
[TestMethod]
public void TestBigEndianLabels()
{
var testItem = testState
.SignificantAmplitudes(
CommonNativeSimulator.BasisStateLabelingConvention.BigEndian,
false,
0
)
.WhereLabelIs("6")
.Single();
Assert.AreEqual(testItem.Item1.Imaginary, 3.0);
}
[TestMethod]
public void TestLittleEndianLabels()
{
var testItem = testState
.SignificantAmplitudes(
CommonNativeSimulator.BasisStateLabelingConvention.LittleEndian,
false,
0
)
.WhereLabelIs("6")
.Single();
Assert.AreEqual(testItem.Item1.Imaginary, 6.0);
}
[TestMethod]
public void TestBitstringLabels()
{
var testItem = testState
.SignificantAmplitudes(
CommonNativeSimulator.BasisStateLabelingConvention.Bitstring,
false,
0
)
.WhereLabelIs("011")
.Single();
Assert.AreEqual(testItem.Item1.Imaginary, 6.0);
}
}
}