# Path: p5/pmath/utils.py
# def constrain(amount, low, high):
#     """Constrain the given value in the specified range.
# 
#     Examples ::
# 
#         >>> constrain(8, 1, 5)
#         5
# 
#         >>> constrain(5, 1, 5)
#         5
# 
#         >>> constrain(3, 1, 5)
#         3
# 
#         >>> constrain(1, 1, 5)
#         1
# 
#         >>> constrain(-3, 1, 5)
#         1
# 
#     :param amount: The the value to be contrained.
# 
#     :param low: The lower constain.
# 
#     :param high: The upper constain.
# 
#     """
#     if amount < low:
#         return low
#     elif amount > high:
#         return high
#     else:
#         return amount
# 
# def lerp(start, stop, amount):
#     """Linearly interpolate the start value to the stop value.
# 
#     Examples ::
# 
#         >>> lerp(0, 10, 0.0)
#         0.0
# 
#         >>> lerp(0, 10, 0.5)
#         5.0
# 
#         >>> lerp(0, 10, 0.8)
#         8.0
# 
#         >>> lerp(0, 10, 1.0)
#         10.0
# 
#     :param start: The start value
# 
#     :param stop: The stop value
# 
#     :param amount: The amount by which to interpolate. (:math:`0 \leq
#         amount \leq 1`).
#     :type amount: float
# 
#     """
#     return start + amount * (stop - start)
# 
# def remap(value, source_range, target_range):
#     """Remap a value from the source range to the target range.
# 
#     Examples ::
# 
#          >>> remap(50, (0, 100), (0, 10))
#          5.0
# 
#          >>> remap(5, (0, 10), (0, 100))
#          50.0
# 
#          >>> remap(5, (0, 10), (10, 20))
#          15.0
# 
#          >>> remap(15, (10, 20), (0, 10))
#          5.0
# 
#     :param value: The value to be remapped.
# 
#     :param source_range: The source range for :code:`value`
#     :type source_range: tuple
# 
#     :param target_range: The target range for :code:`value`
#     :type target_range: tuple
# 
#     """
#     s0, s1 = source_range
#     t0, t1 = target_range
#     S = s1 - s0
#     T = t1 - t0
#     return t0 + ((value - s0) / S) * T
# 
# def normalize(value, low, high):
#     """Normalize the given value to the specified range.
# 
#     Examples ::
# 
#         >>> normalize(10, 0, 100)
#         0.1
# 
#         >>> normalize(0.3, 0, 1)
#         0.3
# 
#         >>> normalize(100, 0, 100)
#         1.0
# 
#         >>> normalize(1, 1, 15)
#         0.0
# 
#     :param value:
#     :type value: float
# 
#     :param low: The lower bound for the range.
#     :type low: float
# 
#     :param high: The upper bound for the range.
#     :type high: float
#     """
#     return remap(value, (low, high), (0, 1))
# 
# def magnitude(x, y, z=0):
#     """Return the magnitude of the given vector.
# 
#     Examples ::
# 
#         >>> magnitude(3, 4)
#         5.0
# 
#         >>> magnitude(2, 3, 6)
#         7.0
# 
#         >>> magnitude(0, 0, 0)
#         0.0
# 
#     :param x: The x-component of the vector.
#     :type x: float
# 
#     :param y: The y-component of the vector.
#     :type y: float
# 
#     :param z: The z-component of the vector (defaults to 0).
#     :type z: float
# 
#     :returns: The magnitude of the vector.
#     :rtype: float
# 
#     """
#     return np.sqrt(np.sum(np.array([x, y, z]) ** 2))
# 
# def distance(point_1, point_2):
#     """Return the distance between two points.
# 
#     Examples ::
# 
#         >>> distance((0, 0, 0), (2, 3, 6))
#         7.0
# 
#         >>> distance((2, 3, 6), (2, 3, 6))
#         0.0
# 
#         >>> distance((6, 6, 6), (2, 3, 6))
#         5.0
# 
#     :param point_1:
#     :type point_1: tuple
# 
#     :param point_2:
#     :type point_2: tuple
# 
#     :returns: The distance between two points
#     :rtype: float
# 
#     """
#     p1 = np.array(_sanitize(point_1))
#     p2 = np.array(_sanitize(point_2))
#     return np.sqrt(np.sum((p1 - p2) ** 2))
# 
# def sq(number):
#     """Square a number.
# 
#     Examples ::
# 
#         >>> square(-25)
#         625
# 
#         >>> square(0)
#         0
# 
#         >>> square(13)
#         169
# 
# 
#     :param number: The number to be squared.
#     :type number: float
# 
#     :returns: The square of the number.
#     :rtype: float
# 
#     """
#     return number ** 2


import unittest
from p5.pmath.utils import (
    constrain,
    lerp,
    remap,
    normalize,
    magnitude,
    distance,
    sq)



class TestUtils(unittest.TestCase):

    def test_constrain(self):
        self.assertEqual(constrain(5, 0, 10), 5)

