Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
hpp-spline
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
Container Registry
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
Humanoid Path Planner
hpp-spline
Commits
b75b6ed2
Commit
b75b6ed2
authored
5 years ago
by
Guilhem Saurel
Browse files
Options
Downloads
Patches
Plain Diff
[Python][Test] use unittest module
parent
01f88e9b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
python/test/test.py
+103
-94
103 additions, 94 deletions
python/test/test.py
with
103 additions
and
94 deletions
python/test/test.py
+
103
−
94
View file @
b75b6ed2
#!/usr/bin/env python
import
unittest
from
numpy
import
matrix
from
numpy.linalg
import
norm
from
hpp_spline
import
bezier
,
bezier6
,
curve_constraints
,
exact_cubic
,
from_bezier
,
polynom
,
spline_deriv_constraint
__EPS
=
1e-6
waypoints
=
matrix
([[
1.
,
2.
,
3.
],
[
4.
,
5.
,
6.
]]).
transpose
()
waypoints6
=
matrix
([[
1.
,
2.
,
3.
,
7.
,
5.
,
5.
],
[
4.
,
5.
,
6.
,
4.
,
5.
,
6.
]]).
transpose
()
time_waypoints
=
matrix
([
0.
,
1.
]).
transpose
()
# testing bezier curve
a
=
bezier6
(
waypoints6
)
a
=
bezier
(
waypoints
,
3.
)
assert
(
a
.
degree
==
a
.
nbWaypoints
-
1
)
a
.
min
()
a
.
max
()
a
(
0.4
)
assert
((
a
.
derivate
(
0.4
,
0
)
==
a
(
0.4
)).
all
())
a
.
derivate
(
0.4
,
2
)
a
=
a
.
compute_derivate
(
100
)
prim
=
a
.
compute_primitive
(
1
)
for
i
in
range
(
10
):
t
=
float
(
i
)
/
10.
assert
(
a
(
t
)
==
prim
.
derivate
(
t
,
1
)).
all
()
assert
(
prim
(
0
)
==
matrix
([
0.
,
0.
,
0.
])).
all
()
prim
=
a
.
compute_primitive
(
2
)
for
i
in
range
(
10
):
t
=
float
(
i
)
/
10.
assert
(
a
(
t
)
==
prim
.
derivate
(
t
,
2
)).
all
()
assert
(
prim
(
0
)
==
matrix
([
0.
,
0.
,
0.
])).
all
()
waypoints
=
matrix
([[
1.
,
2.
,
3.
],
[
4.
,
5.
,
6.
],
[
4.
,
5.
,
6.
],
[
4.
,
5.
,
6.
],
[
4.
,
5.
,
6.
]]).
transpose
()
a0
=
bezier
(
waypoints
)
a1
=
bezier
(
waypoints
,
3.
)
prim0
=
a0
.
compute_primitive
(
1
)
prim1
=
a1
.
compute_primitive
(
1
)
for
i
in
range
(
10
):
t
=
float
(
i
)
/
10.
assert
norm
(
a0
(
t
)
-
a1
(
3
*
t
))
<
__EPS
assert
norm
(
a0
.
derivate
(
t
,
1
)
-
a1
.
derivate
(
3
*
t
,
1
)
*
3.
)
<
__EPS
assert
norm
(
a0
.
derivate
(
t
,
2
)
-
a1
.
derivate
(
3
*
t
,
2
)
*
9.
)
<
__EPS
assert
norm
(
prim0
(
t
)
-
prim1
(
t
*
3
)
/
3.
)
<
__EPS
assert
(
prim
(
0
)
==
matrix
([
0.
,
0.
,
0.
])).
all
()
# testing bezier with constraints
c
=
curve_constraints
()
c
.
init_vel
=
matrix
([
0.
,
1.
,
1.
]).
transpose
()
c
.
end_vel
=
matrix
([
0.
,
1.
,
1.
]).
transpose
()
c
.
init_acc
=
matrix
([
0.
,
1.
,
-
1.
]).
transpose
()
c
.
end_acc
=
matrix
([
0.
,
100.
,
1.
]).
transpose
()
waypoints
=
matrix
([[
1.
,
2.
,
3.
],
[
4.
,
5.
,
6.
]]).
transpose
()
a
=
bezier
(
waypoints
,
c
)
assert
norm
(
a
.
derivate
(
0
,
1
)
-
c
.
init_vel
)
<
1e-10
assert
norm
(
a
.
derivate
(
1
,
2
)
-
c
.
end_acc
)
<
1e-10
# testing polynom function
a
=
polynom
(
waypoints
)
a
=
polynom
(
waypoints
,
-
1.
,
3.
)
a
.
min
()
a
.
max
()
a
(
0.4
)
assert
((
a
.
derivate
(
0.4
,
0
)
==
a
(
0.4
)).
all
())
a
.
derivate
(
0.4
,
2
)
# testing exact_cubic function
a
=
exact_cubic
(
waypoints
,
time_waypoints
)
a
.
min
()
a
.
max
()
a
(
0.4
)
assert
((
a
.
derivate
(
0.4
,
0
)
==
a
(
0.4
)).
all
())
a
.
derivate
(
0.4
,
2
)
# testing spline_deriv_constraints
c
=
curve_constraints
()
c
.
init_vel
c
.
end_vel
c
.
init_acc
c
.
end_acc
c
.
init_vel
=
matrix
([
0.
,
1.
,
1.
]).
transpose
()
c
.
end_vel
=
matrix
([
0.
,
1.
,
1.
]).
transpose
()
c
.
init_acc
=
matrix
([
0.
,
1.
,
1.
]).
transpose
()
c
.
end_acc
=
matrix
([
0.
,
1.
,
1.
]).
transpose
()
a
=
spline_deriv_constraint
(
waypoints
,
time_waypoints
)
a
=
spline_deriv_constraint
(
waypoints
,
time_waypoints
,
c
)
# converting bezier to polynom
a
=
bezier
(
waypoints
)
a_pol
=
from_bezier
(
a
)
assert
norm
(
a
(
0.3
)
-
a_pol
(
0.3
))
<
__EPS
class
TestSpline
(
unittest
.
TestCase
):
def
test_spline
(
self
):
waypoints
=
matrix
([[
1.
,
2.
,
3.
],
[
4.
,
5.
,
6.
]]).
transpose
()
waypoints6
=
matrix
([[
1.
,
2.
,
3.
,
7.
,
5.
,
5.
],
[
4.
,
5.
,
6.
,
4.
,
5.
,
6.
]]).
transpose
()
time_waypoints
=
matrix
([
0.
,
1.
]).
transpose
()
# testing bezier curve
a
=
bezier6
(
waypoints6
)
a
=
bezier
(
waypoints
,
3.
)
self
.
assertEqual
(
a
.
degree
,
a
.
nbWaypoints
-
1
)
a
.
min
()
a
.
max
()
a
(
0.4
)
self
.
assertTrue
((
a
.
derivate
(
0.4
,
0
)
==
a
(
0.4
)).
all
())
a
.
derivate
(
0.4
,
2
)
a
=
a
.
compute_derivate
(
100
)
prim
=
a
.
compute_primitive
(
1
)
for
i
in
range
(
10
):
t
=
float
(
i
)
/
10.
self
.
assertTrue
((
a
(
t
)
==
prim
.
derivate
(
t
,
1
)).
all
())
self
.
assertTrue
((
prim
(
0
)
==
matrix
([
0.
,
0.
,
0.
])).
all
())
prim
=
a
.
compute_primitive
(
2
)
for
i
in
range
(
10
):
t
=
float
(
i
)
/
10.
self
.
assertTrue
((
a
(
t
)
==
prim
.
derivate
(
t
,
2
)).
all
())
self
.
assertTrue
((
prim
(
0
)
==
matrix
([
0.
,
0.
,
0.
])).
all
())
waypoints
=
matrix
([[
1.
,
2.
,
3.
],
[
4.
,
5.
,
6.
],
[
4.
,
5.
,
6.
],
[
4.
,
5.
,
6.
],
[
4.
,
5.
,
6.
]]).
transpose
()
a0
=
bezier
(
waypoints
)
a1
=
bezier
(
waypoints
,
3.
)
prim0
=
a0
.
compute_primitive
(
1
)
prim1
=
a1
.
compute_primitive
(
1
)
for
i
in
range
(
10
):
t
=
float
(
i
)
/
10.
self
.
assertAlmostEqual
(
norm
(
a0
(
t
),
a1
(
3
*
t
)))
self
.
assertAlmostEqual
(
norm
(
a0
.
derivate
(
t
,
1
),
a1
.
derivate
(
3
*
t
,
1
)
*
3.
))
self
.
assertAlmostEqual
(
norm
(
a0
.
derivate
(
t
,
2
),
a1
.
derivate
(
3
*
t
,
2
)
*
9.
))
self
.
assertAlmostEqual
(
norm
(
prim0
(
t
),
prim1
(
t
*
3
)
/
3.
))
self
.
assertTrue
((
prim
(
0
)
==
matrix
([
0.
,
0.
,
0.
])).
all
())
# testing bezier with constraints
c
=
curve_constraints
()
c
.
init_vel
=
matrix
([
0.
,
1.
,
1.
]).
transpose
()
c
.
end_vel
=
matrix
([
0.
,
1.
,
1.
]).
transpose
()
c
.
init_acc
=
matrix
([
0.
,
1.
,
-
1.
]).
transpose
()
c
.
end_acc
=
matrix
([
0.
,
100.
,
1.
]).
transpose
()
waypoints
=
matrix
([[
1.
,
2.
,
3.
],
[
4.
,
5.
,
6.
]]).
transpose
()
a
=
bezier
(
waypoints
,
c
)
self
.
assertAlmostEqual
(
norm
(
a
.
derivate
(
0
,
1
),
c
.
init_vel
))
self
.
assertAlmostEqual
(
norm
(
a
.
derivate
(
1
,
2
),
c
.
end_acc
))
# testing polynom function
a
=
polynom
(
waypoints
)
a
=
polynom
(
waypoints
,
-
1.
,
3.
)
a
.
min
()
a
.
max
()
a
(
0.4
)
self
.
assertTrue
((
a
.
derivate
(
0.4
,
0
)
==
a
(
0.4
)).
all
())
a
.
derivate
(
0.4
,
2
)
# testing exact_cubic function
a
=
exact_cubic
(
waypoints
,
time_waypoints
)
a
.
min
()
a
.
max
()
a
(
0.4
)
self
.
assertTrue
((
a
.
derivate
(
0.4
,
0
)
==
a
(
0.4
)).
all
())
a
.
derivate
(
0.4
,
2
)
# testing spline_deriv_constraints
c
=
curve_constraints
()
c
.
init_vel
c
.
end_vel
c
.
init_acc
c
.
end_acc
c
.
init_vel
=
matrix
([
0.
,
1.
,
1.
]).
transpose
()
c
.
end_vel
=
matrix
([
0.
,
1.
,
1.
]).
transpose
()
c
.
init_acc
=
matrix
([
0.
,
1.
,
1.
]).
transpose
()
c
.
end_acc
=
matrix
([
0.
,
1.
,
1.
]).
transpose
()
a
=
spline_deriv_constraint
(
waypoints
,
time_waypoints
)
a
=
spline_deriv_constraint
(
waypoints
,
time_waypoints
,
c
)
# converting bezier to polynom
a
=
bezier
(
waypoints
)
a_pol
=
from_bezier
(
a
)
self
.
assertAlmostEqual
(
norm
(
a
(
0.3
),
a_pol
(
0.3
)))
if
__name__
==
'
__main__
'
:
unittest
.
main
()
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