Beispiel #1
0
 def test_commas(self):
     for num, result in [(123456789, '123,456,789'),
             (1234567.89, '1,234,567.89'), (-1234567, '-1,234,567'),
             (0, '0'), (1234, '1,234'), (0.1234, '0.1234'),
             (-1234.56, '-1,234.56'), (1000000, '1,000,000')]:
         guess = num2str(num, style="commas")
         self.assertEqual(guess, result)
Beispiel #2
0
 def test_newspaper(self):
     for num, result in [(123456789, '123 million'),
             (1234567.89, '1.23 million'), (0, '0'), (1234, '1,230'),
             (0.1234, '0.123'), (-1234.56, '-1,230'),
             (1200000, '1.20 million'), (12000000, '12.0 million')]:
         guess = num2str(num, sig_figs=3, style="newspaper")
         self.assertEqual(guess, result)
Beispiel #3
0
 def test_fractions_mixed(self):
     for num, result in [(Fraction(1, 2), '1/2'), (Fraction(3, 2), '1 1/2'),
                         (Fraction(5, 3), '1 2/3'),
                         (Fraction(-5, 3), '-1 2/3'), (Fraction(0, 3), '0'),
                         (Fraction(100, 1), '100')]:
         guess = num2str(num, frac_style="mixed")
         self.assertEqual(guess, result)
Beispiel #4
0
 def test_newspaper(self):
     for num, result in [(123456789, '123 million'),
                         (1234567.89, '1.23 million'), (0, '0'),
                         (1234, '1,230'), (0.1234, '0.123'),
                         (-1234.56, '-1,230'), (1200000, '1.20 million'),
                         (12000000, '12.0 million')]:
         guess = num2str(num, sig_figs=3, style="newspaper")
         self.assertEqual(guess, result)
Beispiel #5
0
 def test_commas(self):
     for num, result in [(123456789, '123,456,789'),
                         (1234567.89, '1,234,567.89'),
                         (-1234567, '-1,234,567'), (0, '0'),
                         (1234, '1,234'), (0.1234, '0.1234'),
                         (-1234.56, '-1,234.56'), (1000000, '1,000,000')]:
         guess = num2str(num, style="commas")
         self.assertEqual(guess, result)
Beispiel #6
0
 def test_words(self):
     for num, result in [(0, 'zero'), (-1, 'negative one'), (1, 'one'),
             (12, 'twelve'), (123, 'one hundred twenty three'),
             (1234, 'one thousand, two hundred thirty four'),
             (12345, 'twelve thousand, three hundred forty five'),
             (123456, 'one hundred twenty three thousand, four hundred fifty six'),
             (1234567, 'one million, two hundred thirty four thousand, five hundred sixty seven'),
             (12345678, 'twelve million, three hundred forty five thousand, six hundred seventy eight'),
             (1000000001, 'one billion, one'), (1000001001, 'one billion, one thousand, one')]:
         guess = num2str(num, style="words")
         self.assertEqual(guess, result)
Beispiel #7
0
 def test_frac_words(self):
     for num, result in [(Fraction(1, 2), "one half"),
             (Fraction(3, 2), "one and one half"),
             (Fraction(3, 4), "three quarters"),
             (Fraction(10, 3), "three and one third"),
             (100 + Fraction(1, 10), "one hundred and one tenth"),
             (Fraction(-2, 7), "negative two sevenths"),
             (Fraction(5, 26), "five twenty sixths"),
             (Fraction(7, 100), "seven one hundreths"),
             (Fraction(7, 120), "seven one hundred twentieths"),
             (Fraction(7, 123000), "seven one hundred twenty three thousandths"),
             (Fraction(1, 1000000), "one one millionth"),
             (Fraction(1, 1234), "one one thousand, two hundred thirty fourth")]:
         guess = num2str(num, style="words", frac_style="mixed")
         self.assertEqual(guess, result)
