File size: 13,410 Bytes
4c75d73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6c6097e
4c75d73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6c6097e
4c75d73
 
 
6c6097e
4c75d73
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
#!/usr/bin/env python3
"""

Test Data Generators and Fixtures



Provides reusable test data for the MMORPG test suite.

"""

import random
import string
from typing import Dict, List, Any, Optional
from datetime import datetime, timedelta
from dataclasses import dataclass


class TestDataGenerator:
    """Generates test data for MMORPG components."""
    
    @staticmethod
    def random_string(length: int = 10) -> str:
        """Generate a random string of specified length."""
        return ''.join(random.choices(string.ascii_letters + string.digits, k=length))
    
    @staticmethod
    def random_player_name() -> str:
        """Generate a random player name."""
        prefixes = ["Hero", "Knight", "Mage", "Warrior", "Rogue", "Paladin", "Archer"]
        suffixes = ["Bold", "Swift", "Wise", "Strong", "Brave", "Noble", "Quick"]
        return f"{random.choice(prefixes)}{random.choice(suffixes)}{random.randint(1, 999)}"
    
    @staticmethod
    def random_coordinates() -> Dict[str, int]:
        """Generate random valid coordinates."""
        return {
            "x": random.randint(10, 790),
            "y": random.randint(10, 590)
        }
    
    @staticmethod
    def create_player_data(

        name: Optional[str] = None,

        player_type: str = "human",

        level: Optional[int] = None,

        **kwargs

    ) -> Dict[str, Any]:
        """Create test player data."""
        coords = TestDataGenerator.random_coordinates()
        
        data = {
            "name": name or TestDataGenerator.random_player_name(),
            "type": player_type,
            "level": level or random.randint(1, 10),
            "x": coords["x"],
            "y": coords["y"],
            "health": random.randint(80, 100),
            "max_health": 100,
            "experience": random.randint(0, 100),
            "gold": random.randint(0, 500),
            "session_hash": TestDataGenerator.random_string(32),
            "joined_at": datetime.now().isoformat(),
            **kwargs
        }
        
        return data
    
    @staticmethod
    def create_npc_data(

        npc_id: Optional[str] = None,

        name: Optional[str] = None,

        **kwargs

    ) -> Dict[str, Any]:
        """Create test NPC data."""
        coords = TestDataGenerator.random_coordinates()
        
        npc_types = [
            {"char": "🏪", "name": "Trader", "personality": "merchant"},
            {"char": "🛡️", "name": "Guard", "personality": "protective"},
            {"char": "🧙", "name": "Wizard", "personality": "mysterious"},
            {"char": "📮", "name": "Mailbox", "personality": "neutral"}
        ]
        
        npc_type = random.choice(npc_types)
        
        data = {
            "id": npc_id or f"npc_{TestDataGenerator.random_string(8)}",
            "name": name or f"{npc_type['name']} {TestDataGenerator.random_string(4)}",
            "char": npc_type["char"],
            "x": coords["x"],
            "y": coords["y"],
            "personality": npc_type["personality"],
            "health": 100,
            "level": random.randint(5, 20),
            **kwargs
        }
        
        return data
    
    @staticmethod
    def create_chat_message(

        sender: Optional[str] = None,

        message_type: str = "public",

        **kwargs

    ) -> Dict[str, Any]:
        """Create test chat message data."""
        messages = [
            "Hello everyone!",
            "How is everyone doing?",
            "Nice weather today!",
            "Anyone want to trade?",
            "Looking for a party!",
            "This game is awesome!",
            "Where can I find the merchant?",
            "Thanks for the help!"
        ]
        
        data = {
            "sender": sender or TestDataGenerator.random_player_name(),
            "message": random.choice(messages),
            "type": message_type,
            "timestamp": datetime.now().isoformat(),
            **kwargs
        }
        
        if message_type == "private":
            data["recipient"] = TestDataGenerator.random_player_name()
        
        return data
    
    @staticmethod
    def create_plugin_data(

        plugin_id: Optional[str] = None,

        **kwargs

    ) -> Dict[str, Any]:
        """Create test plugin data."""
        plugin_types = ["trading", "weather", "chat", "npc", "utility"]
        
        data = {
            "id": plugin_id or f"plugin_{TestDataGenerator.random_string(8)}",
            "name": f"Test {random.choice(plugin_types).title()} Plugin",
            "version": f"{random.randint(1, 3)}.{random.randint(0, 9)}.{random.randint(0, 9)}",
            "type": random.choice(plugin_types),
            "active": random.choice([True, False]),
            "dependencies": [],
            "config": {},
            **kwargs
        }
        
        return data


