File size: 1,846 Bytes
4c75661 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | """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
|