Spaces:
Running
Running
File size: 5,277 Bytes
bb3fbf9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
import json
import engine_rust
def test_live_cards_added_to_deck_rust():
"""
Regression Test (Rust Engine): Verify that Live Cards passed to initialize_game
are actually added to the player's deck in the Rust implementation.
"""
# 1. Create minimal DB JSON matching Rust struct keys EXACTLY
db_json = {
"member_db": {
"1": {
"card_id": 1,
"card_no": "M001",
"name": "Test Member",
"cost": 1,
"hearts": [0, 0, 0, 0, 0, 0, 0],
"blade_hearts": [0, 0, 0, 0, 0, 0, 0],
"blades": 1,
"groups": [],
"units": [],
"abilities": [],
"volume_icons": 0,
"draw_icons": 0,
# Optional fields with default
"ability_text": "",
"char_id": 0,
"img_path": "",
}
},
"live_db": {
"10001": {
"card_id": 10001,
"card_no": "L001",
"name": "Live 1",
"score": 1,
"required_hearts": [0, 0, 0, 0, 0, 0, 0],
"burst_locks": [
0,
0,
0,
0,
0,
0,
0,
], # Rust might not have this? Checked logic.rs, it does NOT have burst_locks in LiveCard struct.
# Wait, wait. Let's re-verify LiveCard struct in logic.rs.
# 214: pub struct LiveCard {
# ...
# 225: #[serde(default)] rare, ability_text, img_path
# It accepts: card_id, card_no, name, score, required_hearts, abilities, groups, units, volume_icons, blade_hearts.
# "burst_locks" NOT present in logic.rs line 214-230.
"abilities": [],
"groups": [],
"units": [],
"volume_icons": 0,
"blade_hearts": [0, 0, 0, 0, 0, 0, 0],
"rare": "N",
"ability_text": "",
"img_path": "",
}
},
"energy_db": {
"20001": {"id": 20001, "card_id": 20001} # Energy might just be ID?
# Checking EnergyCard in logic.rs? It wasn't in the snippet.
# Assuming simple struct or just ID mapping.
# Logic.rs: pub const ENERGY_ID_OFFSET = 20000;
# CardDatabase struct: members, lives. DOES NOT HAVE energy_db?
# Logic.rs: struct CardDatabase { members: HashMap<u32, MemberCard>, lives: HashMap<u32, LiveCard> }
# It does NOT store energy cards explicitly?
# But from_json might ignore extra fields?
},
}
# Rust CardDatabase struct in logic.rs lines 378+ DEFINITELY only has members and lives fields.
# But from_json might read energy_db?
# Logic.rs: let data: serde_json::Value = serde_json::from_str(json_str)?;
# It parses member_db and live_db.
# It seems to ignore energy_db.
db_str = json.dumps(db_json)
db = engine_rust.PyCardDatabase(db_str)
game = engine_rust.PyGameState(db)
# Official sizes
members = [1] * 48
lives = [10001] * 12
energy = [20001] * 12
# Passing explicit lives
game.initialize_game(
members, # p0 deck
members, # p1 deck
energy, # p0 energy
energy, # p1 energy
lives, # p0 lives (Should be added to deck)
lives, # p1 lives
)
p0 = game.get_player(0)
assert p0.deck_count + len(p0.hand) == 60, "Total cards count mismatch"
def test_can_draw_live_card_rust():
# Similar fix for second test
db_json = {
"member_db": {
"1": {
"card_id": 1,
"card_no": "M001",
"name": "Test Member",
"cost": 1,
"hearts": [0] * 7,
"blade_hearts": [0] * 7,
"blades": 1,
"groups": [],
"units": [],
"abilities": [],
"volume_icons": 0,
"draw_icons": 0,
}
},
"live_db": {
"10001": {
"card_id": 10001,
"card_no": "L001",
"name": "Live 1",
"score": 1,
"required_hearts": [0] * 7,
"blade_hearts": [0] * 7,
"abilities": [],
"groups": [],
"units": [],
"volume_icons": 0,
}
},
}
db = engine_rust.PyCardDatabase(json.dumps(db_json))
game = engine_rust.PyGameState(db)
# Official sizes
members = [1] * 48
lives = [10001] * 12
energy = [20001] * 12
game.initialize_game(members, members, energy, energy, lives, lives)
p0 = game.get_player(0)
# Check hand + main deck for the live card
# Total cards = 60.
assert p0.deck_count + len(p0.hand) == 60, "Total cards count mismatch"
|