import unittest

class TestStringMethods(unittest.TestCase):

    def test_upper(self):
        self.assertEqual('foo'.upper(), 'FOO')

    def test_isupper(self):
        self.assertTrue('FOO'.isupper())
        self.assertFalse('Foo'.isupper())

    def test_split(self):
        s = 'hello world'
        self.assertEqual(s.split(), ['hello', 'world'])
        # check that s.split fails when the separator is not a string
        with self.assertRaises(TypeError):
            s.split(2)



def map_range(x, X_min, X_max, Y_min, Y_max):
    X_range = X_max - X_min
    Y_range = Y_max - Y_min
    XY_ratio = X_range/Y_range

    y = ((x-X_min) / XY_ratio + Y_min) // 1

    return int(y)



class TestMapping(unittest.TestCase):
    def test_positive(self):
        min = map_range(-100, -100, 100, 0, 1000)
        half = map_range(0, -100, 100, 0, 1000)
        max = map_range(100, -100, 100, 0, 1000)
        assert min == 0
        assert half == 500
        assert max == 1000

    def test_negative(self):
        ranges = (0, 100, 0, 1000)
        min = map_range(0, *ranges)
        half = map_range(50, *ranges)
        max = map_range(100, *ranges)
        assert min == 0
        assert half == 500
        assert max == 1000

if __name__ == '__main__':
    unittest.main()
@@ -492,204 +492,46 @@
 %0A%0A%0A%0A
-def map_range(x, X_min, X_max, Y_min, Y_max):%0A    X_range = X_max - X_min%0A    Y_range = Y_max - Y_min%0A    XY_ratio = X_range/Y_range%0A%0A    y = ((x-X_min) / XY_ratio + Y_min) // 1%0A%0A    return int(y)
+from donkey.actuators import map_range
 %0A%0A%0A%0A

update mapping test