Browse Source

Added a test for measurment

Adam Kelly 6 years ago
parent
commit
dd7efbdc17
1 changed files with 10 additions and 0 deletions
  1. 10 0
      tests/opencl.rs

+ 10 - 0
tests/opencl.rs

@@ -1,6 +1,7 @@
 extern crate qcgpu;
 
 use qcgpu::Simulator;
+use qcgpu::gate::x;
 
 fn create_simulator(n: u8) -> Simulator {
     let sim = Simulator::new_opencl(n);
@@ -89,3 +90,12 @@ fn can_apply_cx_gate() {
         }
     }
 }
+
+#[test]
+fn can_perform_measurement() {
+    for n in 1..25 {
+        let mut sim = create_simulator(n);
+        sim.apply_all(x()).unwrap();
+        assert_eq!(sim.measure().unwrap() as i32, 2i32.pow(n as u32) - 1);
+    }
+}