def test_number(self): self.assertEqual( bahttext(5611116.50), "ห้าล้านหกแสนหนึ่งหมื่นหนึ่งพันหนึ่งร้อยสิบหกบาทห้าสิบสตางค์", ) self.assertEqual(bahttext(116), "หนึ่งร้อยสิบหกบาทถ้วน") self.assertEqual(bahttext(0), "ศูนย์บาทถ้วน") self.assertEqual(bahttext(None), "") self.assertEqual(num_to_thaiword(112), "หนึ่งร้อยสิบสอง") self.assertEqual(num_to_thaiword(0), "ศูนย์") self.assertEqual(num_to_thaiword(None), "") self.assertEqual(thaiword_to_num("ร้อยสิบสอง"), 112) self.assertEqual( thaiword_to_num([ "หก", "ล้าน", "หก", "แสน", "หกหมื่น", "หกพัน", "หกร้อย", "หกสิบ", "หก" ]), 6666666, ) self.assertEqual(thaiword_to_num("ยี่สิบ"), 20) self.assertEqual(thaiword_to_num("ศูนย์"), 0) self.assertEqual(thaiword_to_num("ศูนย์อะไรนะ"), 0) self.assertEqual(thaiword_to_num(""), None) self.assertEqual(thaiword_to_num(None), None) self.assertEqual(arabic_digit_to_thai_digit("ไทยแลนด์ 4.0"), "ไทยแลนด์ ๔.๐") self.assertEqual(arabic_digit_to_thai_digit(""), "") self.assertEqual(arabic_digit_to_thai_digit(None), "") self.assertEqual(thai_digit_to_arabic_digit("๔๐๔ Not Found"), "404 Not Found") self.assertEqual(thai_digit_to_arabic_digit(""), "") self.assertEqual(thai_digit_to_arabic_digit(None), "") self.assertEqual(digit_to_text("RFC 7258"), "RFC เจ็ดสองห้าแปด") self.assertEqual(digit_to_text(""), "") self.assertEqual(digit_to_text(None), "") self.assertEqual(text_to_arabic_digit("เจ็ด"), "7") self.assertEqual(text_to_arabic_digit(""), "") self.assertEqual(text_to_arabic_digit(None), "") self.assertEqual(text_to_thai_digit("เก้า"), "๙") self.assertEqual(text_to_thai_digit(""), "") self.assertEqual(text_to_thai_digit(None), "")
def test_number(self): self.assertEqual( bahttext(5611116.50), "ห้าล้านหกแสนหนึ่งหมื่นหนึ่งพันหนึ่งร้อยสิบหกบาทห้าสิบสตางค์", ) self.assertEqual(bahttext(116), "หนึ่งร้อยสิบหกบาทถ้วน") self.assertEqual(bahttext(0), "ศูนย์บาทถ้วน") self.assertEqual(bahttext(None), "") self.assertEqual(num_to_thaiword(112), "หนึ่งร้อยสิบสอง") self.assertEqual(num_to_thaiword(0), "ศูนย์") self.assertEqual(num_to_thaiword(None), "") self.assertEqual(thaiword_to_num("ร้อยสิบสอง"), 112) self.assertEqual( thaiword_to_num( ["หก", "ล้าน", "หก", "แสน", "หกหมื่น", "หกพัน", "หกร้อย", "หกสิบ", "หก"] ), 6666666, ) self.assertEqual(thaiword_to_num("ยี่สิบ"), 20) self.assertEqual(thaiword_to_num("ศูนย์"), 0) self.assertEqual(thaiword_to_num("ศูนย์อะไรนะ"), 0) self.assertEqual(thaiword_to_num(""), None) self.assertEqual(thaiword_to_num(None), None) self.assertEqual(arabic_digit_to_thai_digit("ไทยแลนด์ 4.0"), "ไทยแลนด์ ๔.๐") self.assertEqual(arabic_digit_to_thai_digit(""), "") self.assertEqual(arabic_digit_to_thai_digit(None), "") self.assertEqual(thai_digit_to_arabic_digit("๔๐๔ Not Found"), "404 Not Found") self.assertEqual(thai_digit_to_arabic_digit(""), "") self.assertEqual(thai_digit_to_arabic_digit(None), "") self.assertEqual(digit_to_text("RFC 7258"), "RFC เจ็ดสองห้าแปด") self.assertEqual(digit_to_text(""), "") self.assertEqual(digit_to_text(None), "") self.assertEqual(text_to_arabic_digit("เจ็ด"), "7") self.assertEqual(text_to_arabic_digit(""), "") self.assertEqual(text_to_arabic_digit(None), "") self.assertEqual(text_to_thai_digit("เก้า"), "๙") self.assertEqual(text_to_thai_digit(""), "") self.assertEqual(text_to_thai_digit(None), "")
def test_number(self): self.assertEqual( bahttext(5611116.50), "ห้าล้านหกแสนหนึ่งหมื่นหนึ่งพันหนึ่งร้อยสิบหกบาทห้าสิบสตางค์", ) self.assertEqual(bahttext(116), "หนึ่งร้อยสิบหกบาทถ้วน") self.assertEqual(bahttext(0), "ศูนย์บาทถ้วน") self.assertEqual(bahttext(None), "") self.assertEqual(num_to_thaiword(None), "") self.assertEqual(num_to_thaiword(0), "ศูนย์") self.assertEqual(num_to_thaiword(112), "หนึ่งร้อยสิบสอง") self.assertEqual(num_to_thaiword(-273), "ลบสองร้อยเจ็ดสิบสาม") self.assertEqual(thaiword_to_num("ศูนย์"), 0) self.assertEqual(thaiword_to_num("แปด"), 8) self.assertEqual(thaiword_to_num("ยี่สิบ"), 20) self.assertEqual(thaiword_to_num("ร้อยสิบสอง"), 112) self.assertEqual( thaiword_to_num("หกล้านหกแสนหกหมื่นหกพันหกร้อยหกสิบหก"), 6666666) self.assertEqual(thaiword_to_num("สองล้านสามแสนหกร้อยสิบสอง"), 2300612) self.assertEqual(thaiword_to_num("หนึ่งร้อยสิบล้าน"), 110000000) self.assertEqual(thaiword_to_num("สิบห้าล้านล้านเจ็ดสิบสอง"), 15000000000072) self.assertEqual(thaiword_to_num("หนึ่งล้านล้าน"), 1000000000000) self.assertEqual( thaiword_to_num("สองแสนสี่หมื่นสามสิบล้านสี่พันล้าน"), 240030004000000000, ) self.assertEqual(thaiword_to_num("ร้อยสิบล้านแปดแสนห้าพัน"), 110805000) self.assertEqual(thaiword_to_num("ลบหนึ่ง"), -1) text = "ลบหนึ่งร้อยล้านสี่แสนห้าพันยี่สิบเอ็ด" self.assertEqual(num_to_thaiword(thaiword_to_num(text)), text) with self.assertRaises(ValueError): thaiword_to_num("ศูนย์อะไรนะ") with self.assertRaises(ValueError): thaiword_to_num("") with self.assertRaises(ValueError): thaiword_to_num("ห้าพันสี่หมื่น") with self.assertRaises(TypeError): thaiword_to_num(None) with self.assertRaises(TypeError): thaiword_to_num(["หนึ่ง"]) self.assertEqual(arabic_digit_to_thai_digit("ไทยแลนด์ 4.0"), "ไทยแลนด์ ๔.๐") self.assertEqual(arabic_digit_to_thai_digit(""), "") self.assertEqual(arabic_digit_to_thai_digit(None), "") self.assertEqual(thai_digit_to_arabic_digit("๔๐๔ Not Found"), "404 Not Found") self.assertEqual(thai_digit_to_arabic_digit(""), "") self.assertEqual(thai_digit_to_arabic_digit(None), "") self.assertEqual(digit_to_text("RFC 7258"), "RFC เจ็ดสองห้าแปด") self.assertEqual(digit_to_text(""), "") self.assertEqual(digit_to_text(None), "") self.assertEqual(text_to_arabic_digit("เจ็ด"), "7") self.assertEqual(text_to_arabic_digit(""), "") self.assertEqual(text_to_arabic_digit(None), "") self.assertEqual(text_to_thai_digit("เก้า"), "๙") self.assertEqual(text_to_thai_digit(""), "") self.assertEqual(text_to_thai_digit(None), "")