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 getwhtdict(self): whtdict = {} whtdict['book_number'] = self.getbooknumber() whtdict['number'] = self.getnumber() # tax payer part whtdict['taxpayer_name'] = self.getfullname() whtdict['taxpayer_id'] = self.getidwithformat() whtdict['taxpayer_address'] = self.getfulladdress() # section 40 part dt = self.gettaxdate_thaiformat() whtdict['section40_date'] = dt whtdict['section40_amount'] = self.getinterestamount() whtdict['section40_tax'] = self.gettaxamount() # total part whtdict['total_amount'] = self.getinterestamount() whtdict['total_tax'] = self.gettaxamount() whtdict['total_bahttext'] = "( {} )".format( bahttext(self.gettaxamount())) # Issue date / month / year part whtdict['issue_date'] = "{}".format(dt[0:2]) whtdict['issue_month'] = " {}".format(dt[3:7]) whtdict['issue_year'] = "{}".format(dt[8:]) return whtdict
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), "")