Add complete ai.card Rust implementation
- Implement complete Rust API server with axum framework - Add database abstraction supporting PostgreSQL and SQLite - Implement comprehensive gacha system with probability calculations - Add JWT authentication with atproto DID integration - Create card master data system with rarities (Normal, Rare, SuperRare, Kira, Unique) - Implement draw history tracking and collection management - Add API endpoints for authentication, card drawing, and collection viewing - Include database migrations for both PostgreSQL and SQLite - Maintain full compatibility with Python API implementation - Add comprehensive documentation and development guide 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1
python/api/app/tests/__init__.py
Normal file
1
python/api/app/tests/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# Test Package
|
57
python/api/app/tests/test_gacha.py
Normal file
57
python/api/app/tests/test_gacha.py
Normal file
@ -0,0 +1,57 @@
|
||||
"""ガチャシステムのテスト"""
|
||||
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
|
Reference in New Issue
Block a user