Beispiel #1
0
    def test_associativity_law(self):
        a = ExactlyOne(1)

        def f(x):
            return x + 1

        def g(x):
            return x * 2

        self.assertEqual(a.map(f).map(g), a.map(f | andThen | g))
Beispiel #2
0
 def test_replaceWithA(self):
     self.assertEqual(
         ExactlyOne(1).replaceWithA(ExactlyOne(2)).value,
         ExactlyOne(2).value)
Beispiel #3
0
    def test_fold(self):
        def add(x, y):
            return x + y

        self.assertEqual(ExactlyOne(2).fold(add, 1), 3)
Beispiel #4
0
 def test_contains(self):
     self.assertEqual(ExactlyOne(0).contains(1), False)
     self.assertEqual(ExactlyOne(1).contains(1), True)
Beispiel #5
0
 def test_isEmpty(self):
     self.assertFalse(ExactlyOne(0).isEmpty())
Beispiel #6
0
 def test_length(self):
     self.assertEqual(ExactlyOne(0).length(), 1)
Beispiel #7
0
 def test_identity_law(self):
     a = ExactlyOne(1)
     self.assertEqual(identity(a), a.map(identity))
Beispiel #8
0
 def test_void(self):
     assert ExactlyOne(1).void() == ExactlyOne(())
Beispiel #9
0
 def test_replaceWith(self):
     assert ExactlyOne(1).replaceWith(2) == ExactlyOne(2)