Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
AmpScan
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Joshua Steer
AmpScan
Commits
a17e8f93
Commit
a17e8f93
authored
5 years ago
by
jack-parsons
Browse files
Options
Downloads
Patches
Plain Diff
Adding test for translating (may want to move to separate file)
parent
2baf041b
No related branches found
No related tags found
1 merge request
!23
Merge in Jack's changes
Pipeline
#845
passed
5 years ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
AmpScan/core.py
+10
-1
10 additions, 1 deletion
AmpScan/core.py
tests/sample_test.py
+27
-0
27 additions, 0 deletions
tests/sample_test.py
with
37 additions
and
1 deletion
AmpScan/core.py
+
10
−
1
View file @
a17e8f93
...
...
@@ -314,7 +314,16 @@ class AmpObject(trimMixin, smoothMixin, analyseMixin, visMixin):
Translation in [x, y, z]
"""
self
.
vert
[:]
+=
trans
# Check that trans is array like
if
isinstance
(
trans
,
(
list
,
np
.
ndarray
)):
# Check that trans has exactly 3 dimensions
if
len
(
trans
)
==
3
:
self
.
vert
[:]
+=
trans
else
:
raise
ValueError
(
"
Translation has incorrect dimensions. Expected 3 but found:
"
+
str
(
len
(
trans
)))
else
:
raise
TypeError
(
"
Translation is not array_like:
"
+
trans
)
def
centre
(
self
):
r
"""
...
...
This diff is collapsed.
Click to expand it.
tests/sample_test.py
+
27
−
0
View file @
a17e8f93
...
...
@@ -2,7 +2,9 @@ import unittest
import
os
import
sys
class
TestBasicFunction
(
unittest
.
TestCase
):
ACCURACY
=
3
# The number of decimal places to value accuracy for
def
SetUp
(
self
):
modPath
=
os
.
path
.
abspath
(
os
.
getcwd
())
...
...
@@ -48,6 +50,31 @@ class TestBasicFunction(unittest.TestCase):
#with self.assertRaises(TypeError):
#Amp.planarTrim([], plane=[])
def
test_translate
(
self
):
from
AmpScan.core
import
AmpObject
stlPath
=
self
.
get_path
(
"
sample_stl_sphere_BIN.stl
"
)
amp
=
AmpObject
(
stlPath
)
# Check that everything has been translated by 1
start
=
amp
.
vert
.
mean
(
axis
=
0
)[:]
amp
.
translate
([
1
,
-
1
,
0
])
end
=
amp
.
vert
.
mean
(
axis
=
0
)[:]
self
.
assertAlmostEqual
(
start
[
0
],
end
[
0
]
-
1
,
places
=
TestBasicFunction
.
ACCURACY
)
self
.
assertAlmostEqual
(
start
[
1
],
end
[
1
]
+
1
,
places
=
TestBasicFunction
.
ACCURACY
)
self
.
assertAlmostEqual
(
start
[
2
],
end
[
2
],
places
=
TestBasicFunction
.
ACCURACY
)
# Check that translating raises TypeError when translating with an invalid type
with
self
.
assertRaises
(
Exception
):
amp
.
translate
(
""
)
# Check that translating raises ValueError when translating with 2 dimensions
with
self
.
assertRaises
(
ValueError
):
amp
.
translate
([
0
,
0
])
# Check that translating raises ValueError when translating with 4 dimensions
with
self
.
assertRaises
(
ValueError
):
amp
.
translate
([
0
,
0
,
0
,
0
])
def
get_path
(
self
,
filename
):
"""
Method to get the absolute path to the testing files
...
...
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