32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
"""Worker-only numeric equivalence at hazard boundaries and disconnected patches."""
|
|
|
|
import argparse
|
|
import json
|
|
from pathlib import Path
|
|
|
|
import numpy as np
|
|
import terrain_costs as costs
|
|
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("--output", type=Path, required=True)
|
|
args = parser.parse_args()
|
|
assert costs._NATIVE is not None, "Compiled implementation must be installed"
|
|
engine = costs._NATIVE
|
|
rng = np.random.default_rng(230923)
|
|
cases = []
|
|
for dtype in (np.float32, np.float64):
|
|
for _ in range(200):
|
|
points = rng.uniform(-0.4, 0.4, (rng.integers(8, 180), 3)).astype(dtype)
|
|
points[:, 2] *= 0.3
|
|
cases.append(points)
|
|
for distance in (0.119999, 0.12, 0.120001):
|
|
for jump in (0.100099, 0.1001, 0.100101):
|
|
cases.append(np.array([[0, 0, 0], [distance, 0, jump]], dtype=dtype))
|
|
for points in cases:
|
|
costs._NATIVE = None
|
|
expected = costs.connected_grade(points)
|
|
costs._NATIVE = engine
|
|
assert costs.connected_grade(points) == expected
|
|
args.output.write_text(json.dumps({"passed": True, "cases": len(cases)}))
|
|
print(json.dumps({"passed": True, "cases": len(cases)}))
|