Example #1
0
    def testApplication(self):
        """Test function application across values."""
        self.assertEqual(
            repeated.repeated(2, 4),
            repeated.value_apply(repeated.repeated(1, 2), lambda x: x * 2))

        # As everything working on values, this should also work on scalars.
        applied = repeated.value_apply(5, lambda x: x * 2)
        self.assertValueEq(10, applied)
Example #2
0
    def testApplication(self):
        """Test function application across values."""
        self.assertEqual(
            repeated.repeated(2, 4),
            repeated.value_apply(
                repeated.repeated(1, 2),
                lambda x: x * 2))

        # As everything working on values, this should also work on scalars.
        applied = repeated.value_apply(5, lambda x: x * 2)
        self.assertValueEq(10, applied)
Example #3
0
    def testSuperpositions(self):
        """Superpositions can be manipulated using IRepeated."""
        s = superposition.superposition("foo", "bar")
        r = repeated.repeated("foo", "bar")

        # Comparison should work in both directions.
        self.assertValueEq(r, s)
        self.assertValueEq(s, r)

        # Application should preserve container type.
        s = superposition.superposition(1, 2)
        applied = repeated.value_apply(s, lambda x: x * 2)
        self.assertValueEq(applied, repeated.repeated(2, 4))
        self.assertIsInstance(applied, superposition.ISuperposition)