-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Test Cases
(venv) wabisabi@wabisabi:~/Desktop/WordToNumber$ pytest
============================= test session starts ==============================
platform linux -- Python 3.12.3, pytest-8.3.5, pluggy-1.5.0
rootdir: /home/wabisabi/Desktop/WordToNumber
collected 10 items
tests/test_word_to_number.py .....FFF.. [100%]
=================================== FAILURES ===================================
_____________________ TestWordToNum.test_error_conditions ______________________
self = <tests.test_word_to_number.TestWordToNum testMethod=test_error_conditions>
def test_error_conditions(self):
"""Test error conditions."""
with self.assertRaises(ValueError):
word_to_num(123) # Non-string input
with self.assertRaises(ValueError):
word_to_num("") # Empty string
with self.assertRaises(ValueError):
word_to_num("hello world") # No valid number words
with self.assertRaises(ValueError):
word_to_num("million billion") # Incorrect order
with self.assertRaises(ValueError):
word_to_num("thousand million") # Incorrect order
with self.assertRaises(ValueError):
word_to_num("lakh crore") # Incorrect order
with self.assertRaises(ValueError):
word_to_num("one million one million") # Repeated term
with self.assertRaises(ValueError):
> word_to_num("one billion thousand") # Missing million between billion and thousand
tests/test_word_to_number.py:90:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
WordToNumber/word_to_number.py:194: in word_to_num
thousand_multiplier = number_formation(clean_numbers[billion_index+1:thousand_index])
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
def number_formation(number_words):
numbers = []
for number_word in number_words:
numbers.append(american_number_system[number_word])
if len(numbers) == 4:
return (numbers[0] * numbers[1]) + numbers[2] + numbers[3]
elif len(numbers) == 3:
return numbers[0] * numbers[1] + numbers[2]
elif len(numbers) == 2:
if 100 in numbers:
return numbers[0] * numbers[1]
else:
return numbers[0] + numbers[1]
else:
> return numbers[0]
E IndexError: list index out of range
WordToNumber/word_to_number.py:70: IndexError
______________________ TestWordToNum.test_extended_system ______________________
self = <tests.test_word_to_number.TestWordToNum testMethod=test_extended_system>
def test_extended_system(self):
"""Test extended number system with arba."""
self.assertEqual(word_to_num("one arba"), 1000000000)
> self.assertEqual(word_to_num("two arba fifty crore"), 2500000000)
E AssertionError: 2510000050 != 2500000000
tests/test_word_to_number.py:39: AssertionError
_______________________ TestWordToNum.test_indian_system _______________________
self = <tests.test_word_to_number.TestWordToNum testMethod=test_indian_system>
def test_indian_system(self):
"""Test Indian number system words."""
self.assertEqual(word_to_num("one lakh"), 100000)
self.assertEqual(word_to_num("one lac"), 100000)
self.assertEqual(word_to_num("one lakhs"), 100000)
> self.assertEqual(word_to_num("two lakh fifty thousand"), 250000)
E AssertionError: 251050 != 250000
tests/test_word_to_number.py:31: AssertionError
=========================== short test summary info ============================
FAILED tests/test_word_to_number.py::TestWordToNum::test_error_conditions - IndexError: list index out of range
FAILED tests/test_word_to_number.py::TestWordToNum::test_extended_system - AssertionError: 2510000050 != 2500000000
FAILED tests/test_word_to_number.py::TestWordToNum::test_indian_system - AssertionError: 251050 != 250000
========================= 3 failed, 7 passed in 0.09s ==========================
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working