Beispiel #8
0
 def test_frac_words(self):
     for num, result in [
         (Fraction(1, 2), "one half"), (Fraction(3, 2), "one and one half"),
         (Fraction(3, 4), "three quarters"),
         (Fraction(10, 3), "three and one third"),
         (100 + Fraction(1, 10), "one hundred and one tenth"),
         (Fraction(-2, 7), "negative two sevenths"),
         (Fraction(5, 26), "five twenty sixths"),
         (Fraction(7, 100), "seven one hundreths"),
         (Fraction(7, 120), "seven one hundred twentieths"),
         (Fraction(7,
                   123000), "seven one hundred twenty three thousandths"),
         (Fraction(1, 1000000), "one one millionth"),
         (Fraction(1, 1234), "one one thousand, two hundred thirty fourth")
     ]:
         guess = num2str(num, style="words", frac_style="mixed")
         self.assertEqual(guess, result)
Beispiel #9
0
 def test_words(self):
     for num, result in [
         (0, 'zero'), (-1, 'negative one'), (1, 'one'), (12, 'twelve'),
         (123, 'one hundred twenty three'),
         (1234, 'one thousand, two hundred thirty four'),
         (12345, 'twelve thousand, three hundred forty five'),
         (123456,
          'one hundred twenty three thousand, four hundred fifty six'),
         (1234567,
          'one million, two hundred thirty four thousand, five hundred sixty seven'
          ),
         (12345678,
          'twelve million, three hundred forty five thousand, six hundred seventy eight'
          ), (1000000001, 'one billion, one'),
         (1000001001, 'one billion, one thousand, one')
     ]:
         guess = num2str(num, style="words")
         self.assertEqual(guess, result)
Beispiel #10
0
 def test_halves(self):
     guess = num2str(Fraction(5, 2), style="words", frac_style="improper")
     self.assertEqual(guess, "five halves")
     guess = num2str(Fraction(1, 2), style="words", frac_style="improper")
     self.assertEqual(guess, "one half")
Beispiel #11
0
 def test_fractions_improper(self):
     for num, result in [(Fraction(1, 2), '1/2'), (Fraction(3, 2), '3/2'),
             (Fraction(5, 3), '5/3'), (Fraction(-5, 3), '-5/3'),
             (Fraction(0, 3), '0'), (Fraction(100, 1), '100')]:
         guess = num2str(num, frac_style="improper")
         self.assertEqual(guess, result)
Beispiel #12
0
 def test_fractions_mixed(self):
     for num, result in [(Fraction(1, 2), '1/2'), (Fraction(3, 2), '1 1/2'),
             (Fraction(5, 3), '1 2/3'), (Fraction(-5, 3), '-1 2/3'),
             (Fraction(0, 3), '0'), (Fraction(100, 1), '100')]:
         guess = num2str(num, frac_style="mixed")
         self.assertEqual(guess, result)
Beispiel #13
0
 def test_argparsing(self):
     self.assertRaises(TypeError, lambda: num2str(0, foshizzle='jim'))
     self.assertRaises(ValueError, lambda: num2str(0, style='foshizzle'))
Beispiel #14
0
 def test_halves(self):
     guess = num2str(Fraction(5, 2), style="words", frac_style="improper")
     self.assertEqual(guess, "five halves")
     guess = num2str(Fraction(1, 2), style="words", frac_style="improper")
     self.assertEqual(guess, "one half")
Beispiel #15
0
 def test_fractions_improper(self):
     for num, result in [(Fraction(1, 2), '1/2'), (Fraction(3, 2), '3/2'),
                         (Fraction(5, 3), '5/3'), (Fraction(-5, 3), '-5/3'),
                         (Fraction(0, 3), '0'), (Fraction(100, 1), '100')]:
         guess = num2str(num, frac_style="improper")
         self.assertEqual(guess, result)
Beispiel #16
0
 def test_argparsing(self):
     self.assertRaises(TypeError, lambda: num2str(0, foshizzle='jim'))
     self.assertRaises(ValueError, lambda: num2str(0, style='foshizzle'))