|
| 1 | +use qsharp_bridge::noise::{Noise, PauliNoiseDistribution}; |
| 2 | + |
| 3 | +#[test] |
| 4 | +fn test_ideal_noise_to_distribution() { |
| 5 | + let noise = Noise::Ideal; |
| 6 | + let dist = noise.to_distribution().unwrap(); |
| 7 | + assert_eq!(dist.x, 0.0); |
| 8 | + assert_eq!(dist.y, 0.0); |
| 9 | + assert_eq!(dist.z, 0.0); |
| 10 | +} |
| 11 | + |
| 12 | +#[test] |
| 13 | +fn test_pauli_noise_to_distribution() { |
| 14 | + let pauli_dist = PauliNoiseDistribution::new(0.1, 0.2, 0.3).unwrap(); |
| 15 | + let noise = Noise::Pauli { |
| 16 | + noise: pauli_dist.clone(), |
| 17 | + }; |
| 18 | + let dist = noise.to_distribution().unwrap(); |
| 19 | + assert_eq!(dist.x, 0.1); |
| 20 | + assert_eq!(dist.y, 0.2); |
| 21 | + assert_eq!(dist.z, 0.3); |
| 22 | +} |
| 23 | + |
| 24 | +#[test] |
| 25 | +fn test_bit_flip_noise_to_distribution() { |
| 26 | + let noise = Noise::BitFlip { p: 0.1 }; |
| 27 | + let dist = noise.to_distribution().unwrap(); |
| 28 | + assert_eq!(dist.x, 0.1); |
| 29 | + assert_eq!(dist.y, 0.0); |
| 30 | + assert_eq!(dist.z, 0.0); |
| 31 | +} |
| 32 | + |
| 33 | +#[test] |
| 34 | +fn test_phase_flip_noise_to_distribution() { |
| 35 | + let noise = Noise::PhaseFlip { p: 0.2 }; |
| 36 | + let dist = noise.to_distribution().unwrap(); |
| 37 | + assert_eq!(dist.x, 0.0); |
| 38 | + assert_eq!(dist.y, 0.0); |
| 39 | + assert_eq!(dist.z, 0.2); |
| 40 | +} |
| 41 | + |
| 42 | +#[test] |
| 43 | +fn test_depolarizing_noise_to_distribution() { |
| 44 | + let noise = Noise::Depolarizing { p: 0.3 }; |
| 45 | + let dist = noise.to_distribution().unwrap(); |
| 46 | + assert!((dist.x - 0.1).abs() < 1e-9); |
| 47 | + assert!((dist.y - 0.1).abs() < 1e-9); |
| 48 | + assert!((dist.z - 0.1).abs() < 1e-9); |
| 49 | +} |
| 50 | + |
| 51 | +#[test] |
| 52 | +fn test_pauli_distribution_new_valid() { |
| 53 | + let dist = PauliNoiseDistribution::new(0.1, 0.2, 0.3); |
| 54 | + assert!(dist.is_ok()); |
| 55 | +} |
| 56 | + |
| 57 | +#[test] |
| 58 | +fn test_pauli_distribution_new_invalid_negative() { |
| 59 | + let dist = PauliNoiseDistribution::new(-0.1, 0.2, 0.3); |
| 60 | + assert!(dist.is_err()); |
| 61 | +} |
| 62 | + |
| 63 | +#[test] |
| 64 | +fn test_pauli_distribution_new_invalid_sum() { |
| 65 | + let dist = PauliNoiseDistribution::new(0.5, 0.6, 0.1); |
| 66 | + assert!(dist.is_err()); |
| 67 | +} |
0 commit comments