class TestScenarios:
    """Predefined test scenarios for complex testing."""
    
    @staticmethod
    def multiplayer_scenario(player_count: int = 3) -> Dict[str, Any]:
        """Create a multiplayer test scenario."""
        players = []
        for i in range(player_count):
            player_data = TestDataGenerator.create_player_data(
                name=f"Player{i+1}",
                level=i+1
            )
            players.append(player_data)
        
        npcs = []
        for i in range(2):
            npc_data = TestDataGenerator.create_npc_data()
            npcs.append(npc_data)
        
        chat_messages = []
        for i in range(5):
            message = TestDataGenerator.create_chat_message(
                sender=random.choice(players)["name"]
            )
            chat_messages.append(message)
        
        return {
            "players": players,
            "npcs": npcs,
            "chat_messages": chat_messages,
            "world_size": {"width": 800, "height": 600}
        }
    
    @staticmethod
    def private_chat_scenario() -> Dict[str, Any]:
        """Create a private chat test scenario."""
        player1 = TestDataGenerator.create_player_data(name="Alice")
        player2 = TestDataGenerator.create_player_data(name="Bob")
        
        # Position players near each other
        player2["x"] = player1["x"] + 30
        player2["y"] = player1["y"] + 20
        
        private_messages = [
            {
                "sender": "Alice",
                "recipient": "Bob", 
                "message": "Hey, want to team up?",
                "type": "private",
                "timestamp": (datetime.now() - timedelta(minutes=2)).isoformat()
            },
            {
                "sender": "Bob",
                "recipient": "Alice",
                "message": "Sure! Let's go to the forest.",
                "type": "private", 
                "timestamp": (datetime.now() - timedelta(minutes=1)).isoformat()
            }
        ]
        
        return {
            "players": [player1, player2],
            "private_messages": private_messages,
            "proximity_range": 50
        }
    
    @staticmethod
    def npc_interaction_scenario() -> Dict[str, Any]:
        """Create an NPC interaction test scenario."""
        player = TestDataGenerator.create_player_data(name="TestHero")
        
        # Create Donald the Trader NPC
        donald_npc = {
            "id": "donald_trader",
            "name": "Donald the Trader",
            "char": "🏪",
            "x": player["x"] + 25,  # Near the player
            "y": player["y"] + 15,
            "personality": "trump_like",
            "health": 100,
            "level": 10,
            "inventory": ["sword", "shield", "potion"],
            "responses": {
                "greeting": "Welcome to my tremendous store! The best deals, believe me!",
                "trade": "You want to make a deal? I make the best deals!",
                "goodbye": "Come back soon! Nobody has better stuff than me!"
            }
        }
        
        # Create interaction sequence
        interactions = [
            {"player": "Hello", "expected_response": "greeting"},
            {"player": "I want to trade", "expected_response": "trade"},
            {"player": "Goodbye", "expected_response": "goodbye"}
        ]
        
        return {
            "player": player,
            "npc": donald_npc,
            "interactions": interactions,
            "interaction_range": 50
        }
    
    @staticmethod
    def plugin_system_scenario() -> Dict[str, Any]:
        """Create a plugin system test scenario."""
        plugins = [
            TestDataGenerator.create_plugin_data(
                plugin_id="trading_system",
                name="Trading System",
                type="trading",
                active=True
            ),
            TestDataGenerator.create_plugin_data(
                plugin_id="weather_service",
                name="Weather Service", 
                type="weather",
                active=True,
                dependencies=["http_client"]
            ),
            TestDataGenerator.create_plugin_data(
                plugin_id="chat_enhancer",
                name="Chat Enhancer",
                type="chat",
                active=False
            )
        ]
        
        plugin_events = [
            {"type": "load", "plugin_id": "trading_system", "timestamp": datetime.now().isoformat()},
            {"type": "activate", "plugin_id": "trading_system", "timestamp": datetime.now().isoformat()},
            {"type": "load", "plugin_id": "weather_service", "timestamp": datetime.now().isoformat()},
            {"type": "error", "plugin_id": "chat_enhancer", "error": "Dependency not found", "timestamp": datetime.now().isoformat()}
        ]
        
        return {
            "plugins": plugins,
            "events": plugin_events,
            "expected_active": 2,
            "expected_errors": 1
        }
    
    @staticmethod
    def performance_test_scenario() -> Dict[str, Any]:
        """Create a performance testing scenario."""
        # Large number of players for load testing
        players = []
        for i in range(20):
            player = TestDataGenerator.create_player_data(
                name=f"LoadTestPlayer{i+1}",
                player_type="ai_agent" if i % 3 == 0 else "human"
            )
            players.append(player)
        
        # Many chat messages
        chat_messages = []
        for i in range(100):
            message = TestDataGenerator.create_chat_message(
                sender=random.choice(players)["name"]
            )
            chat_messages.append(message)
        
        # Multiple NPCs
        npcs = []
        for i in range(10):
            npc = TestDataGenerator.create_npc_data()
            npcs.append(npc)
        
        return {
            "players": players,
            "chat_messages": chat_messages,
            "npcs": npcs,
            "expected_max_response_time": 200,  # milliseconds
            "expected_max_memory": 512  # MB
        }


