Spaces:
Runtime error
Runtime error
neoai-kterasawa
commited on
Commit
·
3f90d06
1
Parent(s):
e656870
test追加
Browse files- tests/model/test_choice.py +10 -0
- tests/model/test_choice_with_bet.py +16 -0
- tests/model/test_choices.py +56 -0
- tests/model/test_choices_with_bet.py +51 -0
- tests/test_func.py +0 -22
tests/model/test_choice.py
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pytest # noqa
|
2 |
+
|
3 |
+
from src.model.choice import Choice
|
4 |
+
|
5 |
+
|
6 |
+
class TestChoice:
|
7 |
+
def test_init(self) -> None:
|
8 |
+
choice = Choice(name="test", odds=1.1)
|
9 |
+
assert choice.name == "test"
|
10 |
+
assert choice.odds == 1.1
|
tests/model/test_choice_with_bet.py
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from src.model.choice import ChoiceWithBet
|
2 |
+
|
3 |
+
choice_with_bet = ChoiceWithBet(name="test", odds=1.1, bet_amount=100)
|
4 |
+
|
5 |
+
|
6 |
+
class TestChoiceWithBet:
|
7 |
+
def test_init(self) -> None:
|
8 |
+
assert choice_with_bet.name == "test"
|
9 |
+
assert choice_with_bet.odds == 1.1
|
10 |
+
assert choice_with_bet.bet_amount == 100
|
11 |
+
|
12 |
+
def test_pay_back(self) -> None:
|
13 |
+
assert choice_with_bet.pay_back == 110
|
14 |
+
|
15 |
+
def test_profit(self) -> None:
|
16 |
+
assert choice_with_bet.profit == 10
|
tests/model/test_choices.py
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pytest # noqa
|
2 |
+
|
3 |
+
from src.model.choice import Choice, Choices
|
4 |
+
|
5 |
+
|
6 |
+
class TestChoices:
|
7 |
+
def test_ensure_at_least_one_choice(self) -> None:
|
8 |
+
with pytest.raises(ValueError):
|
9 |
+
Choices(root=[])
|
10 |
+
|
11 |
+
def test_from_text(self) -> None:
|
12 |
+
assert Choices.from_text(
|
13 |
+
"オッズを見て個別に選択全選択全解除\n"
|
14 |
+
"選択\n"
|
15 |
+
"1\n"
|
16 |
+
" \n"
|
17 |
+
"1\n"
|
18 |
+
"675.5\n"
|
19 |
+
"1\n"
|
20 |
+
"\n"
|
21 |
+
"2\n"
|
22 |
+
"93.7"
|
23 |
+
).root == [
|
24 |
+
Choice(name="1-1", odds=675.5),
|
25 |
+
Choice(name="1-2", odds=93.7),
|
26 |
+
]
|
27 |
+
|
28 |
+
assert Choices.from_text("\n" "1\n" "\n" "2\n" "1778.5\n").root == [
|
29 |
+
Choice(name="1-2", odds=1778.5),
|
30 |
+
]
|
31 |
+
|
32 |
+
assert Choices.from_text(
|
33 |
+
"1\n"
|
34 |
+
"\n"
|
35 |
+
"2\n"
|
36 |
+
"\n"
|
37 |
+
"3\n"
|
38 |
+
"5688.9\n"
|
39 |
+
"1\n"
|
40 |
+
"\n"
|
41 |
+
"2\n"
|
42 |
+
"\n"
|
43 |
+
"4\n"
|
44 |
+
"9239.1\n"
|
45 |
+
"1\n"
|
46 |
+
"\n"
|
47 |
+
"3\n"
|
48 |
+
"\n"
|
49 |
+
"4\n"
|
50 |
+
"18619.1\n"
|
51 |
+
).root == [
|
52 |
+
Choice(name="1-2-3", odds=5688.9),
|
53 |
+
Choice(name="1-2-4", odds=9239.1),
|
54 |
+
Choice(name="1-3-4", odds=18619.1),
|
55 |
+
]
|
56 |
+
# TODO: モバイル
|
tests/model/test_choices_with_bet.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pytest # noqa
|
2 |
+
|
3 |
+
from src.model.choice import Choice, Choices, ChoicesWithBet, ChoiceWithBet
|
4 |
+
|
5 |
+
ChoiceWithBetTable = list[tuple[str, float, int, int]]
|
6 |
+
|
7 |
+
choices = Choices(
|
8 |
+
root=[
|
9 |
+
Choice(name="test", odds=2.0),
|
10 |
+
Choice(name="test", odds=4.0),
|
11 |
+
]
|
12 |
+
)
|
13 |
+
choices_with_bet = ChoicesWithBet(
|
14 |
+
root=[
|
15 |
+
ChoiceWithBet(name="test", odds=2.0, bet_amount=6000),
|
16 |
+
ChoiceWithBet(name="test", odds=4.0, bet_amount=3000),
|
17 |
+
]
|
18 |
+
)
|
19 |
+
|
20 |
+
|
21 |
+
class TestChoicesWithBet:
|
22 |
+
def test_from_choice(self) -> None:
|
23 |
+
assert (
|
24 |
+
ChoicesWithBet.from_choices(choices, 9000).model_dump()
|
25 |
+
== choices_with_bet.model_dump()
|
26 |
+
)
|
27 |
+
|
28 |
+
def test_to_summary_markdwown(self) -> None:
|
29 |
+
# assert choices_with_bet.to_summary_markdwown() == (
|
30 |
+
# "**点数**: 2 点<br>" "**購入額**: ¥ 9,000<br>" "**回収率**: 133%"
|
31 |
+
# )
|
32 |
+
assert choices_with_bet.to_summary_markdwown() == (
|
33 |
+
"**点数**: 2点<br>"
|
34 |
+
"**購入/払戻**: ¥9,000 → ¥12,000 (+3,000)<br>"
|
35 |
+
"**回収率**: 133%"
|
36 |
+
)
|
37 |
+
|
38 |
+
def test_to_table(self) -> None:
|
39 |
+
assert choices_with_bet.to_table() == [
|
40 |
+
("test", 2.0, 6000, 12000),
|
41 |
+
("test", 4.0, 3000, 12000),
|
42 |
+
]
|
43 |
+
|
44 |
+
def test_total_bet_amount(self) -> None:
|
45 |
+
assert choices_with_bet.total_bet_amount == 9000
|
46 |
+
|
47 |
+
def test_average_pay_back(self) -> None:
|
48 |
+
assert choices_with_bet.average_pay_back == 12000
|
49 |
+
|
50 |
+
def test_average_profit(self) -> None:
|
51 |
+
assert choices_with_bet.average_profit == 3000
|
tests/test_func.py
DELETED
@@ -1,22 +0,0 @@
|
|
1 |
-
from src.func import calculate
|
2 |
-
|
3 |
-
|
4 |
-
def test_calculate():
|
5 |
-
assert (
|
6 |
-
calculate(
|
7 |
-
10000,
|
8 |
-
(
|
9 |
-
"オッズを見て個別に選択全選択全解除\n"
|
10 |
-
"選択\n"
|
11 |
-
"1\n"
|
12 |
-
" \n"
|
13 |
-
"1\n"
|
14 |
-
"675.5\n"
|
15 |
-
"1\n"
|
16 |
-
"\n"
|
17 |
-
"2\n"
|
18 |
-
"93.7"
|
19 |
-
),
|
20 |
-
)
|
21 |
-
== []
|
22 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|