Download tests/test_drive_cpp.py from kimjunhan/vkgs-sim: direct link, hf CLI and curl.
- Browser
- Download file 1.85 kB
-
https://huggingface.co/kimjunhan/vkgs-sim/resolve/main/tests/test_drive_cpp.py
- Command line
-
hf download hf://kimjunhan/vkgs-sim/tests/test_drive_cpp.py
-
curl -L -o test_drive_cpp.py https://huggingface.co/kimjunhan/vkgs-sim/resolve/main/tests/test_drive_cpp.py
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++" | |
| 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 | |
| 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 | |