# Predefined test data sets
SAMPLE_PLAYERS = [
    TestDataGenerator.create_player_data(name="Alice", level=5, x=100, y=100),
    TestDataGenerator.create_player_data(name="Bob", level=3, x=200, y=150),
    TestDataGenerator.create_player_data(name="Charlie", level=7, x=300, y=200, player_type="ai_agent")
]

SAMPLE_NPCS = [
    TestDataGenerator.create_npc_data(npc_id="merchant1", name="Friendly Trader", char="🏪"),
    TestDataGenerator.create_npc_data(npc_id="guard1", name="Town Guard", char="🛡️"),
    TestDataGenerator.create_npc_data(npc_id="wizard1", name="Mysterious Wizard", char="🧙")
]

SAMPLE_CHAT_MESSAGES = [
    TestDataGenerator.create_chat_message(sender="Alice", message="Hello everyone!"),
    TestDataGenerator.create_chat_message(sender="Bob", message="How is everyone?"),
    TestDataGenerator.create_chat_message(sender="Alice", message="Secret message", message_type="private", recipient="Bob")
]

SAMPLE_PLUGINS = [
    TestDataGenerator.create_plugin_data(plugin_id="core_trading", name="Core Trading System", active=True),
    TestDataGenerator.create_plugin_data(plugin_id="weather_api", name="Weather API", active=True),
    TestDataGenerator.create_plugin_data(plugin_id="test_plugin", name="Test Plugin", active=False)
]


class TestingConstants:
    """Constants used in testing."""
    
    # World dimensions
    WORLD_WIDTH = 800
    WORLD_HEIGHT = 600
    
    # Player limits
    MAX_PLAYERS = 20
    MIN_HEALTH = 0
    MAX_HEALTH = 100
    
    # Performance thresholds
    MAX_RESPONSE_TIME_MS = 200
    MAX_MEMORY_MB = 512
    MAX_CPU_PERCENT = 50
    
    # Proximity ranges
    INTERACTION_RANGE = 50
    CHAT_RANGE = 100
    
    # Test timeouts
    DEFAULT_TIMEOUT = 5.0
    LONG_TIMEOUT = 30.0
    SHORT_TIMEOUT = 1.0


# Export commonly used items
__all__ = [
    'TestDataGenerator',
    'TestScenarios',    'SAMPLE_PLAYERS',
    'SAMPLE_NPCS',
    'SAMPLE_CHAT_MESSAGES',
    'SAMPLE_PLUGINS',
    'TestingConstants'
]