Skip to content

Commit

Permalink
Core tests implementation (partial)
Browse files Browse the repository at this point in the history
- MemoryObjectTest
- MemoryTest
- MindTest
- RawMemoryTest
- CodeletTest
  • Loading branch information
EltonCN committed Oct 4, 2024
1 parent f186201 commit 44ceb1b
Show file tree
Hide file tree
Showing 19 changed files with 787 additions and 21 deletions.
2 changes: 2 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
addopts = --ignore=examples --ignore=docs --doctest-modules
3 changes: 1 addition & 2 deletions src/cst_python/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from . import python
from . import core

from .core.entities import Codelet, Mind, MemoryObject
from .python.manager import *
from .core.entities import Codelet, Mind, MemoryObject
3 changes: 2 additions & 1 deletion src/cst_python/core/entities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
from .memory_container import MemoryContainer
from .rest_memory_container import RESTMemoryContainer
from .rest_memory_object import RESTMemoryObject
from .mind import Mind
from .mind import Mind
from .raw_memory import RawMemory
40 changes: 26 additions & 14 deletions src/cst_python/core/entities/codelet.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self) -> None:
self._time_step = 300
self._enabled = True
self._enable_count = 0
self._name = threading.currentThread().name+"|"+type(self).__name__+str(Codelet._last_id)
self._name = threading.current_thread().name+"|"+type(self).__name__+str(Codelet._last_id)
self._last_start_time = 0.0
self._lock = threading.RLock()
self._activation = 0.0
Expand Down Expand Up @@ -82,8 +82,13 @@ def activation(self) -> float:
@activation.setter
def activation(self, value:float):
if value > 1.0 or value < 0.0:
if value > 1.0:
self._activation = 1.0
else:
self._activation = 0.0

raise ValueError(f"Codelet activation must be in (0.0 , 1.0) \
(value {value} is not allowed).")
(value {value} is not allowed).")

self._activation = value

Expand Down Expand Up @@ -115,9 +120,14 @@ def threshold(self) -> float:
#@alias.alias("set_threshold", "setThreshold")
@threshold.setter
def threshold(self, value:float):
if value > 1.0 or value < 1.0:
if value > 1.0 or value < 0.0:
if value > 1.0:
self._threshold = 1.0
else:
self._threshold = 0.0

raise ValueError(f"Codelet threshold must be in (0.0 , 1.0) \
(value {value} is not allowed).")
(value {value} is not allowed).")

self._threshold = value

Expand Down Expand Up @@ -145,12 +155,12 @@ def broadcast(self, value:List[Memory]) -> None:

#@alias.alias("IsProfiling")
@property
def is_profiling(self) -> bool:
def profiling(self) -> bool:
return self._is_profiling

#@alias.alias("set_profiling", "setProfiling")
@is_profiling.setter
def is_profiling(self, value:bool):
@profiling.setter
def profiling(self, value:bool):
if value is True:
raise NotImplementedError("Profiling is not implemented")

Expand Down Expand Up @@ -299,7 +309,7 @@ def add_broadcasts(self, memories:List[Memory]) -> None:

#@alias.alias("getThreadName")
def get_thread_name(self) -> str:
return threading.currentThread().name
return threading.current_thread().name

#@alias.alias("to_string", "toString")
def __str__(self) -> str:
Expand All @@ -308,16 +318,18 @@ def __str__(self) -> str:
result = f"Codelet [activation={self._activation}, name={self._name}, "

if self._broadcast is not None:
result += self._broadcast[min(len(self._broadcast), max_len)]
result += "broadcast="
result += str(self._broadcast[:min(len(self._broadcast), max_len)])
result += ", "

if self._inputs is not None:
result += self._inputs[min(len(self._outputs), max_len)]
result += "inputs="
result += str(self._inputs[:min(len(self.inputs), max_len)])
result += ", "

if self._outputs is not None:
result += self._outputs[min(len(self._outputs), max_len)]
result += ", "
result += "outputs="
result += str(self._outputs[:min(len(self._outputs), max_len)])

result += "]"

Expand Down Expand Up @@ -414,7 +426,7 @@ def notify_codelet(self) -> None:
self._raise_exception()

except Exception as e:
#Logging
#TODO Logging
pass

finally:
Expand Down
4 changes: 0 additions & 4 deletions src/cst_python/core/entities/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ def get_id(self) -> int:
def set_id(self, memory_id:int) -> None:
...

#@alias.alias("getTimestamp")
@abc.abstractmethod
def get_timestamp(self) -> int:
...


def compare_name(self, other_name:str) -> bool:
Expand Down
Empty file added tests/core/__init__.py
Empty file.
15 changes: 15 additions & 0 deletions tests/core/entities/CoalitionTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import unittest

class Test(unittest.TestCase):
def setUp(self) -> None:
super().setUp()

def tearDown(self) -> None:
super().tearDown()

@classmethod
def tearDownClass(cls):
...

def test_(self) -> None:
...
15 changes: 15 additions & 0 deletions tests/core/entities/CodeRackTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import unittest

class Test(unittest.TestCase):
def setUp(self) -> None:
super().setUp()

def tearDown(self) -> None:
super().tearDown()

@classmethod
def tearDownClass(cls):
...

def test_(self) -> None:
...
15 changes: 15 additions & 0 deletions tests/core/entities/CodeletContainerTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import unittest

class Test(unittest.TestCase):
def setUp(self) -> None:
super().setUp()

def tearDown(self) -> None:
super().tearDown()

@classmethod
def tearDownClass(cls):
...

def test_(self) -> None:
...
Loading

0 comments on commit 44ceb1b

Please sign in to comment.