def testApplication(self): """Test function application across states.""" self.assertEqual( superposition.superposition(2, 4), superposition.state_apply(superposition.superposition(1, 2), lambda x: x * 2)) # As everything working on states, this should also work on scalars. applied = superposition.state_apply(5, lambda x: x * 2) self.assertTrue(superposition.state_eq(10, applied))
def testApplication(self): """Test function application across states.""" self.assertEqual( superposition.superposition(2, 4), superposition.state_apply( superposition.superposition(1, 2), lambda x: x * 2)) # As everything working on states, this should also work on scalars. applied = superposition.state_apply(5, lambda x: x * 2) self.assertTrue(superposition.state_eq(10, applied))
def testStates(self): """Test that states are inspectable and comparable.""" s1 = superposition.superposition("foo", "bar") s2 = superposition.superposition("bar", "foo") s3 = superposition.superposition(1, 2) s4 = 1 s5 = superposition.superposition(1) self.assertItemsEqual(superposition.getstates(s1), superposition.getstates(s2)) self.assertTrue(superposition.state_eq(s1, s2)) self.assertFalse(superposition.state_eq(s1, s3)) # Superposition is obviously not equal to a scalar. self.assertFalse(s5 == s4) # But their states CAN be equal: self.assertTrue(superposition.state_eq(s4, s5)) self.assertTrue(superposition.state_eq(s5, s4)) # We can also compare two scalars this way (if we really have nothing # better to do). self.assertTrue(superposition.state_eq("foo", "foo"))
def assertStateEq(self, s1, s2): return self.assertTrue(superposition.state_eq(s1, s2))