vkgs-sim / tests /test_drive_cpp.py
kimjunhan's picture
Add files using upload-large-folder tool
4c75661 verified
Raw History Blame Contribute Delete
1.85 kB
"""src/vkgs/src/drive.hpp (ํ—ค๋” ์ „์šฉ) ์˜ ์ถฉ๋Œยทํ›„์ง„ ๋กœ์ง์„ g++ ๋กœ ์ปดํŒŒ์ผํ•ด ์‹œํ—˜ํ•œ๋‹ค. ์ฐฝ์„ ๋„์šฐ์ง€ ์•Š๋Š”๋‹ค."""
import os
import shutil
import subprocess
from pathlib import Path
import numpy as np
import pytest
ROOT = Path(__file__).resolve().parents[1]
# ๋ทฐ์–ด ๋นŒ๋“œ์™€ ๊ฐ™์€ ์ปดํŒŒ์ผ๋Ÿฌ (conda gcc 12, $CXX). ์‹œ์Šคํ…œ g++ 9 ๋Š” C++20 ์„ ๋ชจ๋ฅธ๋‹ค
CXX = os.environ.get("CXX") or "g++"
@pytest.mark.skipif(shutil.which(CXX) is None, reason="g++ ์—†์Œ")
def test_drive_collision_and_reverse(tmp_path):
res, n, x0 = 0.2, 200, -20.0
g = np.zeros((n, n), np.uint8)
xs = (np.arange(n) + 0.5) * res + x0
g[:, (xs >= 10) & (xs < 10.4)] = 255 # x = 10 m ์˜ ๋ฒฝ
g[np.ix_((xs > 0.3) & (xs < 0.7), (xs > 0.9) & (xs < 1.3))] = 255 # ์ถœ๋ฐœ ์ž์„ธ ์ฐจ์ฒด ๋ฐ‘์˜ ๊ธฐ๋‘ฅ
g[np.ix_((xs > 5.0) & (xs < 5.2), (xs > -10.0) & (xs < -9.8))] = 255 # ์™ธํ†จ์ด ํ•œ ์นธ (x -10, y 5) โ€” ์ฐจ์ฒด ์˜†์„ ์Šค์นœ๋‹ค
pgm = tmp_path / "obst.pgm"
pgm.write_bytes(f"P5\n# nusim obstacles {x0} {x0} {res}\n{n} {n}\n255\n".encode() + g.tobytes())
exe = tmp_path / "t"
subprocess.run([CXX, "-std=c++20", "-O1", "-I", str(ROOT / "src/vkgs/src"),
str(ROOT / "tests/cpp/test_drive.cpp"), "-o", str(exe)], check=True)
r = subprocess.run([str(exe), str(pgm)], capture_output=True, text=True)
assert r.returncode == 0, r.stdout + r.stderr
@pytest.mark.skipif(shutil.which(CXX) is None, reason="g++ ์—†์Œ")
def test_autopilot_follows_curve_and_stops(tmp_path):
exe = tmp_path / "ap"
subprocess.run([CXX, "-std=c++20", "-O1", "-I", str(ROOT / "src/vkgs/src"),
str(ROOT / "tests/cpp/test_autopilot.cpp"), "-o", str(exe)], check=True)
r = subprocess.run([str(exe)], capture_output=True, text=True)
assert r.returncode == 0, r.stdout + r.stderr