forked from akshaynagpal/w2n
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unit_testing.py
50 lines (45 loc) · 3.09 KB
/
unit_testing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import unittest
from word2number import w2n
class TestW2N(unittest.TestCase):
def test_positives(self):
self.assertEqual(w2n.word_to_num("two million three thousand nine hundred and eighty four"), 2003984)
self.assertEqual(w2n.word_to_num("nineteen"), 19)
self.assertEqual(w2n.word_to_num("two thousand and nineteen"), 2019)
self.assertEqual(w2n.word_to_num("two million three thousand and nineteen"), 2003019)
self.assertEqual(w2n.word_to_num('three billion'), 3000000000)
self.assertEqual(w2n.word_to_num('three million'), 3000000)
self.assertEqual(w2n.word_to_num('one hundred twenty three million four hundred fifty six thousand seven hundred and eighty nine'), 123456789)
self.assertEqual(w2n.word_to_num('eleven'), 11)
self.assertEqual(w2n.word_to_num('nineteen billion and nineteen'), 19000000019)
self.assertEqual(w2n.word_to_num('one hundred and forty two'), 142)
self.assertEqual(w2n.word_to_num('112'), 112)
self.assertEqual(w2n.word_to_num('11211234'), 11211234)
self.assertEqual(w2n.word_to_num('five'), 5)
self.assertEqual(w2n.word_to_num('two million twenty three thousand and forty nine'), 2023049)
self.assertEqual(w2n.word_to_num('two point three'), 2.3)
self.assertEqual(w2n.word_to_num('two million twenty three thousand and forty nine point two three six nine'), 2023049.2369)
self.assertEqual(w2n.word_to_num('one billion two million twenty three thousand and forty nine point two three six nine'), 1002023049.2369)
self.assertEqual(w2n.word_to_num('point one'), 0.1)
self.assertEqual(w2n.word_to_num('point'), 0)
self.assertEqual(w2n.word_to_num('point nineteen'), 0)
self.assertEqual(w2n.word_to_num('one hundred thirty-five'), 135)
self.assertEqual(w2n.word_to_num('hundred'), 100)
self.assertEqual(w2n.word_to_num('thousand'), 1000)
self.assertEqual(w2n.word_to_num('million'), 1000000)
self.assertEqual(w2n.word_to_num('billion'), 1000000000)
self.assertEqual(w2n.word_to_num('nine point nine nine nine'), 9.999)
self.assertEqual(w2n.word_to_num('seventh point nineteen'), 0)
self.assertEqual(w2n.word_to_num('hundred and fifteen million'), 115000000)
self.assertEqual(w2n.word_to_num('forty-five hundred'), 4500)
def test_negatives(self):
self.assertRaises(ValueError, w2n.word_to_num, '112-')
self.assertRaises(ValueError, w2n.word_to_num, '-')
self.assertRaises(ValueError, w2n.word_to_num, 'on')
self.assertRaises(ValueError, w2n.word_to_num, 'million million')
self.assertRaises(ValueError, w2n.word_to_num, 'three million million')
self.assertRaises(ValueError, w2n.word_to_num, 'million four million')
self.assertRaises(ValueError, w2n.word_to_num, 'thousand million')
self.assertRaises(ValueError, w2n.word_to_num, 'one billion point two million twenty three thousand and forty nine point two three six nine')
self.assertRaises(ValueError, w2n.word_to_num, 112)
if __name__ == '__main__':
unittest.main()