Continuing refactor work.
This commit is contained in:
@@ -27,23 +27,23 @@
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace scsl {
|
||||
namespace sctest {
|
||||
|
||||
|
||||
/// TestAssert is a variant on the assert macro. This variant is intended to be
|
||||
/// Assert is a variant on the assert macro. This variant is intended to be
|
||||
/// a drop-in replacement for the cassert macro: even in release mode, the tests
|
||||
/// should still run.
|
||||
///
|
||||
/// If NDEBUG is set, TestAssert will throw an exception if condition is false.
|
||||
/// If NDEBUG is set, Assert will throw an exception if condition is false.
|
||||
/// Otherwise, it calls assert after printing the message.
|
||||
///
|
||||
/// \param condition If true, TestAssert throws an exception.
|
||||
void TestAssert(bool condition);
|
||||
/// \param condition If true, Assert throws an exception.
|
||||
void Assert(bool condition);
|
||||
|
||||
|
||||
/// TestAssert is a variant on the assert macro.
|
||||
/// Assert is a variant on the assert macro.
|
||||
///
|
||||
/// If NDEBUG is set, TestAssert will throw an exception if condition is false.
|
||||
/// If NDEBUG is set, Assert will throw an exception if condition is false.
|
||||
/// Otherwise, it calls assert after printing the message.
|
||||
///
|
||||
/// In addition to NDEBUG, SCSL_NOEXCEPT will suppress assertions.
|
||||
@@ -52,7 +52,7 @@ void TestAssert(bool condition);
|
||||
///
|
||||
/// \param condition The condition to assert.
|
||||
/// \param message The message that should be displayed if condition is false.
|
||||
void TestAssert(bool condition, std::string message);
|
||||
void Assert(bool condition, std::string message);
|
||||
|
||||
|
||||
} // namespace scsl
|
||||
|
||||
53
include/sctest/Checks.h
Executable file
53
include/sctest/Checks.h
Executable file
@@ -0,0 +1,53 @@
|
||||
///
|
||||
/// \file Checks.h
|
||||
/// \author K. Isom <kyle@imap.cc>
|
||||
/// \date 2017-06-05
|
||||
/// \brief Provides a number of utility macros for testing.
|
||||
///
|
||||
/// Copyright 2017 K. Isom <kyle@imap.cc>
|
||||
///
|
||||
/// Permission to use, copy, modify, and/or distribute this software for
|
||||
/// any purpose with or without fee is hereby granted, provided that
|
||||
/// the above copyright notice and this permission notice appear in all /// copies.
|
||||
///
|
||||
/// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
|
||||
/// WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
|
||||
/// WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
|
||||
/// AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||
/// DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
|
||||
/// OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
||||
/// TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
/// PERFORMANCE OF THIS SOFTWARE.
|
||||
///
|
||||
|
||||
#ifndef SCTEST_CHECKS_H
|
||||
#define SCTEST_CHECKS_H
|
||||
|
||||
#include <scmp/Math.h>
|
||||
|
||||
|
||||
namespace sctest {
|
||||
|
||||
|
||||
// The following checks are designed as shortcuts that return false on
|
||||
// if some condition isn't met.
|
||||
#define SCTEST_CHECK(x) if (!(x)) { return false; }
|
||||
#define SCTEST_CHECK_FALSE(x) if ((x)) { return false; }
|
||||
#define SCTEST_CHECK_EQ(x, y) if ((x) != (y)) { return false; }
|
||||
#define SCTEST_CHECK_NE(x, y) if ((x) == (y)) { return false; }
|
||||
#define SCTEST_CHECK_ZERO(x) if ((x) != 0) { return false; }
|
||||
#define SCTEST_CHECK_GTZ(x) if ((x) > 0) { return false; }
|
||||
#define SCTEST_CHECK_GEZ(x) if ((x) >= 0) { return false; }
|
||||
#define SCTEST_CHECK_LEZ(x) if ((x) <= 0) { return false; }
|
||||
#define SCTEST_CHECK_LTZ(x) if ((x) < 0) { return false; }
|
||||
#define SCTEST_CHECK_FEQ(x, y) { float eps; scmp::DefaultEpsilon(eps); if (!scmp::WithinTolerance((x), (y), eps)) { return false; }}
|
||||
#define SCTEST_CHECK_DEQ(x, y) { double eps; scmp::DefaultEpsilon(eps); if (!scmp::WithinTolerance((x), (y), eps)) { return false; }}
|
||||
|
||||
#define SCTEST_CHECK_FEQ_EPS(x, y, eps) { if (!scmp::WithinTolerance((x), (y), eps)) { return false; }}
|
||||
#define SCTEST_CHECK_DEQ_EPS(x, y, eps) { if (!scmp::WithinTolerance((x), (y), eps)) { return false; }}
|
||||
|
||||
|
||||
} // namespace sctest
|
||||
|
||||
|
||||
#endif
|
||||
70
include/sctest/Exceptions.h
Normal file
70
include/sctest/Exceptions.h
Normal file
@@ -0,0 +1,70 @@
|
||||
///
|
||||
/// \file Exceptions.h
|
||||
/// \author K. Isom <kyle@imap.cc>
|
||||
/// \date 2023-10-10
|
||||
/// \brief Custom exceptions for use in SCSL used in writing test programs.
|
||||
///
|
||||
/// Copyright 2023 K. Isom <kyle@imap.cc>
|
||||
///
|
||||
/// Permission to use, copy, modify, and/or distribute this software for
|
||||
/// any purpose with or without fee is hereby granted, provided that
|
||||
/// the above copyright notice and this permission notice appear in all /// copies.
|
||||
///
|
||||
/// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
|
||||
/// WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
|
||||
/// WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
|
||||
/// AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||
/// DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
|
||||
/// OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
||||
/// TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
/// PERFORMANCE OF THIS SOFTWARE.
|
||||
///
|
||||
|
||||
#ifndef SCSL_EXCEPTIONS_H
|
||||
#define SCSL_EXCEPTIONS_H
|
||||
|
||||
|
||||
#include <exception>
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace sctest {
|
||||
|
||||
|
||||
/// NotImplemented is an exception reserved for unsupported platforms.
|
||||
///
|
||||
/// It is used to mark functionality included for compatibility, and useful for
|
||||
/// debugging.
|
||||
class NotImplemented : public std::exception {
|
||||
public:
|
||||
/// NotImplemented exceptions are constructed with a platform name.
|
||||
explicit NotImplemented(const char *pl) : platform((char *)pl) {}
|
||||
|
||||
/// what returns a message naming the platform.
|
||||
const char *what() const throw() {
|
||||
return this->platform;
|
||||
}
|
||||
private:
|
||||
char *platform;
|
||||
};
|
||||
|
||||
|
||||
/// AssertionFailed indicates that some invariant didn't hold.
|
||||
class AssertionFailed : public std::exception {
|
||||
public:
|
||||
/// AssertionFailed is constructed with a message describing what
|
||||
/// failed.
|
||||
explicit AssertionFailed(std::string message);
|
||||
|
||||
/// what returns a message describing the exception.
|
||||
const char *what() const throw();
|
||||
|
||||
private:
|
||||
std::string msg;
|
||||
};
|
||||
|
||||
|
||||
} // namespace sctest
|
||||
|
||||
|
||||
#endif // SCSL_EXCEPTIONS_H
|
||||
@@ -21,8 +21,8 @@
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#ifndef __SCTEST_REPORT_H
|
||||
#define __SCTEST_REPORT_H
|
||||
#ifndef SCTEST_REPORT_H
|
||||
#define SCTEST_REPORT_H
|
||||
|
||||
#include <chrono>
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#ifndef __SCTEST_SIMPLESUITE_H
|
||||
#define __SCTEST_SIMPLESUITE_H
|
||||
#ifndef SCTEST_SIMPLESUITE_H
|
||||
#define SCTEST_SIMPLESUITE_H
|
||||
|
||||
// SimpleSuite.h
|
||||
// This header file defines the interface for a simple suite of tests.
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
//
|
||||
// Project: scccl
|
||||
// File: include/test/checks.h
|
||||
// Author: Kyle Isom
|
||||
// Date: 2017-06-05
|
||||
// Namespace: test.
|
||||
//
|
||||
// checks.h defines a number of macros (which are global in scope) for
|
||||
// use in test functions that return bools.
|
||||
//
|
||||
// Copyright 2017 Kyle Isom <kyle@imap.cc>
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#ifndef __SCTEST_CHECKS_H
|
||||
#define __SCTEST_CHECKS_H
|
||||
|
||||
#include <scmp/Math.h>
|
||||
|
||||
|
||||
namespace sctest {
|
||||
|
||||
|
||||
// The following checks are designed as shortcuts that just return false on certain
|
||||
// conditions.
|
||||
#define SCTEST_CHECK(x) if (!(x)) { return false; }
|
||||
#define SCTEST_CHECK_FALSE(x) if ((x)) { return false; }
|
||||
#define SCTEST_CHECK_EQ(x, y) if ((x) != (y)) { return false; }
|
||||
#define SCTEST_CHECK_NE(x, y) if ((x) == (y)) { return false; }
|
||||
#define SCTEST_CHECK_ZERO(x) if ((x) != 0) { return false; }
|
||||
#define SCTEST_CHECK_GTZ(x) if ((x) > 0) { return false; }
|
||||
#define SCTEST_CHECK_GEZ(x) if ((x) >= 0) { return false; }
|
||||
#define SCTEST_CHECK_LEZ(x) if ((x) <= 0) { return false; }
|
||||
#define SCTEST_CHECK_LTZ(x) if ((x) < 0) { return false; }
|
||||
#define SCTEST_CHECK_FEQ(x, y) { float eps; scmp::DefaultEpsilon(eps); if (!scmp::WithinTolerance((x), (y), eps)) { return false; }}
|
||||
#define SCTEST_CHECK_DEQ(x, y) { double eps; scmp::DefaultEpsilon(eps); if (!scmp::WithinTolerance((x), (y), eps)) { return false; }}
|
||||
|
||||
} // namespace test
|
||||
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user