Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ayaka14732 committed Apr 18, 2024
1 parent 0492000 commit 1b24342
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 55 deletions.
94 changes: 39 additions & 55 deletions src/QieyunEncoder/音韻地位.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
編碼表 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
韻順序表 = '東_冬鍾江支脂之微魚虞模齊祭泰佳皆夬灰咍廢真臻文殷元魂痕寒刪山仙先蕭宵肴豪歌_麻_陽唐庚_耕清青蒸登尤侯幽侵覃談鹽添咸銜嚴凡'

解析音韻描述 = re.compile(fr'([{常量.所有母}])([{常量.所有呼}]?)([{常量.所有等}]?)([{常量.所有重紐}]?)([{常量.所有韻}])([{常量.所有聲}])')
解析音韻描述 = re.compile(fr'([{常量.所有母}])([{常量.所有呼}])?([{常量.所有等}])?([{常量.所有重紐}])?([{常量.所有韻}])([{常量.所有聲}])')

class 音韻地位:
'''
切韻音系音韻地位。
:param 母: 聲母
:type 母: str
:param 呼: 呼(開口呼/合口呼),可以爲 ``None``
:param 呼: 呼(開/合),可以爲 ``None``
:type 呼: str, optional
:param 等: 等
:type 等: str
Expand Down Expand Up @@ -368,12 +368,10 @@ def 驗證(母: str, 呼: str | None, 等: str, 重紐: str | None, 韻: str,
elif in 常量.必爲合口的韻:
assert == '合'
else:
assert is not None and len(
) == 1 and in 常量.所有呼, 'Unexpected 呼: ' + repr()
assert is not None and len() == 1 and in 常量.所有呼, 'Unexpected 呼: ' + repr()

if in 常量.重紐母 and in 常量.重紐韻:
assert 重紐 is not None and len(
重紐) == 1 and 重紐 in 常量.所有重紐, 'Unexpected 重紐: ' + repr(重紐)
assert 重紐 is not None and len(重紐) == 1 and 重紐 in 常量.所有重紐, 'Unexpected 重紐: ' + repr(重紐)
else:
assert 重紐 is None, 'Unexpected 重紐: ' + repr(重紐)

Expand Down Expand Up @@ -410,40 +408,41 @@ def from編碼(編碼: str):
重紐: str | None = 常量.所有重紐[重紐編碼]
= 常量.所有聲[聲編碼]

if 韻編碼 == 0:
= '東'
= '一'
elif 韻編碼 == 1:
= '東'
= '三'
elif 韻編碼 == 37:
= '歌'
= '一'
elif 韻編碼 == 38:
= '歌'
= '三'
elif 韻編碼 == 39:
= '麻'
= '二'
elif 韻編碼 == 40:
= '麻'
= '三'
elif 韻編碼 == 43:
= '庚'
= '二'
elif 韻編碼 == 44:
= '庚'
= '三'
else:
= 韻順序表[韻編碼]
if in 常量.一等韻:
match 韻編碼:
case 0:
= '東'
= '一'
elif in 常量.二等韻:
case 1:
= '東'
= '三'
case 37:
= '歌'
= '一'
case 38:
= '歌'
= '三'
case 39:
= '麻'
= '二'
elif in 常量.三等韻:
case 40:
= '麻'
= '三'
elif in 常量.四等韻:
= '四'
case 43:
= '庚'
= '二'
case 44:
= '庚'
= '三'
case _:
= 韻順序表[韻編碼]
if in 常量.一等韻:
= '一'
elif in 常量.二等韻:
= '二'
elif in 常量.三等韻:
= '三'
elif in 常量.四等韻:
= '四'

if in '幫滂並明' or in 常量.開合中立的韻:
assert == '開'
Expand Down Expand Up @@ -531,27 +530,12 @@ def 韻到編碼(韻):
def 聲到編碼():
return 常量.所有聲.index()

return (
聲到編碼(self.),
韻到編碼(self.),
重紐到編碼(self.重紐),
等到編碼(self.),
呼到編碼(self.),
母到編碼(self.),
) < (
聲到編碼(that.),
韻到編碼(that.),
重紐到編碼(that.重紐),
等到編碼(that.),
呼到編碼(that.),
母到編碼(that.),
)
return (聲到編碼(self.), 韻到編碼(self.), 重紐到編碼(self.重紐), 等到編碼(self.), 呼到編碼(self.), 母到編碼(self.)) \
< (聲到編碼(that.), 韻到編碼(that.), 重紐到編碼(that.重紐), 等到編碼(that.), 呼到編碼(that.), 母到編碼(that.))

def __le__(self, that) -> bool:
if not isinstance(that, 音韻地位):
raise TypeError(
"'<' not supported between instances of '音韻地位' and " + type(that).__name__)

raise TypeError("'<' not supported between instances of '音韻地位' and " + type(that).__name__)
return self == that or self < that

def __hash__(self) -> int:
Expand Down
Empty file removed tests/__init__.py
Empty file.

0 comments on commit 1b24342

Please sign in to comment.