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
80c78649
Commit
80c78649
authored
5 years ago
by
Ivar Härnqvist
Browse files
Options
Downloads
Patches
Plain Diff
fix core_operations tests relying on protected interface
parent
dd68a74d
Branches
Branches containing commit
Tags
Tags containing commit
4 merge requests
!31
Resolve "Specify internal input/output dependencies of an Operation"
,
!25
Resolve "System tests iteration 1"
,
!24
Resolve "System tests iteration 1"
,
!23
Resolve "Simulate SFG"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/test_core_operations.py
+144
-249
144 additions, 249 deletions
test/test_core_operations.py
with
144 additions
and
249 deletions
test/test_core_operations.py
+
144
−
249
View file @
80c78649
...
@@ -7,308 +7,203 @@ from b_asic.core_operations import Constant, Addition, Subtraction, \
...
@@ -7,308 +7,203 @@ from b_asic.core_operations import Constant, Addition, Subtraction, \
Absolute
,
ConstantMultiplication
,
ConstantAddition
,
ConstantSubtraction
,
\
Absolute
,
ConstantMultiplication
,
ConstantAddition
,
ConstantSubtraction
,
\
ConstantDivision
,
Butterfly
ConstantDivision
,
Butterfly
# Constant tests.
class
TestConstant
:
def
test_constant_positive
(
self
):
test_operation
=
Constant
(
3
)
assert
test_operation
.
evaluate_output
(
0
,
[])[
0
]
==
3
def
test_constant
(
):
def
test_constant
_negative
(
self
):
constan
t_operation
=
Constant
(
3
)
tes
t_operation
=
Constant
(
-
3
)
assert
constan
t_operation
.
evaluate
()
==
3
assert
tes
t_operation
.
evaluate
_output
(
0
,
[])[
0
]
==
-
3
def
test_constant_complex
(
self
):
test_operation
=
Constant
(
3
+
4j
)
assert
test_operation
.
evaluate_output
(
0
,
[])[
0
]
==
3
+
4j
def
test_constant_negative
():
constant_operation
=
Constant
(
-
3
)
assert
constant_operation
.
evaluate
()
==
-
3
class
TestAddition
:
def
test_addition_positive
(
self
):
test_operation
=
Addition
()
assert
test_operation
.
evaluate_output
(
0
,
[
3
,
5
])[
0
]
==
8
def
test_
constant_complex
(
):
def
test_
addition_negative
(
self
):
constan
t_operation
=
Constant
(
3
+
4j
)
tes
t_operation
=
Addition
(
)
assert
constan
t_operation
.
evaluate
()
==
3
+
4j
assert
tes
t_operation
.
evaluate
_output
(
0
,
[
-
3
,
-
5
])[
0
]
==
-
8
# Addition tests.
def
test_addition_complex
(
self
):
test_operation
=
Addition
()
assert
test_operation
.
evaluate_output
(
0
,
[
3
+
5j
,
4
+
6j
])[
0
]
==
7
+
11j
def
test_addition
():
class
TestSubtraction
:
test_operation
=
Addition
()
def
test_subtraction_positive
(
self
):
constant_operation
=
Constant
(
3
)
test_operation
=
Subtraction
()
constant_operation_2
=
Constant
(
5
)
assert
test_operation
.
evaluate_output
(
0
,
[
5
,
3
])[
0
]
==
2
assert
test_operation
.
evaluate
(
constant_operation
.
evaluate
(),
constant_operation_2
.
evaluate
())
==
8
def
test_subtraction_negative
(
self
):
test_operation
=
Subtraction
()
assert
test_operation
.
evaluate_output
(
0
,
[
-
5
,
-
3
])[
0
]
==
-
2
def
test_addition_negative
():
def
test_subtraction_complex
(
self
):
test_operation
=
Addition
()
test_operation
=
Subtraction
()
constant_operation
=
Constant
(
-
3
)
assert
test_operation
.
evaluate_output
(
0
,
[
3
+
5j
,
4
+
6j
])[
0
]
==
-
1
-
1j
constant_operation_2
=
Constant
(
-
5
)
assert
test_operation
.
evaluate
(
constant_operation
.
evaluate
(),
constant_operation_2
.
evaluate
())
==
-
8
def
test_addition_complex
():
class
TestMultiplication
:
test_operation
=
Addition
()
def
test_multiplication_positive
(
self
):
constant_operation
=
Constant
((
3
+
5j
))
test_operation
=
Multiplication
()
constant_operation_2
=
Constant
((
4
+
6j
))
assert
test_operation
.
evaluate_output
(
0
,
[
5
,
3
])[
0
]
==
15
assert
test_operation
.
evaluate
(
constant_operation
.
evaluate
(),
constant_operation_2
.
evaluate
())
==
(
7
+
11j
)
# Subtraction tests.
def
test_multiplication_negative
(
self
):
test_operation
=
Multiplication
()
assert
test_operation
.
evaluate_output
(
0
,
[
-
5
,
-
3
])[
0
]
==
15
def
test_multiplication_complex
(
self
):
test_operation
=
Multiplication
()
assert
test_operation
.
evaluate_output
(
0
,
[
3
+
5j
,
4
+
6j
])[
0
]
==
-
18
+
38j
def
test_subtraction
():
test_operation
=
Subtraction
()
constant_operation
=
Constant
(
5
)
constant_operation_2
=
Constant
(
3
)
assert
test_operation
.
evaluate
(
constant_operation
.
evaluate
(),
constant_operation_2
.
evaluate
())
==
2
class
TestDivision
:
def
test_division_positive
(
self
):
test_operation
=
Division
()
assert
test_operation
.
evaluate_output
(
0
,
[
30
,
5
])[
0
]
==
6
def
test_subtraction_negative
():
def
test_division_negative
(
self
):
test_operation
=
Subtraction
()
test_operation
=
Division
()
constant_operation
=
Constant
(
-
5
)
assert
test_operation
.
evaluate_output
(
0
,
[
-
30
,
-
5
])[
0
]
==
6
constant_operation_2
=
Constant
(
-
3
)
assert
test_operation
.
evaluate
(
constant_operation
.
evaluate
(),
constant_operation_2
.
evaluate
())
==
-
2
def
test_division_complex
(
self
):
test_operation
=
Division
()
assert
test_operation
.
evaluate_output
(
0
,
[
60
+
40j
,
10
+
20j
])[
0
]
==
2.8
-
1.6j
def
test_subtraction_complex
():
test_operation
=
Subtraction
()
constant_operation
=
Constant
((
3
+
5j
))
constant_operation_2
=
Constant
((
4
+
6j
))
assert
test_operation
.
evaluate
(
constant_operation
.
evaluate
(),
constant_operation_2
.
evaluate
())
==
(
-
1
-
1j
)
# Multiplication tests.
class
TestSquareRoot
:
def
test_squareroot_positive
(
self
):
test_operation
=
SquareRoot
()
assert
test_operation
.
evaluate_output
(
0
,
[
36
])[
0
]
==
6
def
test_squareroot_negative
(
self
):
test_operation
=
SquareRoot
()
assert
test_operation
.
evaluate_output
(
0
,
[
-
36
])[
0
]
==
6j
def
test_multiplication
():
def
test_squareroot_complex
(
self
):
test_operation
=
Multiplication
()
test_operation
=
SquareRoot
()
constant_operation
=
Constant
(
5
)
assert
test_operation
.
evaluate_output
(
0
,
[
48
+
64j
])[
0
]
==
8
+
4j
constant_operation_2
=
Constant
(
3
)
assert
test_operation
.
evaluate
(
constant_operation
.
evaluate
(),
constant_operation_2
.
evaluate
())
==
15
def
test_multiplication_negative
():
class
TestComplexConjugate
:
test_operation
=
Multiplication
()
def
test_complexconjugate_positive
(
self
):
constant_operation
=
Constant
(
-
5
)
test_operation
=
ComplexConjugate
()
constant_operation_2
=
Constant
(
-
3
)
assert
test_operation
.
evaluate_output
(
0
,
[
3
+
4j
])[
0
]
==
3
-
4j
assert
test_operation
.
evaluate
(
constant_operation
.
evaluate
(),
constant_operation_2
.
evaluate
())
==
15
def
test_test_complexconjugate_negative
(
self
):
test_operation
=
ComplexConjugate
()
assert
test_operation
.
evaluate_output
(
0
,
[
-
3
-
4j
])[
0
]
==
-
3
+
4j
def
test_multiplication_complex
():
test_operation
=
Multiplication
()
constant_operation
=
Constant
((
3
+
5j
))
constant_operation_2
=
Constant
((
4
+
6j
))
assert
test_operation
.
evaluate
(
constant_operation
.
evaluate
(),
constant_operation_2
.
evaluate
())
==
(
-
18
+
38j
)
# Division tests.
class
TestMax
:
def
test_max_positive
(
self
):
test_operation
=
Max
()
assert
test_operation
.
evaluate_output
(
0
,
[
30
,
5
])[
0
]
==
30
def
test_max_negative
(
self
):
test_operation
=
Max
()
assert
test_operation
.
evaluate_output
(
0
,
[
-
30
,
-
5
])[
0
]
==
-
5
def
test_division
():
test_operation
=
Division
()
constant_operation
=
Constant
(
30
)
constant_operation_2
=
Constant
(
5
)
assert
test_operation
.
evaluate
(
constant_operation
.
evaluate
(),
constant_operation_2
.
evaluate
())
==
6
class
TestMin
:
def
test_min_positive
(
self
):
test_operation
=
Min
()
assert
test_operation
.
evaluate_output
(
0
,
[
30
,
5
])[
0
]
==
5
def
test_division_negative
():
def
test_min_negative
(
self
):
test_operation
=
Division
()
test_operation
=
Min
()
constant_operation
=
Constant
(
-
30
)
assert
test_operation
.
evaluate_output
(
0
,
[
-
30
,
-
5
])[
0
]
==
-
30
constant_operation_2
=
Constant
(
-
5
)
assert
test_operation
.
evaluate
(
constant_operation
.
evaluate
(),
constant_operation_2
.
evaluate
())
==
6
def
test_division_complex
():
class
TestAbsolute
:
test_operation
=
Division
()
def
test_absolute_positive
(
self
):
constant_operation
=
Constant
((
60
+
40j
))
test_operation
=
Absolute
()
constant_operation_2
=
Constant
((
10
+
20j
))
assert
test_operation
.
evaluate_output
(
0
,
[
30
])[
0
]
==
30
assert
test_operation
.
evaluate
(
constant_operation
.
evaluate
(),
constant_operation_2
.
evaluate
())
==
(
2.8
-
1.6j
)
# SquareRoot tests.
def
test_absolute_negative
(
self
):
test_operation
=
Absolute
()
assert
test_operation
.
evaluate_output
(
0
,
[
-
5
])[
0
]
==
5
def
test_absolute_complex
(
self
):
test_operation
=
Absolute
()
assert
test_operation
.
evaluate_output
(
0
,
[
3
+
4j
])[
0
]
==
5.0
def
test_squareroot
():
test_operation
=
SquareRoot
()
constant_operation
=
Constant
(
36
)
assert
test_operation
.
evaluate
(
constant_operation
.
evaluate
())
==
6
class
TestConstantMultiplication
:
def
test_constantmultiplication_positive
(
self
):
test_operation
=
ConstantMultiplication
(
5
)
assert
test_operation
.
evaluate_output
(
0
,
[
20
])[
0
]
==
100
def
test_squareroot_negative
():
def
test_constantmultiplication_negative
(
self
):
test_operation
=
SquareRoot
()
test_operation
=
ConstantMultiplication
(
5
)
constant_operation
=
Constant
(
-
36
)
assert
test_operation
.
evaluate_output
(
0
,
[
-
5
])[
0
]
==
-
25
assert
test_operation
.
evaluate
(
constant_operation
.
evaluate
())
==
6j
def
test_constantmultiplication_complex
(
self
):
test_operation
=
ConstantMultiplication
(
3
+
2j
)
assert
test_operation
.
evaluate_output
(
0
,
[
3
+
4j
])[
0
]
==
1
+
18j
def
test_squareroot_complex
():
test_operation
=
SquareRoot
()
constant_operation
=
Constant
((
48
+
64j
))
assert
test_operation
.
evaluate
(
constant_operation
.
evaluate
())
==
(
8
+
4j
)
# ComplexConjugate tests.
class
TestConstantAddition
:
def
test_constantaddition_positive
(
self
):
test_operation
=
ConstantAddition
(
5
)
assert
test_operation
.
evaluate_output
(
0
,
[
20
])[
0
]
==
25
def
test_constantaddition_negative
(
self
):
test_operation
=
ConstantAddition
(
4
)
assert
test_operation
.
evaluate_output
(
0
,
[
-
5
])[
0
]
==
-
1
def
test_complexconjugate
():
def
test_constantaddition_complex
(
self
):
test_operation
=
ComplexConjugate
()
test_operation
=
ConstantAddition
(
3
+
2j
)
constant_operation
=
Constant
(
3
+
4j
)
assert
test_operation
.
evaluate_output
(
0
,
[
3
+
2j
])[
0
]
==
6
+
4j
assert
test_operation
.
evaluate
(
constant_operation
.
evaluate
())
==
(
3
-
4j
)
def
test_test_complexconjugate_negative
()
:
class
TestConstantSubtraction
:
test_
ope
ration
=
ComplexConjugate
()
def
test_
constantsubt
ra
c
tion
_positive
(
self
):
constan
t_operation
=
Constant
(
-
3
-
4j
)
tes
t_operation
=
Constant
Subtraction
(
5
)
assert
test_operation
.
evaluate
(
constant_operation
.
evaluate
())
==
(
-
3
+
4j
)
assert
test_operation
.
evaluate
_output
(
0
,
[
20
])[
0
]
==
15
# Max tests.
def
test_constantsubtraction_negative
(
self
):
test_operation
=
ConstantSubtraction
(
4
)
assert
test_operation
.
evaluate_output
(
0
,
[
-
5
])[
0
]
==
-
9
def
test_constantsubtraction_complex
(
self
):
test_operation
=
ConstantSubtraction
(
4
+
6j
)
assert
test_operation
.
evaluate_output
(
0
,
[
3
+
4j
])[
0
]
==
-
1
-
2j
def
test_max
():
test_operation
=
Max
()
constant_operation
=
Constant
(
30
)
constant_operation_2
=
Constant
(
5
)
assert
test_operation
.
evaluate
(
constant_operation
.
evaluate
(),
constant_operation_2
.
evaluate
())
==
30
class
TestConstantDivision
:
def
test_constantdivision_positive
(
self
):
test_operation
=
ConstantDivision
(
5
)
assert
test_operation
.
evaluate_output
(
0
,
[
20
])[
0
]
==
4
def
test_max_negative
():
def
test_constantdivision_negative
(
self
):
test_operation
=
Max
()
test_operation
=
ConstantDivision
(
4
)
constant_operation
=
Constant
(
-
30
)
assert
test_operation
.
evaluate_output
(
0
,
[
-
20
])[
0
]
==
-
5
constant_operation_2
=
Constant
(
-
5
)
assert
test_operation
.
evaluate
(
constant_operation
.
evaluate
(),
constant_operation_2
.
evaluate
())
==
-
5
# Min tests.
def
test_constantdivision_complex
(
self
):
test_operation
=
ConstantDivision
(
2
+
2j
)
assert
test_operation
.
evaluate_output
(
0
,
[
10
+
10j
])[
0
]
==
5
def
test_min
():
class
TestButterfly
:
test_operation
=
Min
()
def
test_butterfly_positive
(
self
):
constant_operation
=
Constant
(
30
)
test_operation
=
Butterfly
()
constant_operation_2
=
Constant
(
5
)
assert
test_operation
.
evaluate_output
(
0
,
[
2
,
3
])[
0
]
==
5
assert
test_operation
.
evaluate
(
assert
test_operation
.
evaluate_output
(
1
,
[
2
,
3
])[
1
]
==
-
1
constant_operation
.
evaluate
(),
constant_operation_2
.
evaluate
())
==
5
def
test_butterfly_negative
(
self
):
test_operation
=
Butterfly
()
assert
test_operation
.
evaluate_output
(
0
,
[
-
2
,
-
3
])[
0
]
==
-
5
assert
test_operation
.
evaluate_output
(
1
,
[
-
2
,
-
3
])[
1
]
==
1
def
test_min_negative
():
def
test_buttefly_complex
(
self
):
test_operation
=
Min
()
test_operation
=
Butterfly
()
constant_operation
=
Constant
(
-
30
)
assert
test_operation
.
evaluate_output
(
0
,
[
2
+
1j
,
3
-
2j
])[
0
]
==
5
-
1j
constant_operation_2
=
Constant
(
-
5
)
assert
test_operation
.
evaluate_output
(
1
,
[
2
+
1j
,
3
-
2j
])[
1
]
==
-
1
+
3j
assert
test_operation
.
evaluate
(
constant_operation
.
evaluate
(),
constant_operation_2
.
evaluate
())
==
-
30
# Absolute tests.
def
test_absolute
():
test_operation
=
Absolute
()
constant_operation
=
Constant
(
30
)
assert
test_operation
.
evaluate
(
constant_operation
.
evaluate
())
==
30
def
test_absolute_negative
():
test_operation
=
Absolute
()
constant_operation
=
Constant
(
-
5
)
assert
test_operation
.
evaluate
(
constant_operation
.
evaluate
())
==
5
def
test_absolute_complex
():
test_operation
=
Absolute
()
constant_operation
=
Constant
((
3
+
4j
))
assert
test_operation
.
evaluate
(
constant_operation
.
evaluate
())
==
5.0
# ConstantMultiplication tests.
def
test_constantmultiplication
():
test_operation
=
ConstantMultiplication
(
5
)
constant_operation
=
Constant
(
20
)
assert
test_operation
.
evaluate
(
constant_operation
.
evaluate
())
==
100
def
test_constantmultiplication_negative
():
test_operation
=
ConstantMultiplication
(
5
)
constant_operation
=
Constant
(
-
5
)
assert
test_operation
.
evaluate
(
constant_operation
.
evaluate
())
==
-
25
def
test_constantmultiplication_complex
():
test_operation
=
ConstantMultiplication
(
3
+
2j
)
constant_operation
=
Constant
((
3
+
4j
))
assert
test_operation
.
evaluate
(
constant_operation
.
evaluate
())
==
(
1
+
18j
)
# ConstantAddition tests.
def
test_constantaddition
():
test_operation
=
ConstantAddition
(
5
)
constant_operation
=
Constant
(
20
)
assert
test_operation
.
evaluate
(
constant_operation
.
evaluate
())
==
25
def
test_constantaddition_negative
():
test_operation
=
ConstantAddition
(
4
)
constant_operation
=
Constant
(
-
5
)
assert
test_operation
.
evaluate
(
constant_operation
.
evaluate
())
==
-
1
def
test_constantaddition_complex
():
test_operation
=
ConstantAddition
(
3
+
2j
)
constant_operation
=
Constant
((
3
+
4j
))
assert
test_operation
.
evaluate
(
constant_operation
.
evaluate
())
==
(
6
+
6j
)
# ConstantSubtraction tests.
def
test_constantsubtraction
():
test_operation
=
ConstantSubtraction
(
5
)
constant_operation
=
Constant
(
20
)
assert
test_operation
.
evaluate
(
constant_operation
.
evaluate
())
==
15
def
test_constantsubtraction_negative
():
test_operation
=
ConstantSubtraction
(
4
)
constant_operation
=
Constant
(
-
5
)
assert
test_operation
.
evaluate
(
constant_operation
.
evaluate
())
==
-
9
def
test_constantsubtraction_complex
():
test_operation
=
ConstantSubtraction
(
4
+
6j
)
constant_operation
=
Constant
((
3
+
4j
))
assert
test_operation
.
evaluate
(
constant_operation
.
evaluate
())
==
(
-
1
-
2j
)
# ConstantDivision tests.
def
test_constantdivision
():
test_operation
=
ConstantDivision
(
5
)
constant_operation
=
Constant
(
20
)
assert
test_operation
.
evaluate
(
constant_operation
.
evaluate
())
==
4
def
test_constantdivision_negative
():
test_operation
=
ConstantDivision
(
4
)
constant_operation
=
Constant
(
-
20
)
assert
test_operation
.
evaluate
(
constant_operation
.
evaluate
())
==
-
5
def
test_constantdivision_complex
():
test_operation
=
ConstantDivision
(
2
+
2j
)
constant_operation
=
Constant
((
10
+
10j
))
assert
test_operation
.
evaluate
(
constant_operation
.
evaluate
())
==
(
5
+
0j
)
def
test_butterfly
():
test_operation
=
Butterfly
()
assert
list
(
test_operation
.
evaluate
(
2
,
3
))
==
[
5
,
-
1
]
def
test_butterfly_negative
():
test_operation
=
Butterfly
()
assert
list
(
test_operation
.
evaluate
(
-
2
,
-
3
))
==
[
-
5
,
1
]
def
test_buttefly_complex
():
test_operation
=
Butterfly
()
assert
list
(
test_operation
.
evaluate
(
2
+
1j
,
3
-
2j
))
==
[
5
-
1j
,
-
1
+
3j
]
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