Skip to content

Commit

Permalink
Test code clean up (AtsushiSakai#456)
Browse files Browse the repository at this point in the history
* Test code clean up

* Test code clean up

* Test code clean up

* Test code clean up

* Test code clean up

* Test code clean up

* Test code clean up

* Test code clean up

* Test code clean up

* Test code clean up

* Test code clean up

* Test code clean up

* Test code clean up

* Test code clean up

* Test code clean up

* Test code clean up

* Test code clean up

* Test code clean up

* Test code clean up

* Test code clean up

* Test code clean up

* Test code clean up

* Test code clean up

* Test code clean up

* Test code clean up
  • Loading branch information
AtsushiSakai authored Jan 12, 2021
1 parent 8861977 commit 67d7d5c
Show file tree
Hide file tree
Showing 88 changed files with 850 additions and 1,310 deletions.
File renamed without changes.
4 changes: 4 additions & 0 deletions AerialNavigation/drone_3d_trajectory_following/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import os
import sys

sys.path.append(os.path.dirname(os.path.abspath(__file__)))
3 changes: 3 additions & 0 deletions ArmNavigation/n_joint_arm_3d/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import sys
import os
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""
import numpy as np

from NLinkArm import NLinkArm
from ArmNavigation.n_joint_arm_to_point_control.NLinkArm import NLinkArm

# Simulation parameters
Kp = 2
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016 Atsushi Sakai
Copyright (c) 2016 - 2021 Atsushi Sakai

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Empty file added Localization/__init__.py
Empty file.
Empty file added Mapping/__init__.py
Empty file.
Empty file.
4 changes: 4 additions & 0 deletions Mapping/rectangle_fitting/__init_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import os
import sys

sys.path.append(os.path.dirname(os.path.abspath(__file__)))
3 changes: 2 additions & 1 deletion Mapping/rectangle_fitting/rectangle_fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
from enum import Enum
from scipy.spatial.transform import Rotation as Rot

from simulator import VehicleSimulator, LidarSimulator
from Mapping.rectangle_fitting.simulator \
import VehicleSimulator, LidarSimulator

show_animation = True

Expand Down
8 changes: 8 additions & 0 deletions PathPlanning/ClosedLoopRRTStar/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import os
import sys

sys.path.append(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(os.path.dirname(
os.path.abspath(__file__)) + "/../ReedsSheppPath/")
sys.path.append(os.path.dirname(
os.path.abspath(__file__)) + "/../RRTStarReedsShepp/")
24 changes: 7 additions & 17 deletions PathPlanning/ClosedLoopRRTStar/closed_loop_rrt_star_car.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,13 @@
"""

import os
import sys

import matplotlib.pyplot as plt
import numpy as np
import reeds_shepp_path_planning
from rrt_star_reeds_shepp import RRTStarReedsShepp

import pure_pursuit

sys.path.append(os.path.dirname(
os.path.abspath(__file__)) + "/../ReedsSheppPath/")
sys.path.append(os.path.dirname(
os.path.abspath(__file__)) + "/../RRTStarReedsShepp/")

try:
import reeds_shepp_path_planning
import unicycle_model
from rrt_star_reeds_shepp import RRTStarReedsShepp
except ImportError:
raise
import unicycle_model

show_animation = True

Expand Down Expand Up @@ -77,7 +65,8 @@ def search_best_feasible_path(self, path_indexs):
for ind in path_indexs:
path = self.generate_final_course(ind)

flag, x, y, yaw, v, t, a, d = self.check_tracking_path_is_feasible(path)
flag, x, y, yaw, v, t, a, d = self.check_tracking_path_is_feasible(
path)

if flag and best_time >= t[-1]:
print("feasible path is found")
Expand Down Expand Up @@ -186,7 +175,8 @@ def main(gx=6.0, gy=7.0, gyaw=np.deg2rad(90.0), max_iter=100):
obstacle_list,
[-2.0, 20.0],
max_iter=max_iter)
flag, x, y, yaw, v, t, a, d = closed_loop_rrt_star.planning(animation=show_animation)
flag, x, y, yaw, v, t, a, d = closed_loop_rrt_star.planning(
animation=show_animation)

if not flag:
print("cannot find feasible path")
Expand Down
7 changes: 7 additions & 0 deletions PathPlanning/GridBasedSweepCPP/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import os
import sys

GRID_MAP_LIB = os.path.dirname(os.path.abspath(__file__)) + \
"/../../Mapping/"

sys.path.append(GRID_MAP_LIB)
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,12 @@
"""

import math
import os
import sys
from enum import IntEnum

import matplotlib.pyplot as plt
import numpy as np
from scipy.spatial.transform import Rotation as Rot

sys.path.append(os.path.relpath("../../Mapping/grid_map_lib/"))
try:
from grid_map_lib import GridMap
except ImportError:
raise
from Mapping.grid_map_lib.grid_map_lib import GridMap

do_animation = True

Expand Down
4 changes: 4 additions & 0 deletions PathPlanning/HybridAStar/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import os
import sys

sys.path.append(os.path.dirname(os.path.abspath(__file__)))
4 changes: 4 additions & 0 deletions PathPlanning/VoronoiRoadMap/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import os
import sys

sys.path.append(os.path.dirname(os.path.abspath(__file__)))
Empty file added PathTracking/__init__.py
Empty file.
Empty file added __init__.py
Empty file.
6 changes: 4 additions & 2 deletions runtests.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env bash
echo "Run test suites! "
# tests: include unittest based tests

# === pytest based test runner ===
# -Werror: warning as error
# --durations=0: show ranking of test durations
pytest tests -Werror --durations=0
# -l (--showlocals); show local variables when test failed
pytest tests -l -Werror --durations=0
13 changes: 13 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""Path hack to make tests work."""
import sys
import os
import pytest

TEST_DIR = os.path.dirname(os.path.abspath(__file__))
sys.path.append(TEST_DIR) # to import this file from test code.
ROOT_DIR = os.path.dirname(TEST_DIR)
sys.path.append(ROOT_DIR)


def run_this_test(file):
pytest.main([os.path.abspath(file)])
16 changes: 6 additions & 10 deletions tests/test_LQR_planner.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import sys
from unittest import TestCase

sys.path.append("./PathPlanning/LQRPlanner")

import conftest # Add root path to sys.path
from PathPlanning.LQRPlanner import LQRplanner as m

print(__file__)

def test_1():
m.SHOW_ANIMATION = False
m.main()

class Test(TestCase):

def test1(self):
m.SHOW_ANIMATION = False
m.main()
if __name__ == '__main__':
conftest.run_this_test(__file__)
23 changes: 7 additions & 16 deletions tests/test_a_star.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
from unittest import TestCase
import sys
import os
sys.path.append(os.path.dirname(__file__) + "/../")
try:
from PathPlanning.AStar import a_star as m
except:
raise
import conftest
from PathPlanning.AStar import a_star as m


class Test(TestCase):
def test_1():
m.show_animation = False
m.main()

def test1(self):
m.show_animation = False
m.main()


if __name__ == '__main__': # pragma: no cover
test = Test()
test.test1()
if __name__ == '__main__':
conftest.run_this_test(__file__)
29 changes: 9 additions & 20 deletions tests/test_a_star_searching_two_side.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
from unittest import TestCase
import os
import sys
import conftest
from PathPlanning.AStar import a_star_searching_from_two_side as m

sys.path.append(os.path.dirname(__file__) + '/../')

try:
from PathPlanning.AStar import a_star_searching_from_two_side as m
except ImportError:
raise
def test1():
m.show_animation = False
m.main(800)


class Test(TestCase):

def test1(self):
m.show_animation = False
m.main(800)

def test2(self):
m.show_animation = False
m.main(5000) # increase obstacle number, block path
def test2():
m.show_animation = False
m.main(5000) # increase obstacle number, block path


if __name__ == '__main__':
test = Test()
test.test1()
test.test2()
conftest.run_this_test(__file__)
94 changes: 44 additions & 50 deletions tests/test_a_star_variants.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,44 @@
import PathPlanning.AStar.a_star_variants as astar
from unittest import TestCase
import sys
import os
sys.path.append(os.path.dirname(__file__) + "/../")


class Test(TestCase):

def test(self):
# A* with beam search
astar.show_animation = False

astar.use_beam_search = True
astar.main()
self.reset_all()

# A* with iterative deepening
astar.use_iterative_deepening = True
astar.main()
self.reset_all()

# A* with dynamic weighting
astar.use_dynamic_weighting = True
astar.main()
self.reset_all()

# theta*
astar.use_theta_star = True
astar.main()
self.reset_all()

# A* with jump point
astar.use_jump_point = True
astar.main()
self.reset_all()

@staticmethod
def reset_all():
astar.show_animation = False
astar.use_beam_search = False
astar.use_iterative_deepening = False
astar.use_dynamic_weighting = False
astar.use_theta_star = False
astar.use_jump_point = False


if __name__ == '__main__': # pragma: no cover
test = Test()
test.test()
import PathPlanning.AStar.a_star_variants as a_star
import conftest


def test_1():
# A* with beam search
a_star.show_animation = False

a_star.use_beam_search = True
a_star.main()
reset_all()

# A* with iterative deepening
a_star.use_iterative_deepening = True
a_star.main()
reset_all()

# A* with dynamic weighting
a_star.use_dynamic_weighting = True
a_star.main()
reset_all()

# theta*
a_star.use_theta_star = True
a_star.main()
reset_all()

# A* with jump point
a_star.use_jump_point = True
a_star.main()
reset_all()


def reset_all():
a_star.show_animation = False
a_star.use_beam_search = False
a_star.use_iterative_deepening = False
a_star.use_dynamic_weighting = False
a_star.use_theta_star = False
a_star.use_jump_point = False


if __name__ == '__main__':
conftest.run_this_test(__file__)
27 changes: 8 additions & 19 deletions tests/test_batch_informed_rrt_star.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
from unittest import TestCase
import sys
import os
import random
sys.path.append(os.path.dirname(__file__) + "/../")
try:
from PathPlanning.BatchInformedRRTStar import batch_informed_rrtstar as m
except ImportError:
raise

print(__file__)
import conftest
from PathPlanning.BatchInformedRRTStar import batch_informed_rrtstar as m

random.seed(12345)

def test_1():
m.show_animation = False
random.seed(12345)
m.main(maxIter=10)

class Test(TestCase):

def test1(self):
m.show_animation = False
m.main(maxIter=10)


if __name__ == '__main__': # pragma: no cover
test = Test()
test.test1()
if __name__ == '__main__':
conftest.run_this_test(__file__)
Loading

0 comments on commit 67d7d5c

Please sign in to comment.