microsoft/qdk
Publicmirrored fromhttps://github.com/microsoft/qdkAvailable
source/pip/src/displayable_output/tests.rs
41lines ยท modecode
| 1 | // Copyright (c) Microsoft Corporation. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | use num_bigint::BigUint; |
| 5 | use num_complex::Complex; |
| 6 | |
| 7 | use crate::displayable_output::DisplayableState; |
| 8 | |
| 9 | #[test] |
| 10 | fn 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] |
| 17 | fn 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] |
| 27 | fn 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 | |