Skip to content

Commit

Permalink
Fix final letters
Browse files Browse the repository at this point in the history
  • Loading branch information
Noam Nol authored and NoamNol committed Sep 12, 2024
1 parent 37dc0b2 commit a2a3143
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
12 changes: 11 additions & 1 deletion gematriapy/gematria.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@
])


HEBREW_ALL_LETTERS = {
**HEBREW_BASIC_LETTERS,
"ך": 20,
"ם": 40,
"ן": 50,
"ף": 80,
"ץ": 90,
}


def to_hebrew(number: int) -> str:
"""
Convert number to Hebrew letter(s).
Expand Down Expand Up @@ -68,5 +78,5 @@ def to_number(hebrew: str) -> int:
"""
sum = 0
for letter in hebrew:
sum += HEBREW_BASIC_LETTERS.get(letter, 0)
sum += HEBREW_ALL_LETTERS.get(letter, 0)
return sum
14 changes: 14 additions & 0 deletions tests/test_to_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ def test_long_hebrew_v1(self):
def test_long_hebrew_v2(self):
self.assertEqual(gematriapy.to_number("רטו"), 215)

def test_long_hebrew_v3(self):
self.assertEqual(gematriapy.to_number("שלום"), 376)

def test_single_final_letter(self):
"""
In Hebrew, 'final' letters are different from regular letters.
Some letters have a special shape if positioned at the end of a word.
"""
self.assertEqual(gematriapy.to_number("ך"), 20)
self.assertEqual(gematriapy.to_number("ם"), 40)
self.assertEqual(gematriapy.to_number("ן"), 50)
self.assertEqual(gematriapy.to_number("ף"), 80)
self.assertEqual(gematriapy.to_number("ץ"), 90)

def test_illegal_hebrew_number_v1(self):
"""
In Hebrew, letters representing a numerical value should have an order:
Expand Down

0 comments on commit a2a3143

Please sign in to comment.