brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.4 KiB · 303ef4d Raw
87 lines · plain
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8///9/// \file10/// This file contains the definition of the TestResult class, which aggregates11/// and stores the results of a math test run.12///13//===----------------------------------------------------------------------===//14 15#ifndef MATHTEST_TESTRESULT_HPP16#define MATHTEST_TESTRESULT_HPP17 18#include <cstdint>19#include <optional>20#include <tuple>21#include <utility>22 23namespace mathtest {24 25template <typename OutType, typename... InTypes>26class [[nodiscard]] TestResult {27public:28  struct [[nodiscard]] TestCase {29    std::tuple<InTypes...> Inputs;30    OutType Actual;31    OutType Expected;32 33    explicit constexpr TestCase(std::tuple<InTypes...> &&Inputs, OutType Actual,34                                OutType Expected) noexcept35        : Inputs(std::move(Inputs)), Actual(std::move(Actual)),36          Expected(std::move(Expected)) {}37  };38 39  TestResult() = default;40 41  explicit TestResult(uint64_t UlpDistance, bool IsFailure,42                      TestCase &&Case) noexcept43      : MaxUlpDistance(UlpDistance), FailureCount(IsFailure ? 1 : 0),44        TestCaseCount(1) {45    if (IsFailure)46      WorstFailingCase.emplace(std::move(Case));47  }48 49  void accumulate(const TestResult &Other) noexcept {50    if (Other.MaxUlpDistance > MaxUlpDistance) {51      MaxUlpDistance = Other.MaxUlpDistance;52      WorstFailingCase = Other.WorstFailingCase;53    }54 55    FailureCount += Other.FailureCount;56    TestCaseCount += Other.TestCaseCount;57  }58 59  [[nodiscard]] bool hasPassed() const noexcept { return FailureCount == 0; }60 61  [[nodiscard]] uint64_t getMaxUlpDistance() const noexcept {62    return MaxUlpDistance;63  }64 65  [[nodiscard]] uint64_t getFailureCount() const noexcept {66    return FailureCount;67  }68 69  [[nodiscard]] uint64_t getTestCaseCount() const noexcept {70    return TestCaseCount;71  }72 73  [[nodiscard]] const std::optional<TestCase> &74  getWorstFailingCase() const noexcept {75    return WorstFailingCase;76  }77 78private:79  uint64_t MaxUlpDistance = 0;80  uint64_t FailureCount = 0;81  uint64_t TestCaseCount = 0;82  std::optional<TestCase> WorstFailingCase;83};84} // namespace mathtest85 86#endif // MATHTEST_TESTRESULT_HPP87