From 2e1f340982dee4bf606209d415e80c9cf9df6bc1 Mon Sep 17 00:00:00 2001 From: Rohan Katreddy Date: Thu, 30 Jan 2025 21:57:33 -0500 Subject: [PATCH 1/6] Nearly completed test (with an unusual error) --- .../test_cluster_estimation_worker.py | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 tests/integration/test_cluster_estimation_worker.py diff --git a/tests/integration/test_cluster_estimation_worker.py b/tests/integration/test_cluster_estimation_worker.py new file mode 100644 index 00000000..f26c15c2 --- /dev/null +++ b/tests/integration/test_cluster_estimation_worker.py @@ -0,0 +1,68 @@ +import time +import multiprocessing as mp +from typing import List +from queue import Queue +import numpy as np +from modules.detection_in_world import DetectionInWorld +from utilities.workers import queue_proxy_wrapper, worker_controller +from modules.cluster_estimation import cluster_estimation_worker + + +def test_cluster_estimation_worker() -> int: + """ + Integration test for cluster estimation worker. + """ + + controller = worker_controller.WorkerController() + + mp_manager = mp.Manager() + input_queue = queue_proxy_wrapper.QueueProxyWrapper(mp_manager) + output_queue = queue_proxy_wrapper.QueueProxyWrapper(mp_manager) + + test_data = [ + DetectionInWorld.create( + np.array([[1, 1], [1, 2], [2, 2], [2, 1]]), np.array([1.5, 1.5]), 1, 0.9 + )[1], + DetectionInWorld.create( + np.array([[2, 2], [2, 3], [3, 3], [3, 2]]), np.array([2.5, 2.5]), 1, 0.85 + )[1], + ] + + worker_process = mp.Process( + target=cluster_estimation_worker, + args=( + 2, + 2, + 3, + 42, + input_queue, + output_queue, + controller, + ), + ) + + worker_process.start() + time.sleep(3) + + input_queue.queue.put(test_data) + time.sleep(5) + + output_results: List[List[DetectionInWorld]] = [] + while not output_queue.queue.empty(): + output_results.append(output_queue.queue.get()) + + print("Hello") + print(output_results) + + # Validating Output TBD + controller.request_exit() + + return 0 + + +if __name__ == "__main__": + result_main = test_cluster_estimation_worker() + if result_main < 0: + print(f"ERROR: Status code: {result_main}") + + print("Done!") \ No newline at end of file From ebc8470181986e15c7c1e35f1d3406c3f8f1a155 Mon Sep 17 00:00:00 2001 From: Rohan Katreddy Date: Thu, 6 Feb 2025 19:20:28 -0500 Subject: [PATCH 2/6] wrote cluster estimation worker integration test --- .../test_cluster_estimation_worker.py | 124 ++++++++++++++---- 1 file changed, 99 insertions(+), 25 deletions(-) diff --git a/tests/integration/test_cluster_estimation_worker.py b/tests/integration/test_cluster_estimation_worker.py index f26c15c2..8cbb2fb2 100644 --- a/tests/integration/test_cluster_estimation_worker.py +++ b/tests/integration/test_cluster_estimation_worker.py @@ -1,11 +1,14 @@ +""" +Test cluster_estimation_worker process. +""" + import time import multiprocessing as mp from typing import List -from queue import Queue import numpy as np -from modules.detection_in_world import DetectionInWorld from utilities.workers import queue_proxy_wrapper, worker_controller -from modules.cluster_estimation import cluster_estimation_worker +from modules.detection_in_world import DetectionInWorld +from modules.cluster_estimation.cluster_estimation_worker import cluster_estimation_worker def test_cluster_estimation_worker() -> int: @@ -13,49 +16,120 @@ def test_cluster_estimation_worker() -> int: Integration test for cluster estimation worker. """ + # Worker and controller setup. controller = worker_controller.WorkerController() mp_manager = mp.Manager() input_queue = queue_proxy_wrapper.QueueProxyWrapper(mp_manager) output_queue = queue_proxy_wrapper.QueueProxyWrapper(mp_manager) - test_data = [ - DetectionInWorld.create( - np.array([[1, 1], [1, 2], [2, 2], [2, 1]]), np.array([1.5, 1.5]), 1, 0.9 - )[1], - DetectionInWorld.create( - np.array([[2, 2], [2, 3], [3, 3], [3, 2]]), np.array([2.5, 2.5]), 1, 0.85 - )[1], - ] - worker_process = mp.Process( target=cluster_estimation_worker, args=( - 2, - 2, 3, - 42, + 0, + 3, + 0, input_queue, output_queue, controller, ), ) + # Second test set: 1 clusters + test_data_1 = [ + # Landing pad 1 + DetectionInWorld.create( + np.array([[1, 1], [1, 2], [2, 2], [2, 1]]), np.array([1.5, 1.5]), 1, 0.9 + )[1], + DetectionInWorld.create( + np.array([[1, 1], [1, 2], [2, 2], [2, 1]]), np.array([1.5, 1.5]), 1, 0.9 + )[1], + DetectionInWorld.create( + np.array([[1, 1], [1, 2], [2, 2], [2, 1]]), np.array([1.5, 1.5]), 1, 0.9 + )[1], + DetectionInWorld.create( + np.array([[1, 1], [1, 2], [2, 2], [2, 1]]), np.array([1.5, 1.5]), 1, 0.9 + )[1], + DetectionInWorld.create( + np.array([[1, 1], [1, 2], [2, 2], [2, 1]]), np.array([1.5, 1.5]), 1, 0.9 + )[1], + ] + + # First test set: 2 clusters + test_data_2 = [ + # Landing pad 1 + DetectionInWorld.create( + np.array([[1, 1], [1, 2], [2, 2], [2, 1]]), np.array([1.5, 1.5]), 1, 0.9 + )[1], + DetectionInWorld.create( + np.array([[1, 1], [1, 2], [2, 2], [2, 1]]), np.array([1.5, 1.5]), 1, 0.9 + )[1], + DetectionInWorld.create( + np.array([[1, 1], [1, 2], [2, 2], [2, 1]]), np.array([1.5, 1.5]), 1, 0.9 + )[1], + DetectionInWorld.create( + np.array([[1, 1], [1, 2], [2, 2], [2, 1]]), np.array([1.5, 1.5]), 1, 0.9 + )[1], + DetectionInWorld.create( + np.array([[1, 1], [1, 2], [2, 2], [2, 1]]), np.array([1.5, 1.5]), 1, 0.9 + )[1], + # Landing pad 2 + DetectionInWorld.create( + np.array([[10, 10], [10, 11], [11, 11], [11, 10]]), np.array([10.5, 10.5]), 1, 0.9 + )[1], + DetectionInWorld.create( + np.array([[10.1, 10.1], [10.1, 11.1], [11.1, 11.1], [11.1, 10.1]]), + np.array([10.6, 10.6]), + 1, + 0.92, + )[1], + DetectionInWorld.create( + np.array([[9.9, 9.9], [9.9, 10.9], [10.9, 10.9], [10.9, 9.9]]), + np.array([10.4, 10.4]), + 1, + 0.88, + )[1], + DetectionInWorld.create( + np.array([[10.2, 10.2], [10.2, 11.2], [11.2, 11.2], [11.2, 10.2]]), + np.array([10.7, 10.7]), + 1, + 0.95, + )[1], + DetectionInWorld.create( + np.array([[10.3, 10.3], [10.3, 11.3], [11.3, 11.3], [11.3, 10.3]]), + np.array([10.8, 10.8]), + 1, + 0.93, + )[1], + ] + + # Testing with test_data_1 (1 cluster) + + input_queue.queue.put(test_data_1) worker_process.start() - time.sleep(3) + time.sleep(1) + + output_results: List[List[DetectionInWorld]] = output_queue.queue.get() + + assert output_results is not None + assert len(output_results) == 1 + + time.sleep(1) + + # Testing with test_data_2 (2 clusters) - input_queue.queue.put(test_data) - time.sleep(5) + input_queue.queue.put(test_data_2) + time.sleep(1) - output_results: List[List[DetectionInWorld]] = [] - while not output_queue.queue.empty(): - output_results.append(output_queue.queue.get()) + output_results: List[List[DetectionInWorld]] = output_queue.queue.get() - print("Hello") - print(output_results) + assert output_results is not None + assert len(output_results) == 2 - # Validating Output TBD controller.request_exit() + input_queue.queue.put(None) + worker_process.join() return 0 @@ -65,4 +139,4 @@ def test_cluster_estimation_worker() -> int: if result_main < 0: print(f"ERROR: Status code: {result_main}") - print("Done!") \ No newline at end of file + print("Done!") From 8bd2fd727ef29aedf0d533ae474b6e13c44c45c1 Mon Sep 17 00:00:00 2001 From: Rohan Katreddy Date: Thu, 30 Jan 2025 21:57:33 -0500 Subject: [PATCH 3/6] Nearly completed test (with an unusual error) --- .../test_cluster_estimation_worker.py | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 tests/integration/test_cluster_estimation_worker.py diff --git a/tests/integration/test_cluster_estimation_worker.py b/tests/integration/test_cluster_estimation_worker.py new file mode 100644 index 00000000..f26c15c2 --- /dev/null +++ b/tests/integration/test_cluster_estimation_worker.py @@ -0,0 +1,68 @@ +import time +import multiprocessing as mp +from typing import List +from queue import Queue +import numpy as np +from modules.detection_in_world import DetectionInWorld +from utilities.workers import queue_proxy_wrapper, worker_controller +from modules.cluster_estimation import cluster_estimation_worker + + +def test_cluster_estimation_worker() -> int: + """ + Integration test for cluster estimation worker. + """ + + controller = worker_controller.WorkerController() + + mp_manager = mp.Manager() + input_queue = queue_proxy_wrapper.QueueProxyWrapper(mp_manager) + output_queue = queue_proxy_wrapper.QueueProxyWrapper(mp_manager) + + test_data = [ + DetectionInWorld.create( + np.array([[1, 1], [1, 2], [2, 2], [2, 1]]), np.array([1.5, 1.5]), 1, 0.9 + )[1], + DetectionInWorld.create( + np.array([[2, 2], [2, 3], [3, 3], [3, 2]]), np.array([2.5, 2.5]), 1, 0.85 + )[1], + ] + + worker_process = mp.Process( + target=cluster_estimation_worker, + args=( + 2, + 2, + 3, + 42, + input_queue, + output_queue, + controller, + ), + ) + + worker_process.start() + time.sleep(3) + + input_queue.queue.put(test_data) + time.sleep(5) + + output_results: List[List[DetectionInWorld]] = [] + while not output_queue.queue.empty(): + output_results.append(output_queue.queue.get()) + + print("Hello") + print(output_results) + + # Validating Output TBD + controller.request_exit() + + return 0 + + +if __name__ == "__main__": + result_main = test_cluster_estimation_worker() + if result_main < 0: + print(f"ERROR: Status code: {result_main}") + + print("Done!") \ No newline at end of file From 86456bc4c60eca7d33297f978eb538c8ed67336a Mon Sep 17 00:00:00 2001 From: Rohan Katreddy Date: Thu, 6 Feb 2025 19:20:28 -0500 Subject: [PATCH 4/6] wrote cluster estimation worker integration test --- .../test_cluster_estimation_worker.py | 124 ++++++++++++++---- 1 file changed, 99 insertions(+), 25 deletions(-) diff --git a/tests/integration/test_cluster_estimation_worker.py b/tests/integration/test_cluster_estimation_worker.py index f26c15c2..8cbb2fb2 100644 --- a/tests/integration/test_cluster_estimation_worker.py +++ b/tests/integration/test_cluster_estimation_worker.py @@ -1,11 +1,14 @@ +""" +Test cluster_estimation_worker process. +""" + import time import multiprocessing as mp from typing import List -from queue import Queue import numpy as np -from modules.detection_in_world import DetectionInWorld from utilities.workers import queue_proxy_wrapper, worker_controller -from modules.cluster_estimation import cluster_estimation_worker +from modules.detection_in_world import DetectionInWorld +from modules.cluster_estimation.cluster_estimation_worker import cluster_estimation_worker def test_cluster_estimation_worker() -> int: @@ -13,49 +16,120 @@ def test_cluster_estimation_worker() -> int: Integration test for cluster estimation worker. """ + # Worker and controller setup. controller = worker_controller.WorkerController() mp_manager = mp.Manager() input_queue = queue_proxy_wrapper.QueueProxyWrapper(mp_manager) output_queue = queue_proxy_wrapper.QueueProxyWrapper(mp_manager) - test_data = [ - DetectionInWorld.create( - np.array([[1, 1], [1, 2], [2, 2], [2, 1]]), np.array([1.5, 1.5]), 1, 0.9 - )[1], - DetectionInWorld.create( - np.array([[2, 2], [2, 3], [3, 3], [3, 2]]), np.array([2.5, 2.5]), 1, 0.85 - )[1], - ] - worker_process = mp.Process( target=cluster_estimation_worker, args=( - 2, - 2, 3, - 42, + 0, + 3, + 0, input_queue, output_queue, controller, ), ) + # Second test set: 1 clusters + test_data_1 = [ + # Landing pad 1 + DetectionInWorld.create( + np.array([[1, 1], [1, 2], [2, 2], [2, 1]]), np.array([1.5, 1.5]), 1, 0.9 + )[1], + DetectionInWorld.create( + np.array([[1, 1], [1, 2], [2, 2], [2, 1]]), np.array([1.5, 1.5]), 1, 0.9 + )[1], + DetectionInWorld.create( + np.array([[1, 1], [1, 2], [2, 2], [2, 1]]), np.array([1.5, 1.5]), 1, 0.9 + )[1], + DetectionInWorld.create( + np.array([[1, 1], [1, 2], [2, 2], [2, 1]]), np.array([1.5, 1.5]), 1, 0.9 + )[1], + DetectionInWorld.create( + np.array([[1, 1], [1, 2], [2, 2], [2, 1]]), np.array([1.5, 1.5]), 1, 0.9 + )[1], + ] + + # First test set: 2 clusters + test_data_2 = [ + # Landing pad 1 + DetectionInWorld.create( + np.array([[1, 1], [1, 2], [2, 2], [2, 1]]), np.array([1.5, 1.5]), 1, 0.9 + )[1], + DetectionInWorld.create( + np.array([[1, 1], [1, 2], [2, 2], [2, 1]]), np.array([1.5, 1.5]), 1, 0.9 + )[1], + DetectionInWorld.create( + np.array([[1, 1], [1, 2], [2, 2], [2, 1]]), np.array([1.5, 1.5]), 1, 0.9 + )[1], + DetectionInWorld.create( + np.array([[1, 1], [1, 2], [2, 2], [2, 1]]), np.array([1.5, 1.5]), 1, 0.9 + )[1], + DetectionInWorld.create( + np.array([[1, 1], [1, 2], [2, 2], [2, 1]]), np.array([1.5, 1.5]), 1, 0.9 + )[1], + # Landing pad 2 + DetectionInWorld.create( + np.array([[10, 10], [10, 11], [11, 11], [11, 10]]), np.array([10.5, 10.5]), 1, 0.9 + )[1], + DetectionInWorld.create( + np.array([[10.1, 10.1], [10.1, 11.1], [11.1, 11.1], [11.1, 10.1]]), + np.array([10.6, 10.6]), + 1, + 0.92, + )[1], + DetectionInWorld.create( + np.array([[9.9, 9.9], [9.9, 10.9], [10.9, 10.9], [10.9, 9.9]]), + np.array([10.4, 10.4]), + 1, + 0.88, + )[1], + DetectionInWorld.create( + np.array([[10.2, 10.2], [10.2, 11.2], [11.2, 11.2], [11.2, 10.2]]), + np.array([10.7, 10.7]), + 1, + 0.95, + )[1], + DetectionInWorld.create( + np.array([[10.3, 10.3], [10.3, 11.3], [11.3, 11.3], [11.3, 10.3]]), + np.array([10.8, 10.8]), + 1, + 0.93, + )[1], + ] + + # Testing with test_data_1 (1 cluster) + + input_queue.queue.put(test_data_1) worker_process.start() - time.sleep(3) + time.sleep(1) + + output_results: List[List[DetectionInWorld]] = output_queue.queue.get() + + assert output_results is not None + assert len(output_results) == 1 + + time.sleep(1) + + # Testing with test_data_2 (2 clusters) - input_queue.queue.put(test_data) - time.sleep(5) + input_queue.queue.put(test_data_2) + time.sleep(1) - output_results: List[List[DetectionInWorld]] = [] - while not output_queue.queue.empty(): - output_results.append(output_queue.queue.get()) + output_results: List[List[DetectionInWorld]] = output_queue.queue.get() - print("Hello") - print(output_results) + assert output_results is not None + assert len(output_results) == 2 - # Validating Output TBD controller.request_exit() + input_queue.queue.put(None) + worker_process.join() return 0 @@ -65,4 +139,4 @@ def test_cluster_estimation_worker() -> int: if result_main < 0: print(f"ERROR: Status code: {result_main}") - print("Done!") \ No newline at end of file + print("Done!") From 9f675871821cf1eaa6b268859b5e45eeab46e8d9 Mon Sep 17 00:00:00 2001 From: Rohan Katreddy Date: Sat, 8 Feb 2025 20:30:39 -0500 Subject: [PATCH 5/6] Added review changes: type checking, created constants, and import style conventions --- .../test_cluster_estimation_worker.py | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/tests/integration/test_cluster_estimation_worker.py b/tests/integration/test_cluster_estimation_worker.py index 8cbb2fb2..c4193822 100644 --- a/tests/integration/test_cluster_estimation_worker.py +++ b/tests/integration/test_cluster_estimation_worker.py @@ -5,10 +5,18 @@ import time import multiprocessing as mp from typing import List + import numpy as np + from utilities.workers import queue_proxy_wrapper, worker_controller -from modules.detection_in_world import DetectionInWorld from modules.cluster_estimation.cluster_estimation_worker import cluster_estimation_worker +from modules.detection_in_world import DetectionInWorld +from modules.object_in_world import ObjectInWorld + +MIN_ACTIVATION_THRESHOLD = 3 +MIN_NEW_POINTS_TO_RUN = 0 +MAX_NUM_COMPONENTS = 3 +RANDOM_STATE = 0 def test_cluster_estimation_worker() -> int: @@ -26,10 +34,10 @@ def test_cluster_estimation_worker() -> int: worker_process = mp.Process( target=cluster_estimation_worker, args=( - 3, - 0, - 3, - 0, + MIN_ACTIVATION_THRESHOLD, + MIN_NEW_POINTS_TO_RUN, + MAX_NUM_COMPONENTS, + RANDOM_STATE, input_queue, output_queue, controller, @@ -113,7 +121,9 @@ def test_cluster_estimation_worker() -> int: output_results: List[List[DetectionInWorld]] = output_queue.queue.get() assert output_results is not None + assert isinstance(output_results, list) assert len(output_results) == 1 + assert all(isinstance(obj, ObjectInWorld) for obj in output_results) time.sleep(1) @@ -125,7 +135,9 @@ def test_cluster_estimation_worker() -> int: output_results: List[List[DetectionInWorld]] = output_queue.queue.get() assert output_results is not None + assert isinstance(output_results, list) assert len(output_results) == 2 + assert all(isinstance(obj, ObjectInWorld) for obj in output_results) controller.request_exit() input_queue.queue.put(None) From b37c9652f77ee6d7339321a7687bb2bc7714721d Mon Sep 17 00:00:00 2001 From: Rohan Katreddy Date: Sun, 9 Feb 2025 18:47:23 -0500 Subject: [PATCH 6/6] review changes: corrected expected type of output_results --- tests/integration/test_cluster_estimation_worker.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/test_cluster_estimation_worker.py b/tests/integration/test_cluster_estimation_worker.py index c4193822..a4e06292 100644 --- a/tests/integration/test_cluster_estimation_worker.py +++ b/tests/integration/test_cluster_estimation_worker.py @@ -118,7 +118,7 @@ def test_cluster_estimation_worker() -> int: worker_process.start() time.sleep(1) - output_results: List[List[DetectionInWorld]] = output_queue.queue.get() + output_results: List[DetectionInWorld] = output_queue.queue.get() assert output_results is not None assert isinstance(output_results, list) @@ -132,7 +132,7 @@ def test_cluster_estimation_worker() -> int: input_queue.queue.put(test_data_2) time.sleep(1) - output_results: List[List[DetectionInWorld]] = output_queue.queue.get() + output_results: List[DetectionInWorld] = output_queue.queue.get() assert output_results is not None assert isinstance(output_results, list)