Exemple #1
0
  def test_composition_with_one_function(self):
    def f(x): return x

    a = compose(f)
    self.assertEqual(a(5), 5)
Exemple #2
0
  def test_numerical_composition(self):
    plus1 = lambda w: w + 1
    times2 = lambda w: w * 2

    self.assertEqual(compose(plus1, times2)(5), 11)
    self.assertEqual(compose(times2, plus1)(5), 12)
Exemple #3
0
 def test_composition(self):
   greet = lambda name: "hi: " + name
   exclaim = lambda statement: statement + "!"
   welcome = compose(exclaim, greet)
   self.assertEqual(welcome("moe"), "hi: moe!")
Exemple #4
0
  def test_composition_with_one_function(self):
    def f(x): return x

    a = functional.compose(f)
    self.assertEqual(a(5), 5)
Exemple #5
0
  def test_numerical_composition(self):
    plus1 = lambda w: w + 1
    times2 = lambda w: w * 2

    self.assertEqual(functional.compose(plus1, times2)(5), 11)
    self.assertEqual(functional.compose(times2, plus1)(5), 12)
Exemple #6
0
 def test_composition(self):
   greet = lambda name: "hi: " + name
   exclaim = lambda statement: statement + "!"
   welcome = functional.compose(exclaim, greet)
   self.assertEqual(welcome("moe"), "hi: moe!")