# Path: css2video/interpolators/value.py
# def interpolate_value(from_value, to_value, fraction, type='linear'):
#     '''Interpolate a value between the given two values
#     from_value - initial value
#     to_value   - final value
#     fraction   - fraction position from the initial value
#     type       - type of interpolation function'''
# 
#     if from_value.get('type') != to_value.get('type'):
#         raise ValueTypeMismatch()
# 
#     value_type = from_value.get('type')
#     interpolator_fn = Interpolators.get_timing_function(name=type)
# 
#     required_value = copy.deepcopy(from_value)
# 
#     if value_type in ['number', 'length', 'percentage', 'time']:
#         # Interpolate the value
#         required_value['value'] = interpolator_fn(
#             from_value['value'], to_value['value'], fraction)
# 
#     if value_type == 'color':
#         # Interpolate RGBA values
#         required_value['red'] = interpolator_fn(
#             from_value['red'], to_value['red'], fraction)
#         required_value['green'] = interpolator_fn(
#             from_value['green'], to_value['green'], fraction)
#         required_value['blue'] = interpolator_fn(
#             from_value['blue'], to_value['blue'], fraction)
#         required_value['alpha'] = interpolator_fn(
#             from_value['alpha'], to_value['alpha'], fraction)
# 
#     if value_type in ['text', 'url']:
#         # Text values cannot be interpolated.
#         # When the fraction is 1, return the final value
#         if fraction == 1:
#             required_value['value'] = to_value['value']
# 
#     if value_type == 'function':
#         # Check the argument count of both the values and interpolate each of
#         # the value
#         from_args = from_value.get('args', [])
#         to_args = to_value.get('args', [])
#         if len(from_args) != len(to_args):
#             raise FunctionValueArgCountMismatch()
#         args = []
#         for arg1, arg2 in zip(from_args, to_args):
#             args.append(interpolate_value(arg1, arg2, fraction, type))
#         required_value['args'] = args
# 
#     if value_type == 'array':
#         # Check the length of the array and interpolate each of the array items
#         from_values = from_value.get('values', [])
#         to_values = to_value.get('values', [])
#         if len(from_values) != len(to_values):
#             raise ArrayLengthMismatch()
#         values = []
#         for value1, value2 in zip(from_values, to_values):
#             values.append(interpolate_value(value1, value2, fraction, type))
#         required_value['values'] = values
# 
#     return required_value
# 
# Path: tests/utils.py
# def isEqual(value1, value2):
#     '''Compare any two values and returns true if they are equal'''
#     if isinstance(value1, list) and isinstance(value2, list):
#         is_equal = True
#         for v1, v2 in zip(value1, value2):
#             is_equal = is_equal and isEqual(v1, v2)
#             if not is_equal:
#                 break
#         return is_equal
# 
#     if isinstance(value1, dict) and isinstance(value2, dict):
#         is_equal = len(value1.keys()) == len(value2.keys())
#         for key1 in value1:
#             is_equal = is_equal and (key1 in value2)
#             if not is_equal:
#                 break
#             is_equal = is_equal and isEqual(value1[key1], value2[key1])
#             if not is_equal:
#                 break
#         return is_equal
#     return value1 == value2


import unittest
from css2video.interpolators import interpolate_value
from .utils import isEqual
            (
                {
                    'type': 'function',
                    'name': 'translateX',
                    'args': [
                        {'type': 'length', 'value': 100, 'unit': 'px'},
                        {'type': 'number', 'value': 0},
                    ]
                },
                {
                    'type': 'function',
                    'name': 'translateX',
                    'args': [
                        {'type': 'length', 'value': 0, 'unit': 'px'},
                        {'type': 'number', 'value': 100},
                    ]
                },
                0.5,
                'linear',
                {
                    'type': 'function',
                    'name': 'translateX',
                    'args': [
                        {'type': 'length', 'value': 50, 'unit': 'px'},
                        {'type': 'number', 'value': 50},
                    ]
                }
            )
        ]
        for v1, v2, f, t, expected_value in data:

