-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_tests_fixed.py
More file actions
427 lines (340 loc) · 15.7 KB
/
run_tests_fixed.py
File metadata and controls
427 lines (340 loc) · 15.7 KB
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
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
"""
COM Framework Test Runner with Fixed Modules
This script runs the test suite for the COM Framework using the fixed modules.
"""
import unittest
import sys
import os
import time
from datetime import datetime
# Add the current directory to the path
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
# Import the fixed modules
from com_framework_core_fixed import LZModule, OctaveModule
from com_visualization_fixed import VisualizationModule
from com_analysis_fixed import (
MathematicalAnalysisModule,
PatternRecognitionModule,
StatisticalAnalysisModule
)
class TestLZModule(unittest.TestCase):
"""Test cases for the LZ Module."""
def setUp(self):
"""Set up test fixtures."""
self.lz_module = LZModule()
def test_lz_constant(self):
"""Test that the LZ constant is correctly defined."""
self.assertAlmostEqual(self.lz_module.LZ, 1.23498, places=5)
def test_recursive_wave_function(self):
"""Test the recursive wave function."""
# Test with known values
self.assertAlmostEqual(
self.lz_module.recursive_wave_function(0),
0 + 1, # sin(0) + e^0
places=5
)
self.assertAlmostEqual(
self.lz_module.recursive_wave_function(1),
np.sin(1) + np.exp(-1),
places=5
)
def test_derive_lz(self):
"""Test LZ derivation through iteration."""
# Derive LZ from different starting points
for start in [0.5, 1.0, 1.5, 2.0]:
derived_lz, sequence, iterations = self.lz_module.derive_lz(
initial_value=start,
max_iterations=100,
precision=1e-6
)
# Check that it converges to LZ
self.assertAlmostEqual(derived_lz, self.lz_module.LZ, places=4)
# Check that sequence has correct length
self.assertEqual(len(sequence), iterations + 1)
# Check that sequence starts with initial value
self.assertEqual(sequence[0], start)
# Check that sequence ends with derived LZ
self.assertAlmostEqual(sequence[-1], derived_lz, places=4)
def test_verify_lz(self):
"""Test verification that LZ is a fixed point."""
self.assertTrue(self.lz_module.verify_lz())
def test_stability_at_point(self):
"""Test stability calculation at various points."""
# LZ should be stable (derivative magnitude < 1)
self.assertLess(self.lz_module.stability_at_point(self.lz_module.LZ), 1)
# Test a known unstable point
self.assertGreater(self.lz_module.stability_at_point(0), 1)
def test_is_stable_fixed_point(self):
"""Test stable fixed point detection."""
# LZ should be a stable fixed point
self.assertTrue(self.lz_module.is_stable_fixed_point(self.lz_module.LZ))
# 0 is a fixed point of sin(x) + e^(-x) but not stable
self.assertFalse(self.lz_module.is_stable_fixed_point(0))
def test_lz_scaling(self):
"""Test LZ-based scaling."""
# Test scaling with different octaves
base_value = 1.0
for octave in range(-3, 4):
scaled = self.lz_module.lz_scaling(base_value, octave)
expected = base_value * (self.lz_module.LZ ** octave)
self.assertAlmostEqual(scaled, expected, places=5)
def test_find_fixed_points(self):
"""Test finding fixed points in a range."""
# Find fixed points in [0, 5]
fixed_points = self.lz_module.find_fixed_points(0, 5, 0.01)
# Should find at least LZ
self.assertGreaterEqual(len(fixed_points), 1)
# LZ should be in the list
self.assertTrue(any(abs(fp - self.lz_module.LZ) < 0.01 for fp in fixed_points))
# All points should be fixed points
for fp in fixed_points:
self.assertAlmostEqual(
self.lz_module.recursive_wave_function(fp),
fp,
places=2
)
def test_plot_recursive_function(self):
"""Test plotting the recursive function."""
fig = self.lz_module.plot_recursive_function()
self.assertIsNotNone(fig)
plt.close(fig)
def test_plot_convergence(self):
"""Test plotting convergence to LZ."""
fig = self.lz_module.plot_convergence()
self.assertIsNotNone(fig)
plt.close(fig)
def test_stability_analysis(self):
"""Test stability analysis plotting."""
fig = self.lz_module.stability_analysis()
self.assertIsNotNone(fig)
plt.close(fig)
def test_hqs_threshold_function(self):
"""Test HQS threshold function."""
# Below threshold should return 0
self.assertEqual(
self.lz_module.hqs_threshold_function(0),
0
)
# Above threshold should return 1
self.assertEqual(
self.lz_module.hqs_threshold_function(2 * np.pi * self.lz_module.HQS + 0.1),
1
)
def test_recursive_hqs(self):
"""Test recursive HQS function."""
# Test with various phase differences
phase_diffs = [0, np.pi/4, np.pi/2, np.pi, 2*np.pi]
results = self.lz_module.recursive_hqs(phase_diffs, depth=3)
# Should return a list of the same length
self.assertEqual(len(results), len(phase_diffs))
# All values should be between 0 and 1
for result in results:
self.assertGreaterEqual(result, 0)
self.assertLessEqual(result, 1)
class TestOctaveModule(unittest.TestCase):
"""Test cases for the Octave Module."""
def setUp(self):
"""Set up test fixtures."""
self.lz_module = LZModule()
self.octave_module = OctaveModule(self.lz_module)
def test_octave_reduction(self):
"""Test octave reduction function."""
# Test known values
test_cases = [
(0, 9), # 0 -> 9
(1, 1), # 1 -> 1
(9, 9), # 9 -> 9
(10, 1), # 10 -> 1
(27, 9), # 27 -> 9
(123, 6) # 123 -> 6
]
for input_val, expected in test_cases:
self.assertEqual(
self.octave_module.octave_reduction(input_val),
expected
)
def test_octave_reduction_sequence(self):
"""Test octave reduction on a sequence."""
sequence = [1, 2, 3, 10, 11, 12, 19, 20, 21]
expected = [1, 2, 3, 1, 2, 3, 1, 2, 3]
result = self.octave_module.octave_reduction_sequence(sequence)
self.assertEqual(result, expected)
def test_lz_based_octave(self):
"""Test LZ-based octave mapping."""
# Test with powers of LZ
for i in range(-3, 4):
value = self.lz_module.LZ ** i
octave = self.octave_module.lz_based_octave(value)
# Should be between 0 and 1
self.assertGreaterEqual(octave, 0)
self.assertLess(octave, 1)
def test_collatz_octave_transform(self):
"""Test Collatz-Octave transformation."""
# Test with known starting values
n = 27
key = 1
steps = 20
result = self.octave_module.collatz_octave_transform(n, key, steps)
# Should return a list
self.assertIsInstance(result, list)
# All values should be octaves (1-9)
for val in result:
self.assertGreaterEqual(val, 1)
self.assertLessEqual(val, 9)
# Different keys should produce different results
result2 = self.octave_module.collatz_octave_transform(n, key + 1, steps)
self.assertNotEqual(result, result2)
def test_octave_distribution(self):
"""Test octave distribution calculation."""
sequence = list(range(1, 100))
distribution = self.octave_module.octave_distribution(sequence)
# Should return a dictionary with keys 1-9
self.assertIsInstance(distribution, dict)
for i in range(1, 10):
self.assertIn(i, distribution)
# Sum of counts should equal length of sequence
self.assertEqual(sum(distribution.values()), len(sequence))
def test_plot_octave_distribution(self):
"""Test plotting octave distribution."""
sequence = list(range(1, 100))
fig = self.octave_module.plot_octave_distribution(sequence)
self.assertIsNotNone(fig)
plt.close(fig)
class TestVisualizationModule(unittest.TestCase):
"""Test cases for the Visualization Module."""
def setUp(self):
"""Set up test fixtures."""
self.lz_module = LZModule()
self.octave_module = OctaveModule(self.lz_module)
self.viz_module = VisualizationModule(self.lz_module, self.octave_module)
def test_create_dashboard(self):
"""Test dashboard creation."""
fig = self.viz_module.create_dashboard()
self.assertIsNotNone(fig)
plt.close(fig)
def test_create_energy_pattern_visualization(self):
"""Test energy pattern visualization."""
# Use smaller size for faster testing
fig = self.viz_module.create_energy_pattern_visualization(size=50, iterations=5)
self.assertIsNotNone(fig)
plt.close(fig)
def test_create_cryptographic_visualization(self):
"""Test cryptographic visualization."""
fig = self.viz_module.create_cryptographic_visualization(text="TEST")
self.assertIsNotNone(fig)
plt.close(fig)
def test_create_interactive_lz_explorer(self):
"""Test interactive LZ explorer."""
fig = self.viz_module.create_interactive_lz_explorer()
self.assertIsNotNone(fig)
plt.close(fig)
def test_create_lz_convergence_animation(self):
"""Test LZ convergence animation."""
anim = self.viz_module.create_lz_convergence_animation(
initial_values=[0.5, 1.0, 1.5],
max_iterations=10
)
self.assertIsNotNone(anim)
plt.close(anim._fig)
def test_save_all_visualizations(self):
"""Test saving all visualizations."""
with tempfile.TemporaryDirectory() as temp_dir:
file_paths = self.viz_module.save_all_visualizations(temp_dir)
# Should return a dictionary with file paths
self.assertIsInstance(file_paths, dict)
# All files should exist
for path in file_paths.values():
self.assertTrue(os.path.exists(path))
class TestMathematicalAnalysisModule(unittest.TestCase):
"""Test cases for the Mathematical Analysis Module."""
def setUp(self):
"""Set up test fixtures."""
self.lz_module = LZModule()
self.octave_module = OctaveModule(self.lz_module)
self.math_module = MathematicalAnalysisModule(self.lz_module, self.octave_module)
def test_analyze_fixed_points(self):
"""Test fixed points analysis."""
# Use smaller range for faster testing
results = self.math_module.analyze_fixed_points(0, 3, 0.1)
# Should return a dictionary with expected keys
self.assertIsInstance(results, dict)
expected_keys = ['fixed_points', 'count', 'stability', 'basin_sizes', 'convergence_rates']
for key in expected_keys:
self.assertIn(key, results)
# Should find at least one fixed point (LZ)
self.assertGreaterEqual(results['count'], 1)
def test_analyze_lz_powers(self):
"""Test LZ powers analysis."""
results = self.math_module.analyze_lz_powers(max_power=5)
# Should return a dictionary with expected keys
self.assertIsInstance(results, dict)
expected_keys = ['powers', 'octaves', 'pattern_length', 'ratios']
for key in expected_keys:
self.assertIn(key, results)
# Powers list should have correct length
self.assertEqual(len(results['powers']), 11) # -5 to 5
def test_analyze_octave_distribution(self):
"""Test octave distribution analysis."""
# Use smaller range for faster testing
results = self.math_module.analyze_octave_distribution(1, 100)
# Should return a dictionary with expected keys
self.assertIsInstance(results, dict)
expected_keys = ['counts', 'chi2_stat', 'p_value', 'is_uniform', 'autocorrelation']
for key in expected_keys:
self.assertIn(key, results)
# Counts should include all octaves
for i in range(1, 10):
self.assertIn(i, results['counts'])
def test_analyze_collatz_octave_properties(self):
"""Test Collatz-Octave properties analysis."""
# Use smaller range for faster testing
results = self.math_module.analyze_collatz_octave_properties(max_n=20)
# Should return a dictionary with expected keys
self.assertIsInstance(results, dict)
expected_keys = ['cycle_lengths', 'sequence_lengths', 'unique_octaves', 'entropy']
for key in expected_keys:
self.assertIn(key, results)
# Lists should have correct length
self.assertEqual(len(results['cycle_lengths']), 20)
def test_analyze_lz_hqs_relationship(self):
"""Test LZ-HQS relationship analysis."""
# Use fewer points for faster testing
results = self.math_module.analyze_lz_hqs_relationship(points=100)
# Should return a dictionary with expected keys
self.assertIsInstance(results, dict)
expected_keys = ['x_values', 'f_values', 'derivatives', 'stability_crossings', 'hqs_values']
for key in expected_keys:
self.assertIn(key, results)
# Lists should have correct length
self.assertEqual(len(results['x_values']), 100)
def test_analyze_octave_scaling(self):
"""Test octave scaling analysis."""
results = self.math_module.analyze_octave_scaling()
# Should return a dictionary with expected keys
self.assertIsInstance(results, dict)
expected_keys = ['scaled_values', 'ratios', 'octave_values', 'pattern_length']
for key in expected_keys:
self.assertIn(key, results)
# Lists should have correct length
self.assertEqual(len(results['scaled_values']), 8)
self.assertEqual(len(results['ratios']), 7)
class TestPatternRecognitionModule(unittest.TestCase):
"""Test cases for the Pattern Recognition Module."""
def setUp(self):
"""Set up test fixtures."""
self.lz_module = LZModule()
self.octave_module = OctaveModule(self.lz_module)
self.pattern_module = PatternRecognitionModule(self.lz_module, self.octave_module)
def test_detect_octave_patterns(self):
"""Test octave pattern detection."""
# Create a sequence with known patterns
data = [1, 2, 3, 1, 2, 3, 4, 5, 6, 4, 5, 6]
results = self.pattern_module.detect_octave_patterns(data)
# Should return a dictionary with expected keys
self.assertIsInstance(results, dict)
expected_keys = ['octaves', 'patterns', 'frequency_distribution', 'transition_matrix', 'rhythm']
for key in expected_keys:
self.assertIn(key, results)
# Should detect at least one pattern
self.assertGreaterEqual(len(re
(Content truncated due to size limit. Use line ranges to read in chunks)