• R/O
  • SSH

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Castle: The best Real-Time/Embedded/HighTech language EVER. Attempt 2


Commit MetaInfo

修订版eb6a71735c23dd9708126a22493e2353edaaa316 (tree)
时间2024-05-12 19:33:44
作者Albert Mietus < albert AT mietus DOT nl >
CommiterAlbert Mietus < albert AT mietus DOT nl >

Log Message

More sieveCastle; small mypy issue: 'Is Call a starement?' _(currently not, it a expression which is not a statement)_

更改概述

差异

diff -r a3662337d36b -r eb6a71735c23 TestDoubles_packages/TestDoubles-aigr-sieve/castle/TESTDOUBLES/aigr/sieve/basic1/sieveCastle.py
--- a/TestDoubles_packages/TestDoubles-aigr-sieve/castle/TESTDOUBLES/aigr/sieve/basic1/sieveCastle.py Sun May 12 12:31:03 2024 +0200
+++ b/TestDoubles_packages/TestDoubles-aigr-sieve/castle/TESTDOUBLES/aigr/sieve/basic1/sieveCastle.py Sun May 12 12:33:44 2024 +0200
@@ -5,8 +5,12 @@
55 .. see also:: :file:`./__init__.py` for a general intro
66 """
77
8+__all__ = ['Sieve']
89
9-from castle.aigr import ComponentImplementation, Body
10+
11+from castle import aigr
12+from castle.aigr import ComponentImplementation, ID, Method
13+
1014
1115
1216 # implement Sieve {
@@ -18,17 +22,33 @@
1822 Sieve = ComponentImplementation('Sieve',
1923 interface=components.SieveMoat,
2024 parameters=(),
21- body=Body()) # Body in filed below
22-
23-
24-
25+ body=aigr.Body()) # Body in filed below
2526
2627 # init(int:onPrime) // `init` is (typically) part of the construction of a element.
2728 # {
2829 # super.init(); // `super` acts as port to the base-class
2930 # .myPrime := onPrime;
3031 # }
31-#
32+
33+init_method = Method(ID('init'),
34+ returns=None,
35+ parameters=(aigr.TypedParameter(name=ID('onPrime'), type=int),),
36+ body=aigr.Body(statements=[
37+ aigr.Call(
38+ callable=aigr.Part(
39+ base=aigr.Call(callable=ID('super')), attribute=ID('init')),
40+ arguments=()),
41+ aigr.Become(
42+ targets=(aigr.Part(base=ID('self'), attribute=ID('myPrime', context=aigr.Set())),),
43+ values=(ID('onPrime', context=aigr.Ref()),))]))
44+
45+assert isinstance(Sieve.body, aigr.Body) # This make mypy happy for the next line :-)
46+Sieve.body.expand(init_method)
47+
48+
49+
50+
51+
3252 # SimpleSieve.input(try) on .try
3353 # {
3454 # if ( (try % .myPrime) !=0 ) {
diff -r a3662337d36b -r eb6a71735c23 TestDoubles_packages/TestDoubles-aigr-sieve/pytst/sieve/basic1/__init__.py
--- a/TestDoubles_packages/TestDoubles-aigr-sieve/pytst/sieve/basic1/__init__.py Sun May 12 12:31:03 2024 +0200
+++ b/TestDoubles_packages/TestDoubles-aigr-sieve/pytst/sieve/basic1/__init__.py Sun May 12 12:33:44 2024 +0200
@@ -0,0 +1,21 @@
1+# (C) Albert Mietus 2024, Part of Castle/CCastle project
2+"""Test the AIGR TestDoubles of the Sieve protocols (basic1 variant)
3+ See: http://docideas.mietus.nl/en/default/CCastle/4.Blog/b.TheSieve.html#the-design
4+"""
5+import logging; logger = logging.getLogger(__name__)
6+
7+import typing as PTH # Python TypeHints
8+from castle import aigr
9+
10+
11+def find_name_in_body(name, body) -> PTH.Optional[aigr.statements.callables._Named_callable]:
12+ logger.info("find_name_in_body(name=%s, body=%s", name, body)
13+ for s in body.statements:
14+ logger.debug("\t: %s", s)
15+ if isinstance(s, aigr.NamedNode):
16+ logger.debug("\t: name=%s in %s", s.name, s)
17+ if s.name == name:
18+ logger.debug("\t: FOUND name=%s in %s", s.name, s)
19+ return s
20+ logger.debug("NOT FOUND: %s", name)
21+ return None
diff -r a3662337d36b -r eb6a71735c23 TestDoubles_packages/TestDoubles-aigr-sieve/pytst/sieve/basic1/test_sieveCastle.py
--- a/TestDoubles_packages/TestDoubles-aigr-sieve/pytst/sieve/basic1/test_sieveCastle.py Sun May 12 12:31:03 2024 +0200
+++ b/TestDoubles_packages/TestDoubles-aigr-sieve/pytst/sieve/basic1/test_sieveCastle.py Sun May 12 12:33:44 2024 +0200
@@ -2,11 +2,15 @@
22 """Test the AIGR TestDoubles of the Sieve protocols (basic1 variant)
33 See: http://docideas.mietus.nl/en/default/CCastle/4.Blog/b.TheSieve.html#the-design
44 """
5+import logging; logger = logging.getLogger(__name__)
56
67 import pytest
8+
79 from castle.TESTDOUBLES.aigr.sieve.basic1 import sieveCastle
10+from castle import aigr
811
9-from castle import aigr
12+from . import find_name_in_body
13+
1014
1115 @pytest.fixture
1216 def comp():
@@ -14,7 +18,7 @@
1418
1519
1620 def test_0a_types(comp):
17- assert isinstance(comp, aigr.ComponentImplementation)
21+ assert isinstance(comp, aigr.ComponentImplementation)
1822 assert isinstance(comp.interface, aigr.ComponentInterface)
1923 assert isinstance(comp.parameters, (type(None), tuple))
2024 assert isinstance(comp.body, aigr.Body)
@@ -24,5 +28,13 @@
2428 assert comp.name == 'Sieve'
2529
2630 def test_0c_noParms(comp):
27- assert comp.parameters is ()
31+ assert comp.parameters == ()
2832
33+def test_has_init(comp):
34+ init = find_name_in_body('init', comp.body)
35+ assert isinstance(init, aigr.Method), f"Expected an init method, got {init}"
36+
37+def test_init_has_body(comp):
38+ init = find_name_in_body('init', comp.body)
39+ assert len(init.body)==2, f"Expected that 'init' has 2 statements, but found: {len(init.body.statements)}"
40+