File size: 4,906 Bytes
076c3cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Adaptive Tactics - Test Runner</title>
    <style>
        body {
            font-family: 'Consolas', 'Monaco', monospace;
            background: #1a1a1a;
            color: #d4c9a8;
            padding: 20px;
        }
        h1 {
            color: #d4a84b;
        }
        .test-section {
            margin: 20px 0;
            padding: 15px;
            background: #252520;
            border: 1px solid #3a2e1a;
            border-radius: 4px;
        }
        .test-section h2 {
            color: #a89060;
            margin-top: 0;
        }
        button {
            background: #3a2e1a;
            color: #d4c9a8;
            border: 1px solid #6b5830;
            padding: 10px 20px;
            cursor: pointer;
            font-family: inherit;
            margin: 5px;
        }
        button:hover {
            background: #4a3e2a;
        }
        #output {
            white-space: pre-wrap;
            margin-top: 20px;
            padding: 15px;
            background: #0e0c0a;
            border: 1px solid #2a2016;
            max-height: 400px;
            overflow-y: auto;
        }
        .passed { color: #5a8a3a; }
        .failed { color: #8a2a2a; }
    </style>
</head>
<body>
    <h1>Adaptive Tactics Test Runner</h1>

    <div class="test-section">
        <h2>Run Tests</h2>
        <button onclick="runTests('rules')">Run Rules Tests</button>
        <button onclick="runTests('combat')">Run Combat Tests</button>
        <button onclick="runTests('ai')">Run AI Scoring Tests</button>
        <button onclick="runTests('adaptation')">Run Adaptation Tests</button>
        <button onclick="runAllTests()">Run All Tests</button>
    </div>

    <div id="output">Click a button to run tests...</div>

    <script type="module">
        import { runAllTests as runRulesTests } from './test_rules.js';
        import { runAllTests as runCombatTests } from './test_combat.js';
        import { runAllTests as runAIScoringTests } from './test_ai_scoring.js';
        import { runAllTests as runAdaptationTests } from './test_adaptation.js';

        const output = document.getElementById('output');

        // Capture console output
        const originalLog = console.log;
        const originalError = console.error;

        function captureConsole() {
            let logs = [];
            console.log = (...args) => {
                logs.push(args.join(' '));
                originalLog.apply(console, args);
            };
            console.error = (...args) => {
                logs.push('ERROR: ' + args.join(' '));
                originalError.apply(console, args);
            };
            return logs;
        }

        function restoreConsole() {
            console.log = originalLog;
            console.error = originalError;
        }

        function formatOutput(logs) {
            return logs.map(line => {
                if (line.includes('PASSED')) {
                    return `<span class="passed">${line}</span>`;
                } else if (line.includes('FAILED') || line.includes('ERROR')) {
                    return `<span class="failed">${line}</span>`;
                }
                return line;
            }).join('\n');
        }

        window.runTests = async function(type) {
            const logs = captureConsole();
            output.innerHTML = `Running ${type} tests...\n`;

            try {
                switch(type) {
                    case 'rules':
                        runRulesTests();
                        break;
                    case 'combat':
                        runCombatTests();
                        break;
                    case 'ai':
                        runAIScoringTests();
                        break;
                    case 'adaptation':
                        runAdaptationTests();
                        break;
                }
            } catch (e) {
                logs.push(`ERROR: ${e.message}`);
            }

            restoreConsole();
            output.innerHTML = formatOutput(logs);
        };

        window.runAllTests = async function() {
            const logs = captureConsole();
            output.innerHTML = 'Running all tests...\n\n';

            try {
                runRulesTests();
                logs.push('');
                runCombatTests();
                logs.push('');
                runAIScoringTests();
                logs.push('');
                runAdaptationTests();
                logs.push('\n=== ALL TEST SUITES COMPLETED ===');
            } catch (e) {
                logs.push(`ERROR: ${e.message}`);
            }

            restoreConsole();
            output.innerHTML = formatOutput(logs);
        };
    </script>
</body>
</html>