예제 #1
0
 def test_double_fun_call(self):
     with self.assertRaises(TypeError):
         curry_explicit(fun_without_args, 0)()()
예제 #2
0
 def test_number_of_arguments_is_greater_than_arity_indefinite_number_of_args(self):
     with self.assertRaises(TypeError):
         curry_explicit(fun_with_indefinite_number_of_args, 2)(1)(2)(3)
예제 #3
0
 def test_number_of_arguments_is_greater_than_arity_fun_without_args(self):
     with self.assertRaises(TypeError):
         curry_explicit(fun_without_args, 0)(1)
예제 #4
0
 def test_intermediate_function(self):
     curried_fun = curry_explicit(fun_with_indefinite_number_of_args, 4)
     intermediate_function = curried_fun(1)(2)
     return self.assertEqual(intermediate_function(3)(4), fun_with_indefinite_number_of_args(1, 2, 3, 4))
예제 #5
0
 def test_negative_arity(self):
     with self.assertRaises(ValueError):
         curry_explicit(fun_with_several_args, -1)("a")
예제 #6
0
 def test_indefinite_number_of_args(self):
     curried_fun = curry_explicit(fun_with_indefinite_number_of_args, 5)
     return self.assertEqual(curried_fun(2)(3)(4)(5)(6), fun_with_indefinite_number_of_args(2, 3, 4, 5, 6))
예제 #7
0
 def test_several_arguments(self):
     curried_fun = curry_explicit(fun_with_several_args, 3)
     return self.assertEqual(curried_fun("some")("value")("here"), fun_with_several_args("some", "value", "here"))
예제 #8
0
 def test_one_arg(self):
     return self.assertEqual(curry_explicit(fun_with_one_arg, 1)(100), fun_with_one_arg(100))
예제 #9
0
 def test_without_arguments(self):
     return self.assertEqual(curry_explicit(fun_without_args, 0)(), fun_without_args())
예제 #10
0
import unittest

from homeworks.homework2.task1.uncurry import uncurry_explicit
from homeworks.homework2.task1.curry import curry_explicit

from tests.homework2.task1.test_curry import (
    fun_without_args,
    fun_with_one_arg,
    fun_with_several_args,
    fun_with_indefinite_number_of_args,
)

curried_fun_without_args = curry_explicit(fun_without_args, 0)
curried_fun_with_one_arg = curry_explicit(fun_with_one_arg, 1)
curried_fun_with_several_args = curry_explicit(fun_with_several_args, 3)
curried_fun_with_indefinite_number_of_args = curry_explicit(
    fun_with_indefinite_number_of_args, 5)


class UncurryTestCase(unittest.TestCase):
    def test_without_args(self):
        return self.assertEqual(
            uncurry_explicit(curried_fun_without_args, 0)(),
            fun_without_args())

    def test_one_arg(self):
        return self.assertEqual(
            uncurry_explicit(curried_fun_with_one_arg, 1)(15),
            fun_with_one_arg(15))

    def test_several_args(self):