serna37's Library

Logo

C++ アルゴリズムとデータ構造のライブラリ

View the Project on GitHub serna37/library-cpp

:heavy_check_mark: 三角形の面積のテスト
(tests/geometry.area_triangle.test.cpp)

Depends on

Code

#define PROBLEM                                                                \
    "https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_1_A"
#include "template/template.hpp"
#include "library/geometry/area_triangle.hpp"
// 浮動小数点の比較用ヘルパー
bool is_near(double a, double b, double epsilon = 1e-9) {
    return abs(a - b) < epsilon;
}
void test_area_triangle() {
    // ケース1: 底辺2、高さ1の直角三角形
    // (0,0), (2,0), (0,1) -> 面積: 2 * 1 / 2 = 1.0
    assert(is_near(area_triangle(0, 0, 2, 0, 0, 1), 1.0));
    // ケース2: 単位正方形の半分 (45度の直角二等辺三角形)
    // (0,0), (1,0), (0,1) -> 面積: 0.5
    assert(is_near(area_triangle(0.0, 0.0, 1.0, 0.0, 0.0, 1.0), 0.5));
    // ケース3: 座標が負のケース
    // (-1,-1), (1,-1), (0,1) -> 底辺2, 高さ2 -> 面積: 2 * 2 / 2 = 2.0
    assert(is_near(area_triangle(-1, -1, 1, -1, 0, 1), 2.0));
    // ケース4: 3点が一直線上にある場合(面積0)
    // (0,0), (1,1), (2,2)
    assert(is_near(area_triangle(0, 0, 1, 1, 2, 2), 0.0));
    // ケース5: 大きな値の計算
    // (0,0), (100,0), (0,100) -> 面積: 100 * 100 / 2 = 5000.0
    assert(is_near(area_triangle(0, 0, 100, 0, 0, 100), 5000.0));
}
/**
 * @brief 三角形の面積のテスト
 */
void solve() {
    print("Hello World");
    test_area_triangle();
}
Traceback (most recent call last):
  File "/home/runner/.local/lib/python3.12/site-packages/onlinejudge_verify/documentation/build.py", line 71, in _render_source_code_stat
    bundled_code = language.bundle(stat.path, basedir=basedir, options={'include_paths': [basedir]}).decode()
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/.local/lib/python3.12/site-packages/onlinejudge_verify/languages/cplusplus.py", line 187, in bundle
    bundler.update(path)
  File "/home/runner/.local/lib/python3.12/site-packages/onlinejudge_verify/languages/cplusplus_bundle.py", line 401, in update
    self.update(self._resolve(pathlib.Path(included), included_from=path))
  File "/home/runner/.local/lib/python3.12/site-packages/onlinejudge_verify/languages/cplusplus_bundle.py", line 400, in update
    raise BundleErrorAt(path, i + 1, "unable to process #include in #if / #ifdef / #ifndef other than include guards")
onlinejudge_verify.languages.cplusplus_bundle.BundleErrorAt: template/template.hpp: line 7: unable to process #include in #if / #ifdef / #ifndef other than include guards
Back to top page