diff options
author | BonfaceKilz | 2020-11-11 21:37:04 +0300 |
---|---|---|
committer | GitHub | 2020-11-11 21:37:04 +0300 |
commit | d60d8bbff8fbd032a3cf72559719a7f78881965a (patch) | |
tree | 9ae956af7a43465851e4f786d416755e890337d8 /wqflask/tests/unit/utility/test_formatting.py | |
parent | 25f7d30b9f052ec5d812bfe3bf9713df850cc267 (diff) | |
parent | dbeefadc25fb2bc6e04b4baa4b35bbbd5298e880 (diff) | |
download | genenetwork2-d60d8bbff8fbd032a3cf72559719a7f78881965a.tar.gz |
Merge pull request #477 from BonfaceKilz/feature/add-glossary-page
Feature/add glossary page
Diffstat (limited to 'wqflask/tests/unit/utility/test_formatting.py')
-rw-r--r-- | wqflask/tests/unit/utility/test_formatting.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/wqflask/tests/unit/utility/test_formatting.py b/wqflask/tests/unit/utility/test_formatting.py new file mode 100644 index 00000000..9d3033d1 --- /dev/null +++ b/wqflask/tests/unit/utility/test_formatting.py @@ -0,0 +1,33 @@ +import unittest +from utility.formatting import numify, commify + + +class TestFormatting(unittest.TestCase): + """Test formatting numbers by numifying or commifying""" + + def test_numify(self): + "Test that a number is correctly converted to a English readable string" + self.assertEqual(numify(1, 'item', 'items'), + 'one item') + self.assertEqual(numify(2, 'book'), 'two') + self.assertEqual(numify(2, 'book', 'books'), 'two books') + self.assertEqual(numify(0, 'book', 'books'), 'zero books') + self.assertEqual(numify(0), 'zero') + self.assertEqual(numify(5), 'five') + self.assertEqual(numify(14, 'book', 'books'), '14 books') + self.assertEqual(numify(999, 'book', 'books'), '999 books') + self.assertEqual(numify(1000000, 'book', 'books'), '1,000,000 books') + self.assertEqual(numify(1956), '1956') + + def test_commify(self): + "Test that commas are added correctly" + self.assertEqual(commify(1), '1') + self.assertEqual(commify(123), '123') + self.assertEqual(commify(1234), '1234') + self.assertEqual(commify(12345), '12,345') + self.assertEqual(commify(1234567890), '1,234,567,890') + self.assertEqual(commify(123.0), '123.0') + self.assertEqual(commify(1234.5), '1234.5') + self.assertEqual(commify(1234.56789), '1234.56789') + self.assertEqual(commify(123456.789), '123,456.789') + self.assertEqual(commify(None), None) |