microsoft/qdk

Public

mirrored fromhttps://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
iadavis/pipeline-issue-debugging

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

source/pip/src/displayable_output/tests.rs

41lines ยท modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4use num_bigint::BigUint;
5use num_complex::Complex;
6
7use crate::displayable_output::DisplayableState;
8
9#[test]
10fn display_neg_zero() {
11 let s = DisplayableState(vec![(BigUint::default(), Complex::new(-0.0, -0.0))], 1);
12 // -0 should be displayed as 0.0000 without a minus sign
13 assert_eq!("STATE:\n|0โŸฉ: 0.0000+0.0000๐‘–", s.to_plain());
14}
15
16#[test]
17fn display_rounds_to_neg_zero() {
18 let s = DisplayableState(
19 vec![(BigUint::default(), Complex::new(-0.00001, -0.00001))],
20 1,
21 );
22 // -0.00001 should be displayed as 0.0000 without a minus sign
23 assert_eq!("STATE:\n|0โŸฉ: 0.0000+0.0000๐‘–", s.to_plain());
24}
25
26#[test]
27fn display_preserves_order() {
28 let s = DisplayableState(
29 vec![
30 (BigUint::from(0_u64), Complex::new(0.0, 0.0)),
31 (BigUint::from(1_u64), Complex::new(0.0, 1.0)),
32 (BigUint::from(2_u64), Complex::new(1.0, 0.0)),
33 (BigUint::from(3_u64), Complex::new(1.0, 1.0)),
34 ],
35 2,
36 );
37 assert_eq!(
38 "STATE:\n|00โŸฉ: 0.0000+0.0000๐‘–\n|01โŸฉ: 0.0000+1.0000๐‘–\n|10โŸฉ: 1.0000+0.0000๐‘–\n|11โŸฉ: 1.0000+1.0000๐‘–",
39 s.to_plain()
40 );
41}
42