# Path: p5/pmath/utils.py
# def constrain(amount, low, high):
#     """Constrain the given value in the specified range.
# 
#     Examples ::
# 
#         >>> constrain(8, 1, 5)
#         5
# 
#         >>> constrain(5, 1, 5)
#         5
# 
#         >>> constrain(3, 1, 5)
#         3
# 
#         >>> constrain(1, 1, 5)
#         1
# 
#         >>> constrain(-3, 1, 5)
#         1
# 
#     :param amount: The the value to be contrained.
# 
#     :param low: The lower constain.
# 
#     :param high: The upper constain.
# 
#     """
#     if amount < low:
#         return low
#     elif amount > high:
#         return high
#     else:
#         return amount
# 
# def lerp(start, stop, amount):
#     """Linearly interpolate the start value to the stop value.
# 
#     Examples ::
# 
#         >>> lerp(0, 10, 0.0)
#         0.0
# 
#         >>> lerp(0, 10, 0.5)
#         5.0
# 
#         >>> lerp(0, 10, 0.8)
#         8.0
# 
#         >>> lerp(0, 10, 1.0)
#         10.0
# 
#     :param start: The start value
# 
#     :param stop: The stop value
# 
#     :param amount: The amount by which to interpolate. (:math:`0 \leq
#         amount \leq 1`).
#     :type amount: float
# 
#     """
#     return start + amount * (stop - start)
# 
# def remap(value, source_range, target_range):
#     """Remap a value from the source range to the target range.
# 
#     Examples ::
# 
#          >>> remap(50, (0, 100), (0, 10))
#          5.0
# 
#          >>> remap(5, (0, 10), (0, 100))
#          50.0
# 
#          >>> remap(5, (0, 10), (10, 20))
#          15.0
# 
#          >>> remap(15, (10, 20), (0, 10))
#          5.0
# 
#     :param value: The value to be remapped.
# 
#     :param source_range: The source range for :code:`value`
#     :type source_range: tuple
# 
#     :param target_range: The target range for :code:`value`
#     :type target_range: tuple
# 
#     """
#     s0, s1 = source_range
#     t0, t1 = target_range
#     S = s1 - s0
#     T = t1 - t0
#     return t0 + ((value - s0) / S) * T
# 
# def normalize(value, low, high):
#     """Normalize the given value to the specified range.
# 
#     Examples ::
# 
#         >>> normalize(10, 0, 100)
#         0.1
# 
#         >>> normalize(0.3, 0, 1)
#         0.3
# 
#         >>> normalize(100, 0, 100)
#         1.0
# 
#         >>> normalize(1, 1, 15)
#         0.0
# 
#     :param value:
#     :type value: float
# 
#     :param low: The lower bound for the range.
#     :type low: float
# 
#     :param high: The upper bound for the range.
#     :type high: float
#     """
#     return remap(value, (low, high), (0, 1))
# 
# def magnitude(x, y, z=0):
#     """Return the magnitude of the given vector.
# 
#     Examples ::
# 
#         >>> magnitude(3, 4)
#         5.0
# 
#         >>> magnitude(2, 3, 6)
#         7.0
# 
#         >>> magnitude(0, 0, 0)
#         0.0
# 
#     :param x: The x-component of the vector.
#     :type x: float
# 
#     :param y: The y-component of the vector.
#     :type y: float
# 
#     :param z: The z-component of the vector (defaults to 0).
#     :type z: float
# 
#     :returns: The magnitude of the vector.
#     :rtype: float
# 
#     """
#     return np.sqrt(np.sum(np.array([x, y, z]) ** 2))
# 
# def distance(point_1, point_2):
#     """Return the distance between two points.
# 
#     Examples ::
# 
#         >>> distance((0, 0, 0), (2, 3, 6))
#         7.0
# 
#         >>> distance((2, 3, 6), (2, 3, 6))
#         0.0
# 
#         >>> distance((6, 6, 6), (2, 3, 6))
#         5.0
# 
#     :param point_1:
#     :type point_1: tuple
# 
#     :param point_2:
#     :type point_2: tuple
# 
#     :returns: The distance between two points
#     :rtype: float
# 
#     """
#     p1 = np.array(_sanitize(point_1))
#     p2 = np.array(_sanitize(point_2))
#     return np.sqrt(np.sum((p1 - p2) ** 2))
# 
# def sq(number):
#     """Square a number.
# 
#     Examples ::
# 
#         >>> square(-25)
#         625
# 
#         >>> square(0)
#         0
# 
#         >>> square(13)
#         169
# 
# 
#     :param number: The number to be squared.
#     :type number: float
# 
#     :returns: The square of the number.
#     :rtype: float
# 
#     """
#     return number ** 2


# Path: p5/pmath/tests/test_utils.py
import unittest
from p5.pmath.utils import (
    constrain,
    lerp,
    remap,
    normalize,
    magnitude,
    distance,
    sq)




class TestUtils(unittest.TestCase):

    def test_constrain(self):
        self.assertEqual(constrain(5, 0, 10), 5)

        self.assertEqual(constrain(-10, 0, 10), 0)