You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

utils_tests.py 766B

12345678910111213141516171819202122232425262728
  1. from django.test import TestCase
  2. from oscar.core.utils import compose
  3. class TestComposeFunction(TestCase):
  4. def test_composes_two_single_arg_functions(self):
  5. double = lambda x: 2*x
  6. triple = lambda x: 3*x
  7. f = compose(double, triple)
  8. self.assertEqual(f(2), 2*2*3)
  9. def test_composes_three_single_arg_functions(self):
  10. double = lambda x: 2*x
  11. triple = lambda x: 3*x
  12. quadruple = lambda x: 4*x
  13. f = compose(double, triple, quadruple)
  14. self.assertEqual(f(2), 2*2*3*4)
  15. def test_composes_two_multi_arg_functions(self):
  16. double = lambda x, y: (2*x, 2*y)
  17. triple = lambda x, y: (3*x, 3*y)
  18. f = compose(double, triple)
  19. self.assertEqual(f(2, 4), (2*2*3, 4*2*3))