Skip to content

Commit

Permalink
fixed #15 thanks to Laura
Browse files Browse the repository at this point in the history
  • Loading branch information
Proteusiq committed Aug 1, 2023
1 parent 1b55dc4 commit 4298c3b
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 37 deletions.
57 changes: 26 additions & 31 deletions saa/luga/de/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
@dataclass(init=False, eq=False, repr=False, frozen=False)
class Deutsch(Luga):
time = {
"to": "{minute} {time_indicator} vor {hour} Uhr",
"past": "{minute} {time_indicator} nach {hour} Uhr",
"to": "{minute} time_indicator vor {hour} Uhr",
"past": "{minute} time_indicator nach {hour} Uhr",
0: "{hour} Uhr",
15: "Viertel nach {hour}",
45: "Viertel vor {hour}",
30: "Halb {hour}",
15: "viertel nach {hour}",
45: "viertel vor {hour}",
30: "halb {hour}",
}
number_connector = "und"
connect_format = "{0}{1}{2}"
connect_format = "{2}{1}{0}"
numbers = {
0: "null",
1: "ein", # ein und zwanzig / eine Minute / ein Uhr
Expand Down Expand Up @@ -42,39 +42,34 @@ class Deutsch(Luga):

@staticmethod
def time_logic(hour, minute) -> tuple[int, int, str, str]:
if minute in [0, 15, 30, 45]:
if minute == 45 or minute == 30:
hour += 1
return (hour, minute, '', '')

is_to = "to" if minute > 30 else "past"
time_indicator = "Minuten" if minute not in [1,59] else "Minute"


is_to = "to" if minute >= 30 else "past"
time_indicator = "Minuten" if minute not in (1,59) else "Minute"


if is_to == "to":
hour += 1
minute = 60 - minute

if minute <= 20 or minute == 30 or minute == 40 or minute == 50:
if minute == 1:
minute = Deutsch.numbers[minute][1] if is_to == 'to' else Deutsch.numbers[minute][0]
else:
minute = Deutsch.numbers[minute]
else:
tens = minute // 10 * 10
ones = minute % 10
minute = Deutsch.connect_format.format(Deutsch.numbers[ones], Deutsch.number_connector, Deutsch.numbers[tens])

hour = Deutsch.numbers[hour]

return hour, minute, is_to, time_indicator



@staticmethod
def post_logic(hour, minute, is_to, time_indicator) -> str:
if is_to:
return Deutsch.time[is_to].format(minute=minute, time_indicator=time_indicator, hour=hour)
else:
return Deutsch.time[minute].format(hour=hour)
def post_logic(text:str) -> str:


if text in ("viertel nach ein",
"viertel vor ein",
"halb ein"):
text+="s"

text = (text
.replace("ein Minute", "eine Minute")
.replace("null", "zwölf")
)

return text

class Language(Deutsch):
pass
Expand Down
31 changes: 25 additions & 6 deletions tests/test_clock/test_clock_de.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,47 @@
from saa.core.watch import Watch
from saa.core.plugins import supported_languages

German = supported_languages.get("de")
Deutsch = supported_languages.get("de")

test_cases = [
(time(hour=13, minute=45), German, "viertel vor zwei"),
(time(hour=13, minute=15), German, "viertel nach eins"),
(time(hour=13, minute=30), German, "halb zwei"),
(time(hour=13, minute=45), Deutsch, "viertel vor zwei"),
(time(hour=13, minute=15), Deutsch, "viertel nach eins"),
(time(hour=13, minute=30), Deutsch, "halb zwei"),
(time(hour=12, minute=45), Deutsch, "viertel vor eins"),
(time(hour=13, minute=0), Deutsch, "ein Uhr"),
(time(hour=13, minute=13), Deutsch, "dreizehn Minuten nach ein Uhr"),
]


@pytest.mark.parametrize("test_input, language, test_output", test_cases)
def test_clocks(test_input, language, test_output):

clock = Watch(language=language)
assert test_output == clock(test_input)


test_plural_cases = [
(time(hour=13, minute=1), German, "eine Minute nach eins"),
(time(hour=6, minute=17), German, "siebzehn Minuten nach sechs"),
(time(hour=13, minute=1), Deutsch, "eine Minute nach ein Uhr"),
(time(hour=6, minute=17), Deutsch, "siebzehn Minuten nach sechs Uhr"),
(time(hour=7, minute=3), Deutsch, "drei Minuten nach sieben Uhr"),
(time(hour=5, minute=40), Deutsch, "zwanzig Minuten vor sechs Uhr"),
(time(hour=8, minute=14), Deutsch, "vierzehn Minuten nach acht Uhr"),
(time(hour=7, minute=46), Deutsch, "vierzehn Minuten vor acht Uhr"),
(time(hour=14, minute=30), Deutsch, "halb drei"),
(time(hour=9, minute=20), Deutsch, "zwanzig Minuten nach neun Uhr"),
(time(hour=5, minute=40), Deutsch, "zwanzig Minuten vor sechs Uhr"),
(time(hour=18, minute=15), Deutsch, "viertel nach sechs"),
(time(hour=17, minute=45), Deutsch, "viertel vor sechs"),
(time(hour=21, minute=30), Deutsch, "halb zehn"),
(time(hour=12, minute=30), Deutsch, "halb eins"),
(time(hour=1, minute=30), Deutsch, "halb zwei"),
(time(hour=0, minute=0), Deutsch, "zwölf Uhr"),
(time(hour=0, minute=15), Deutsch, "viertel nach zwölf"),
]


@pytest.mark.parametrize("test_input, language, test_output", test_plural_cases)
def test_cases(test_input, language, test_output):

clock = Watch(language=language)
assert test_output == clock(test_input)
16 changes: 16 additions & 0 deletions tests/test_numbers/test_numbers_de.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import pytest
from saa.core.numbers import Converter
from saa.core.plugins import supported_languages

Deutsch = supported_languages.get("de")

test_cases = [
(25, Deutsch, "fünfundzwanzig"),
(14, Deutsch, "vierzehn"),
]


@pytest.mark.parametrize("test_input, language, test_output", test_cases)
def test_numbers(test_input, language, test_output):
convert = Converter(language=language)
assert test_output == convert(test_input)

0 comments on commit 4298c3b

Please sign in to comment.