# Path: css2video/interpolators/value.py
# def interpolate_value(from_value, to_value, fraction, type='linear'):
#     '''Interpolate a value between the given two values
#     from_value - initial value
#     to_value   - final value
#     fraction   - fraction position from the initial value
#     type       - type of interpolation function'''
# 
#     if from_value.get('type') != to_value.get('type'):
#         raise ValueTypeMismatch()
# 
#     value_type = from_value.get('type')
#     interpolator_fn = Interpolators.get_timing_function(name=type)
# 
#     required_value = copy.deepcopy(from_value)
# 
#     if value_type in ['number', 'length', 'percentage', 'time']:
#         # Interpolate the value
#         required_value['value'] = interpolator_fn(
#             from_value['value'], to_value['value'], fraction)
# 
#     if value_type == 'color':
#         # Interpolate RGBA values
#         required_value['red'] = interpolator_fn(
#             from_value['red'], to_value['red'], fraction)
#         required_value['green'] = interpolator_fn(
#             from_value['green'], to_value['green'], fraction)
#         required_value['blue'] = interpolator_fn(
#             from_value['blue'], to_value['blue'], fraction)
#         required_value['alpha'] = interpolator_fn(
#             from_value['alpha'], to_value['alpha'], fraction)
# 
#     if value_type in ['text', 'url']:
#         # Text values cannot be interpolated.
#         # When the fraction is 1, return the final value
#         if fraction == 1:
#             required_value['value'] = to_value['value']
# 
#     if value_type == 'function':
#         # Check the argument count of both the values and interpolate each of
#         # the value
#         from_args = from_value.get('args', [])
#         to_args = to_value.get('args', [])
#         if len(from_args) != len(to_args):
#             raise FunctionValueArgCountMismatch()
#         args = []
#         for arg1, arg2 in zip(from_args, to_args):
#             args.append(interpolate_value(arg1, arg2, fraction, type))
#         required_value['args'] = args
# 
#     if value_type == 'array':
#         # Check the length of the array and interpolate each of the array items
#         from_values = from_value.get('values', [])
#         to_values = to_value.get('values', [])
#         if len(from_values) != len(to_values):
#             raise ArrayLengthMismatch()
#         values = []
#         for value1, value2 in zip(from_values, to_values):
#             values.append(interpolate_value(value1, value2, fraction, type))
#         required_value['values'] = values
# 
#     return required_value
# 
# Path: tests/utils.py
# def isEqual(value1, value2):
#     '''Compare any two values and returns true if they are equal'''
#     if isinstance(value1, list) and isinstance(value2, list):
#         is_equal = True
#         for v1, v2 in zip(value1, value2):
#             is_equal = is_equal and isEqual(v1, v2)
#             if not is_equal:
#                 break
#         return is_equal
# 
#     if isinstance(value1, dict) and isinstance(value2, dict):
#         is_equal = len(value1.keys()) == len(value2.keys())
#         for key1 in value1:
#             is_equal = is_equal and (key1 in value2)
#             if not is_equal:
#                 break
#             is_equal = is_equal and isEqual(value1[key1], value2[key1])
#             if not is_equal:
#                 break
#         return is_equal
#     return value1 == value2


# Path: tests/test_interpolators.py
import unittest
from css2video.interpolators import interpolate_value
from .utils import isEqual

            (
                {
                    'type': 'function',
                    'name': 'translateX',
                    'args': [
                        {'type': 'length', 'value': 100, 'unit': 'px'},
                        {'type': 'number', 'value': 0},
                    ]
                },
                {
                    'type': 'function',
                    'name': 'translateX',
                    'args': [
                        {'type': 'length', 'value': 0, 'unit': 'px'},
                        {'type': 'number', 'value': 100},
                    ]
                },
                0.5,
                'linear',
                {
                    'type': 'function',
                    'name': 'translateX',
                    'args': [
                        {'type': 'length', 'value': 50, 'unit': 'px'},
                        {'type': 'number', 'value': 50},
                    ]
                }
            )
        ]
        for v1, v2, f, t, expected_value in data:

            v = interpolate_value(v1, v2, f, t)