diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py
index 88526e5..0f5870c 100644
a
|
b
|
def pprint(value):
|
888 | 888 | return pformat(value) |
889 | 889 | except Exception as e: |
890 | 890 | return "Error in formatting: %s" % force_text(e, errors="replace") |
| 891 | |
| 892 | ################### |
| 893 | # MATH # |
| 894 | ################### |
| 895 | |
| 896 | @register.filter("map") |
| 897 | def map_filter(value, src_min, src_max, dst_min, dst_max): |
| 898 | """map the value from [src_min,src_max] range to [dst_min, dst_max] |
| 899 | range. |
| 900 | |
| 901 | Modeled after the corresponding map() function available (for |
| 902 | example) in Processing http://processing.org/reference/map_.html |
| 903 | """ |
| 904 | return dst_min + value * ( dst_max - dst_min) / ( src_max - src_min) |
| 905 | |
diff --git a/tests/defaultfilters/tests.py b/tests/defaultfilters/tests.py
index 21734fa..50e6ca8 100644
a
|
b
|
class DefaultFiltersTests(TestCase):
|
656 | 656 | self.assertEqual(removetags(123, 'a'), '123') |
657 | 657 | self.assertEqual(striptags(123), '123') |
658 | 658 | |
| 659 | def test_map_filter(self): |
| 660 | self.assertAlmostEqual(map_filter(0, 0, 100, 0, 1000), 0) |
| 661 | self.assertAlmostEqual(map_filter(0, 0, 100, 1000, 0), 1000) |
| 662 | self.assertAlmostEqual(map_filter(0, 100, 0, 0, 1000), 1000) |
| 663 | self.assertAlmostEqual(map_filter(10, 0, 100, 0, 1000), 100) |