Castle: The best Real-Time/Embedded/HighTech language EVER. Attempt 2
修訂 | 5861d35f51411331f01e9ac4cf7965d3599977b8 (tree) |
---|---|
時間 | 2024-03-02 00:46:50 |
作者 | Albert Mietus < albert AT mietus DOT nl > |
Commiter | Albert Mietus < albert AT mietus DOT nl > |
ASIS: activated some (ASIDE) TestDoubles/AIGR into TestDoubles-aigr-sieve package (BUSY)
@@ -1,14 +0,0 @@ | ||
1 | -# (C) Albert Mietus, 2023. Part of Castle/CCastle project | |
2 | - | |
3 | -""".. Note:: The baseProtocol (instance) is used in aigr.protocols as top of all protocols. So we can import & use it. | |
4 | - No such 'top-namespaces' exist, so we have to initiate it here. | |
5 | -""" | |
6 | - | |
7 | -from castle.aigr.protocols import baseProtocol, ID | |
8 | -from castle.aigr import NameSpace | |
9 | - | |
10 | -Protocol = baseProtocol | |
11 | - | |
12 | -base = NameSpace(ID('base')) | |
13 | -base.register(Protocol) | |
14 | - |
@@ -1,29 +0,0 @@ | ||
1 | -# (C) Albert Mietus, 2023. Part of Castle/CCastle project | |
2 | - | |
3 | -from castle.aigr import EventProtocol, Event, ID | |
4 | -from castle.aigr.protocols import ProtocolWrapper | |
5 | -from castle.aigr.aid import TypedParameter, Argument | |
6 | - | |
7 | - | |
8 | -StartSieve = EventProtocol(ID('StartSieve'), | |
9 | - events=( | |
10 | - Event(name=ID('runTo'), return_type=None, typedParameters=(TypedParameter(name='max', type=int),)), | |
11 | - Event(name=ID('newMax'), return_type=None, typedParameters=(TypedParameter(name='max', type=int),)))) | |
12 | - | |
13 | - | |
14 | -SlowStart = EventProtocol(ID('SlowStart'), | |
15 | - typedParameters=(TypedParameter(name='queue_max', type=int),), | |
16 | - events=( | |
17 | - Event(name=ID('setMax'), return_type=None, typedParameters=(TypedParameter(name='queue_max', type=int),)),)) | |
18 | - | |
19 | -SlowStart_1 = ProtocolWrapper(ID("SlowStart_1"), | |
20 | - based_on=SlowStart, | |
21 | - #OR: arguments=(Argument(name=queue_max, value=1),)) | |
22 | - arguments=(Argument(value=1),)) | |
23 | - | |
24 | -SimpleSieve = EventProtocol(ID('SimpleSieve'), | |
25 | - based_on=SlowStart_1, | |
26 | - events=( | |
27 | - Event(name=ID('input'), return_type=None, typedParameters=(TypedParameter(name='try', type=int),)),)) | |
28 | - | |
29 | - |
@@ -1,48 +0,0 @@ | ||
1 | -# (C) Albert Mietus, 2023. Part of Castle/CCastle project | |
2 | -"""Test AIGR representation of the TheSieve protocols | |
3 | - See: http://docideas.mietus.nl/en/default/CCastle/4.Blog/b.TheSieve.html#the-design | |
4 | -""" | |
5 | - | |
6 | -import pytest | |
7 | - | |
8 | -import castle.aigr as aigr | |
9 | -from TestDoubles.AIGR.sieve import protocols | |
10 | -from TestDoubles.AIGR.base import Protocol as base_Protocol | |
11 | - | |
12 | - | |
13 | -def verify_Protocol(p, name, event_names, base=None, no_events=None, cls=None): | |
14 | - if base is None: | |
15 | - base=base_Protocol | |
16 | - if no_events is None: | |
17 | - no_events = len(event_names) | |
18 | - if cls is None: | |
19 | - cls = aigr.EventProtocol | |
20 | - | |
21 | - assert isinstance(p, cls) | |
22 | - assert p.name == name | |
23 | - assert p.based_on is base | |
24 | - assert p._noEvents() == no_events | |
25 | - for no, name in enumerate(event_names): | |
26 | - assert p.events[no].name == name | |
27 | - | |
28 | - | |
29 | - | |
30 | -def test_StartSieve(): | |
31 | - p = protocols.StartSieve | |
32 | - verify_Protocol(p, name="StartSieve", event_names=('runTo', 'newMax')) | |
33 | - | |
34 | -def test_SlowStart(): | |
35 | - p = protocols.SlowStart | |
36 | - verify_Protocol(p, name="SlowStart", event_names=['setMax']) | |
37 | - | |
38 | -def test_SlowStart_1(): | |
39 | - from castle.aigr.protocols import ProtocolWrapper | |
40 | - p = protocols.SlowStart_1 | |
41 | - verify_Protocol(p, name="SlowStart_1", cls=ProtocolWrapper, base=protocols.SlowStart, event_names=['setMax']) | |
42 | - | |
43 | -def test_SimpleSieve(): | |
44 | - p = protocols.SimpleSieve | |
45 | - verify_Protocol(p, name="SimpleSieve", base=protocols.SlowStart_1, event_names=['input']) | |
46 | - | |
47 | - | |
48 | - |
@@ -3,8 +3,10 @@ | ||
3 | 3 | PYREVERSE_PKGS = castle.TESTDOUBLES.aigr.sieve |
4 | 4 | |
5 | 5 | LAST = \ |
6 | + pytst/test_0_dummy.py \ | |
6 | 7 | # |
7 | 8 | CURRENT = \ |
9 | + pytst/test_1_sieve_protocols.py \ | |
8 | 10 | # |
9 | 11 | |
10 | 12 | TODO = \ |
@@ -0,0 +1,14 @@ | ||
1 | +# (C) Albert Mietus, 2023. Part of Castle/CCastle project | |
2 | + | |
3 | +""".. Note:: The baseProtocol (instance) is used in aigr.protocols as top of all protocols. So we can import & use it. | |
4 | + No such 'top-namespaces' exist, so we have to initiate it here. | |
5 | +""" | |
6 | + | |
7 | +from castle.aigr.protocols import baseProtocol, ID | |
8 | +from castle.aigr import NameSpace | |
9 | + | |
10 | +Protocol = baseProtocol | |
11 | + | |
12 | +base = NameSpace(ID('base')) | |
13 | +base.register(Protocol) | |
14 | + |
@@ -0,0 +1,29 @@ | ||
1 | +# (C) Albert Mietus, 2023. Part of Castle/CCastle project | |
2 | + | |
3 | +from castle.aigr import EventProtocol, Event, ID | |
4 | +from castle.aigr.protocols import ProtocolWrapper | |
5 | +from castle.aigr.aid import TypedParameter, Argument | |
6 | + | |
7 | + | |
8 | +StartSieve = EventProtocol(ID('StartSieve'), | |
9 | + events=( | |
10 | + Event(name=ID('runTo'), return_type=None, typedParameters=(TypedParameter(name='max', type=int),)), | |
11 | + Event(name=ID('newMax'), return_type=None, typedParameters=(TypedParameter(name='max', type=int),)))) | |
12 | + | |
13 | + | |
14 | +SlowStart = EventProtocol(ID('SlowStart'), | |
15 | + typedParameters=(TypedParameter(name='queue_max', type=int),), | |
16 | + events=( | |
17 | + Event(name=ID('setMax'), return_type=None, typedParameters=(TypedParameter(name='queue_max', type=int),)),)) | |
18 | + | |
19 | +SlowStart_1 = ProtocolWrapper(ID("SlowStart_1"), | |
20 | + based_on=SlowStart, | |
21 | + #OR: arguments=(Argument(name=queue_max, value=1),)) | |
22 | + arguments=(Argument(value=1),)) | |
23 | + | |
24 | +SimpleSieve = EventProtocol(ID('SimpleSieve'), | |
25 | + based_on=SlowStart_1, | |
26 | + events=( | |
27 | + Event(name=ID('input'), return_type=None, typedParameters=(TypedParameter(name='try', type=int),)),)) | |
28 | + | |
29 | + |
@@ -1,2 +1,26 @@ | ||
1 | +# (C) Albert Mietus, 2023,2024 Part of Castle/CCastle project | |
2 | +"""Check that the AIGR TestDoubles 'the sieve' are available | |
3 | + See: http://docideas.mietus.nl/en/default/CCastle/4.Blog/b.TheSieve.html#the-design | |
4 | + See 'test_1... (and more) for in-depth tests" | |
5 | +""" | |
6 | + | |
7 | + | |
8 | +import pytest | |
9 | + | |
10 | +import castle.aigr as aigr | |
11 | +from castle.TESTDOUBLES.aigr.sieve import protocols | |
12 | +from castle.TESTDOUBLES.aigr.base import Protocol as base_Protocol | |
13 | + | |
14 | + | |
1 | 15 | def test_0_Oke(): |
2 | 16 | return |
17 | + | |
18 | +def test_1_all_sieveProtocols(): | |
19 | + for p in (protocols.StartSieve, protocols.SlowStart, protocols.SimpleSieve): | |
20 | + assert isinstance(p, aigr.EventProtocol) | |
21 | + | |
22 | + for p in (protocols.SlowStart_1,): | |
23 | + assert isinstance(p, aigr.protocols.ProtocolWrapper) # ProtocolWrapper isn't exported | |
24 | + | |
25 | +def test_2_baseProtocol(): | |
26 | + assert isinstance(base_Protocol, aigr.Protocol) |
@@ -0,0 +1,48 @@ | ||
1 | +# (C) Albert Mietus, 2023,2024 Part of Castle/CCastle project | |
2 | +"""Test the AIGR TestDoubles of the Sieve protocols | |
3 | + See: http://docideas.mietus.nl/en/default/CCastle/4.Blog/b.TheSieve.html#the-design | |
4 | +""" | |
5 | + | |
6 | +import pytest | |
7 | + | |
8 | +import castle.aigr as aigr | |
9 | +from castle.TESTDOUBLES.aigr.sieve import protocols | |
10 | +from castle.TESTDOUBLES.aigr.base import Protocol as base_Protocol | |
11 | + | |
12 | + | |
13 | +def verify_Protocol(p, name, event_names, base=None, no_events=None, cls=None): | |
14 | + if base is None: | |
15 | + base=base_Protocol | |
16 | + if no_events is None: | |
17 | + no_events = len(event_names) | |
18 | + if cls is None: | |
19 | + cls = aigr.EventProtocol | |
20 | + | |
21 | + assert isinstance(p, cls) | |
22 | + assert p.name == name | |
23 | + assert p.based_on is base | |
24 | + assert p._noEvents() == no_events | |
25 | + for no, name in enumerate(event_names): | |
26 | + assert p.events[no].name == name | |
27 | + | |
28 | + | |
29 | + | |
30 | +def test_StartSieve(): | |
31 | + p = protocols.StartSieve | |
32 | + verify_Protocol(p, name="StartSieve", event_names=('runTo', 'newMax')) | |
33 | + | |
34 | +def test_SlowStart(): | |
35 | + p = protocols.SlowStart | |
36 | + verify_Protocol(p, name="SlowStart", event_names=['setMax']) | |
37 | + | |
38 | +def test_SlowStart_1(): | |
39 | + from castle.aigr.protocols import ProtocolWrapper | |
40 | + p = protocols.SlowStart_1 | |
41 | + verify_Protocol(p, name="SlowStart_1", cls=ProtocolWrapper, base=protocols.SlowStart, event_names=['setMax']) | |
42 | + | |
43 | +def test_SimpleSieve(): | |
44 | + p = protocols.SimpleSieve | |
45 | + verify_Protocol(p, name="SimpleSieve", base=protocols.SlowStart_1, event_names=['input']) | |
46 | + | |
47 | + | |
48 | + |