Skip to content

Commit

Permalink
Merge pull request #862 from dev-hato/fix-format-fono/add-omikuji
Browse files Browse the repository at this point in the history
formatが間違ってたので直してあげたよ!PRをマージしてね! #860
  • Loading branch information
fono09 authored Mar 5, 2022
2 parents a919021 + 027e7b4 commit d89cdfb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
25 changes: 17 additions & 8 deletions library/omikuji.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,23 @@
from functools import reduce
from random import choices


class AbstractOmikujiResults(ABC)
"""


"""
おみくじの結果一覧の抽象クラス
"""
pass
pass
"""
Enumを継承している
"""
AbstractOmikujiResults.register(Enum)
@dataclass
class OmikujiResult:
key: AbstractOmikujiResults
Expand Down Expand Up @@ -55,14 +58,15 @@ def test(self):
entry.test
assert reduce(lambda acc, cur: acc + cur.rate, self.entries, 0) == 1.0
assert len(filter(lambda key, value: key != value.key, self.entries)) == 0
assert len(filter(lambda key, value: key !=
value.key, self.entries)) == 0
def draw(self):
"""
おみくじを引く
"""
return choices(
population=self.entries,
population=self.entries,
weights=map(lambda entry: entry.rate, self.entries)
k=1
)[0]
Expand All @@ -71,6 +75,8 @@ def draw(self):
"""
おみくじメイン処理
"""


class OmikujiResults(AbstractOmikujiResults):
DaiKichi = auto()
ChuKichi = auto()
Expand All @@ -80,6 +86,7 @@ class OmikujiResults(AbstractOmikujiResults):
Kyo = auto()
DaiKyo = auto()


omikuji = Omikuji(entries={
OmikujiResults.DaiKichi: OmikujiResult(OmikujiResults.DaiKichi, 0.02, ":tada: 大吉 何でもうまくいく!!気がする!!"),
OmikujiResults.ChuKichi: OmikujiResult(OmikujiResults.ChuKichi, 0.2, ":smile: 中吉 そこそこうまくいくかも!?"),
Expand All @@ -90,8 +97,10 @@ class OmikujiResults(AbstractOmikujiResults):
OmikujiResults.DaiKyo: OmikujiResult(OmikujiResults.DaiKyo, 0.0025, ":crying_cat_face: 大凶 そういう時もあります……猫になって耐えましょう"),
})


def test():
omikuji.test()

def draw():


def draw():
return omikuji.draw().message
3 changes: 1 addition & 2 deletions tests/library/test_omikuji.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import unittest
from library.omikuji import AbstractOmikujiResults, OmikujiResult, Omikuji, test


class TestOmikuji(unittest.TestCase):
"""
Expand All @@ -17,7 +17,6 @@ def test_omikuji_config:
"""
test()


def test_omikuji_minimum:
"""
おみくじの実装が正常か
Expand Down

0 comments on commit d89cdfb

Please sign in to comment.