Files
becomingone/tests/test_transducers.py
T

121 lines
3.8 KiB
Python
Raw Normal View History

2026-05-27 18:53:41 +00:00
import pytest
2026-02-19 05:46:51 +00:00
"""
Tests for BecomingONE Transducers and Sync Layer
Tests Master/Emissary transducers and synchronization layer.
"""
import unittest
2026-02-19 09:18:39 +00:00
from becomingone import MasterTransducer, EmissaryTransducer, SynchronizationLayer
from becomingone.transducers.master import MasterConfig
from becomingone.transducers.emissary import EmissaryConfig
from becomingone.sync import SyncConfig
2026-02-19 05:46:51 +00:00
class TestMasterTransducer(unittest.TestCase):
"""Tests for the Master transducer."""
2026-05-27 18:53:41 +00:00
@pytest.mark.asyncio
async def test_instantiate(self):
2026-02-19 09:18:39 +00:00
"""Test Master can be instantiated."""
master = MasterTransducer()
self.assertIsNotNone(master)
self.assertEqual(master.coherence, 1.0)
2026-05-27 18:53:41 +00:00
@pytest.mark.asyncio
async def test_properties(self):
2026-02-19 09:18:39 +00:00
"""Test Master has expected properties."""
master = MasterTransducer()
self.assertIsNotNone(master.coherence)
self.assertIsNotNone(master.phase)
2026-05-27 18:53:41 +00:00
@pytest.mark.asyncio
async def test_reset(self):
2026-02-19 09:18:39 +00:00
"""Test reset works."""
master = MasterTransducer()
master.reset()
self.assertEqual(master.coherence, 1.0)
2026-02-19 05:46:51 +00:00
class TestEmissaryTransducer(unittest.TestCase):
"""Tests for the Emissary transducer."""
2026-05-27 18:53:41 +00:00
@pytest.mark.asyncio
async def test_instantiate(self):
2026-02-19 09:18:39 +00:00
"""Test Emissary can be instantiated."""
emissary = EmissaryTransducer()
self.assertIsNotNone(emissary)
self.assertEqual(emissary.coherence, 1.0)
2026-05-27 18:53:41 +00:00
@pytest.mark.asyncio
async def test_respond_method(self):
2026-02-19 09:18:39 +00:00
"""Test Emissary has respond method."""
emissary = EmissaryTransducer()
self.assertTrue(hasattr(emissary, 'respond'))
2026-05-27 18:53:41 +00:00
@pytest.mark.asyncio
async def test_reset(self):
2026-02-19 09:18:39 +00:00
"""Test reset works."""
emissary = EmissaryTransducer()
emissary.reset()
self.assertEqual(emissary.coherence, 1.0)
2026-02-19 05:46:51 +00:00
class TestSyncLayer(unittest.TestCase):
"""Tests for the synchronization layer."""
2026-05-27 18:53:41 +00:00
@pytest.mark.asyncio
async def test_instantiate(self):
2026-02-19 09:18:39 +00:00
"""Test Sync layer can be instantiated."""
master = MasterTransducer()
emissary = EmissaryTransducer()
sync = SynchronizationLayer(master, emissary)
self.assertIsNotNone(sync)
2026-05-27 18:53:41 +00:00
@pytest.mark.asyncio
async def test_properties(self):
2026-02-19 09:18:39 +00:00
"""Test Sync layer has expected properties."""
master = MasterTransducer()
emissary = EmissaryTransducer()
sync = SynchronizationLayer(master, emissary)
self.assertIsNotNone(sync.T_sync)
self.assertIsNotNone(sync.synchronized_coherence)
self.assertFalse(sync.aligned)
self.assertFalse(sync.collapsed)
2026-05-27 18:53:41 +00:00
@pytest.mark.asyncio
async def test_reset(self):
2026-02-19 09:18:39 +00:00
"""Test reset works."""
master = MasterTransducer()
emissary = EmissaryTransducer()
sync = SynchronizationLayer(master, emissary)
sync.reset()
self.assertFalse(sync.aligned)
self.assertFalse(sync.collapsed)
2026-02-19 05:46:51 +00:00
class TestTransducerComparison(unittest.TestCase):
"""Tests comparing Master and Emissary behavior."""
2026-05-27 18:53:41 +00:00
@pytest.mark.asyncio
async def test_both_start_at_coherence_1(self):
2026-02-19 09:18:39 +00:00
"""Test both transducers start at coherence 1.0."""
master = MasterTransducer()
emissary = EmissaryTransducer()
self.assertEqual(master.coherence, 1.0)
self.assertEqual(emissary.coherence, 1.0)
2026-05-27 18:53:41 +00:00
@pytest.mark.asyncio
async def test_different_methods(self):
2026-02-19 09:18:39 +00:00
"""Test transducers have different primary methods."""
master = MasterTransducer()
emissary = EmissaryTransducer()
# Master uses integrate, Emissary uses respond
self.assertTrue(hasattr(master, 'integrate'))
self.assertTrue(hasattr(emissary, 'respond'))
2026-02-19 05:46:51 +00:00
if __name__ == "__main__":
unittest.main()