57 lines
2.0 KiB
Python
57 lines
2.0 KiB
Python
"""ガチャシステムのテスト"""
|
||
import pytest
|
||
from app.services.gacha import GachaService
|
||
from app.models.card import CardRarity
|
||
|
||
|
||
class TestGachaService:
|
||
"""GachaServiceのテストクラス"""
|
||
|
||
def test_determine_rarity_normal(self):
|
||
"""通常ガチャのレアリティ判定テスト"""
|
||
rarities = []
|
||
for _ in range(1000):
|
||
rarity = GachaService._determine_rarity(is_paid=False)
|
||
rarities.append(rarity)
|
||
|
||
# 大部分がNORMALであることを確認
|
||
normal_count = rarities.count(CardRarity.NORMAL)
|
||
assert normal_count > 900
|
||
|
||
def test_determine_rarity_paid(self):
|
||
"""課金ガチャのレアリティ判定テスト"""
|
||
rarities = []
|
||
for _ in range(1000):
|
||
rarity = GachaService._determine_rarity(is_paid=True)
|
||
rarities.append(rarity)
|
||
|
||
# 課金ガチャの方がレアが出やすいことを確認
|
||
rare_count = sum(1 for r in rarities if r != CardRarity.NORMAL)
|
||
assert rare_count > 50 # 5%以上
|
||
|
||
def test_card_id_selection(self):
|
||
"""カードID選択のテスト"""
|
||
for rarity in CardRarity:
|
||
card_id = GachaService._select_card_id(rarity)
|
||
assert 0 <= card_id <= 15
|
||
|
||
def test_cp_calculation(self):
|
||
"""CP計算のテスト"""
|
||
# 通常カード
|
||
cp_normal = GachaService._calculate_cp(0, CardRarity.NORMAL)
|
||
assert 10 <= cp_normal <= 100
|
||
|
||
# uniqueカード(5倍)
|
||
cp_unique = GachaService._calculate_cp(0, CardRarity.UNIQUE)
|
||
assert 50 <= cp_unique <= 500
|
||
|
||
@pytest.mark.asyncio
|
||
async def test_draw_card(self):
|
||
"""カード抽選の統合テスト"""
|
||
user_did = "did:plc:test123"
|
||
card, is_unique = await GachaService.draw_card(user_did, is_paid=False)
|
||
|
||
assert card.owner_did == user_did
|
||
assert 0 <= card.id <= 15
|
||
assert card.cp > 0
|
||
assert card.status in CardRarity |