Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B-ASIC - Better ASIC Toolbox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Computer Engineering
B-ASIC - Better ASIC Toolbox
Commits
2475a9ca
Commit
2475a9ca
authored
5 years ago
by
Arvid Westerlund
Browse files
Options
Downloads
Patches
Plain Diff
Tests, implementation done of value_length property in InputPort.
parent
762be0cd
No related branches found
No related tags found
1 merge request
!16
Implemented "Modify Word Length"
Pipeline
#11327
passed
5 years ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
b_asic/port.py
+12
-13
12 additions, 13 deletions
b_asic/port.py
test/test_inputport.py
+25
-13
25 additions, 13 deletions
test/test_inputport.py
with
37 additions
and
26 deletions
b_asic/port.py
+
12
−
13
View file @
2475a9ca
...
@@ -35,15 +35,6 @@ class Port(ABC):
...
@@ -35,15 +35,6 @@ class Port(ABC):
"""
Return a list of all connected signals.
"""
"""
Return a list of all connected signals.
"""
raise
NotImplementedError
raise
NotImplementedError
@abstractmethod
def
signal
(
self
,
i
:
int
=
0
)
->
Signal
:
"""
Return the connected signal at index i.
Keyword argumens:
i: integer index of the signal requsted.
"""
raise
NotImplementedError
@property
@property
@abstractmethod
@abstractmethod
def
connected_ports
(
self
)
->
List
[
"
Port
"
]:
def
connected_ports
(
self
)
->
List
[
"
Port
"
]:
...
@@ -119,24 +110,32 @@ class InputPort(AbstractPort):
...
@@ -119,24 +110,32 @@ class InputPort(AbstractPort):
"""
"""
_source_signal
:
Optional
[
Signal
]
_source_signal
:
Optional
[
Signal
]
_value_length
:
Optional
[
int
]
def
__init__
(
self
,
port_id
:
PortIndex
,
operation
:
Operation
):
def
__init__
(
self
,
port_id
:
PortIndex
,
operation
:
Operation
):
super
().
__init__
(
port_id
,
operation
)
super
().
__init__
(
port_id
,
operation
)
self
.
_source_signal
=
None
self
.
_source_signal
=
None
self
.
_value_length
=
None
@property
@property
def
signals
(
self
)
->
List
[
Signal
]:
def
signals
(
self
)
->
List
[
Signal
]:
return
[]
if
self
.
_source_signal
is
None
else
[
self
.
_source_signal
]
return
[]
if
self
.
_source_signal
is
None
else
[
self
.
_source_signal
]
def
signal
(
self
,
i
:
int
=
0
)
->
Signal
:
@property
assert
0
<=
i
<
self
.
signal_count
(),
"
Signal index out of bound.
"
def
value_length
(
self
)
->
Optional
[
int
]:
assert
self
.
_source_signal
is
not
None
,
"
No Signal connect to InputPort.
"
return
self
.
_value_length
return
self
.
_source_signal
@property
@property
def
connected_ports
(
self
)
->
List
[
Port
]:
def
connected_ports
(
self
)
->
List
[
Port
]:
return
[]
if
self
.
_source_signal
is
None
or
self
.
_source_signal
.
source
is
None
\
return
[]
if
self
.
_source_signal
is
None
or
self
.
_source_signal
.
source
is
None
\
else
[
self
.
_source_signal
.
source
]
else
[
self
.
_source_signal
.
source
]
@value_length.setter
def
value_length
(
self
,
bits
:
Optional
[
int
])
->
None
:
assert
isinstance
(
bits
,
int
)
or
bits
is
None
,
"
Value length on input port has to be of type Int or NoneType.
"
assert
bits
is
None
or
bits
>=
0
,
"
Value length on input port has to be a non-negative integer or None.
"
self
.
_value_length
=
bits
def
signal_count
(
self
)
->
int
:
def
signal_count
(
self
)
->
int
:
return
0
if
self
.
_source_signal
is
None
else
1
return
0
if
self
.
_source_signal
is
None
else
1
...
...
This diff is collapsed.
Click to expand it.
test/test_inputport.py
+
25
−
13
View file @
2475a9ca
...
@@ -30,14 +30,12 @@ def s_w_source():
...
@@ -30,14 +30,12 @@ def s_w_source():
@pytest.fixture
@pytest.fixture
def
sig_with_dest
():
def
sig_with_dest
():
inp_port
=
InputPort
(
0
,
None
)
#
inp_port = InputPort(0, None)
return
Signal
(
destination
=
out
_port
)
return
Signal
(
destination
=
inp
_port
()
)
@pytest.fixture
@pytest.fixture
def
connected_sig
():
def
connected_sig
():
out_port
=
OutputPort
(
0
,
None
)
return
Signal
(
source
=
out_port
(),
destination
=
inp_port
())
inp_port
=
InputPort
(
0
,
None
)
return
Signal
(
source
=
out_port
,
destination
=
inp_port
)
def
test_connect_then_disconnect
(
inp_port
,
out_port
):
def
test_connect_then_disconnect
(
inp_port
,
out_port
):
"""
Test connect unused port to port.
"""
"""
Test connect unused port to port.
"""
...
@@ -83,13 +81,27 @@ def test_add_signal_then_disconnect(inp_port, s_w_source):
...
@@ -83,13 +81,27 @@ def test_add_signal_then_disconnect(inp_port, s_w_source):
assert
s_w_source
.
source
.
signals
==
[
s_w_source
]
assert
s_w_source
.
source
.
signals
==
[
s_w_source
]
assert
s_w_source
.
destination
is
None
assert
s_w_source
.
destination
is
None
def
test_connect_then_disconnect
(
inp_port
,
out_port
):
def
test_set_value_length_pos_int
(
inp_port
):
"""
Can port be connected and then disconnected properly?
"""
inp_port
.
value_length
=
10
inp_port
.
connect
(
out_port
)
assert
inp_port
.
value_length
==
10
def
test_set_value_length_zero
(
inp_port
):
inp_port
.
value_length
=
0
assert
inp_port
.
value_length
==
0
def
test_set_value_length_neg_int
(
inp_port
):
with
pytest
.
raises
(
Exception
):
inp_port
.
value_length
=
-
10
def
test_set_value_length_complex
(
inp_port
):
with
pytest
.
raises
(
Exception
):
inp_port
.
value_length
=
(
2
+
4j
)
inp_port
.
disconnect
(
out_port
)
def
test_set_value_length_float
(
inp_port
):
with
pytest
.
raises
(
Exception
):
inp_port
.
value_length
=
3.2
print
(
"
outport signals:
"
,
out_port
.
signals
,
"
count:
"
,
out_port
.
signal_count
())
def
test_set_value_length_pos_then_none
(
inp_port
):
assert
inp_port
.
signal_count
()
=
=
1
inp_port
.
value_length
=
1
0
assert
len
(
inp_port
.
connected_ports
)
==
0
inp_port
.
value_length
=
None
assert
out
_port
.
signal_count
()
==
0
assert
inp
_port
.
value_length
==
None
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment