# Path: endorsements/templatetags/endorsement_extras.py
# @register.filter(name='shorten')
# def shorten(n):
#     """Takes in an integer (over a thousand) and shortens it by using K or M.
#     Examples:
#     * 1,234,567 becomes 1.2M
#     * 12,345 becomes 12K
#     * 99,999,999 becomes 99M
#     """
#     if n > 10000000:
#         return '%dM' % round(n / 1000000)
#     elif n > 1000000:
#         # It's between 1 and 10 million. Include the decimal point.
#         return '%.1fM' % round(n / 1000000., 2)
#     elif n > 1000:
#         pre_decimal = int(round(n / 1000))
#         return "%dK" % pre_decimal
#     else:
#         return str(n)


from django.test import TestCase
from endorsements.templatetags.endorsement_extras import shorten



class TestShortenFilter(TestCase):
    expected = {
        12345678: '12M',
        1234567: '1.2M',
        123456: '123K',
        12345: '12K',
        1234: '1K',
        123: '123',
        99999999: '99M'
    }

    def runTest(self):
        for n, expected_output in self.expected.iteritems():

# Path: endorsements/templatetags/endorsement_extras.py
# @register.filter(name='shorten')
# def shorten(n):
#     """Takes in an integer (over a thousand) and shortens it by using K or M.
#     Examples:
#     * 1,234,567 becomes 1.2M
#     * 12,345 becomes 12K
#     * 99,999,999 becomes 99M
#     """
#     if n > 10000000:
#         return '%dM' % round(n / 1000000)
#     elif n > 1000000:
#         # It's between 1 and 10 million. Include the decimal point.
#         return '%.1fM' % round(n / 1000000., 2)
#     elif n > 1000:
#         pre_decimal = int(round(n / 1000))
#         return "%dK" % pre_decimal
#     else:
#         return str(n)


# Path: endorsements/tests.py
from django.test import TestCase
from endorsements.templatetags.endorsement_extras import shorten




class TestShortenFilter(TestCase):
    expected = {
        12345678: '12M',
        1234567: '1.2M',
        123456: '123K',
        12345: '12K',
        1234: '1K',
        123: '123',
        99999999: '99M'
    }

    def runTest(self):
        for n, expected_output in self.expected.iteritems():

            actual_output = shorten(n)