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