2
0
mirror of https://github.com/rehlds/rehlds.git synced 2025-01-18 09:37:59 +03:00
rehlds/dep/cppunitlite/src/Assertions.cpp
dreamstalker 4b1eabc541 Mathlib unit tests
Added REHLDS_OP_PEDANTIC define to all configs in the msvc project
Fixed CrossProduct
2015-05-16 01:44:13 +04:00

66 lines
2.6 KiB
C++

#include "cppunitlite/Assertions.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sstream>
void Assertions::StringEquals(std::string message, std::string expected, std::string actual, const char* fileName, long lineNumber) {
if (expected != actual) {
std::stringstream ss;
ss << message << " (expected '" << expected << "', got '" << actual << "')";
throw TestFailException(ss.str(), std::string(fileName), lineNumber);
}
}
void Assertions::StringEquals(std::string message, const char* expected, const char* actual, const char* fileName, long lineNumber) {
if (expected == NULL) {
std::stringstream ss;
ss << message << " (expected '" << expected << "', got NULL";
throw TestFailException(ss.str(), std::string(fileName), lineNumber);
}
if (strcmp(expected, actual)) {
std::stringstream ss;
ss << message << " (expected '" << expected << "', got '" << actual << "')";
throw TestFailException(ss.str(), std::string(fileName), lineNumber);
}
}
void Assertions::ConditionFailed(std::string message, std::string condition, const char* fileName, long lineNumber) {
std::stringstream ss;
ss << message << " (condition failed: " << condition << ")";
throw TestFailException(ss.str(), std::string(fileName), lineNumber);
}
void Assertions::LongEquals(std::string message, long expected, long actual, const char* fileName, long lineNumber) {
if (expected != actual) {
std::stringstream ss;
ss << message << " (expected '" << expected << "', got '" << actual << "')";
throw TestFailException(ss.str(), std::string(fileName), lineNumber);
}
}
void Assertions::UInt32Equals(std::string message, unsigned int expected, unsigned int actual, const char* fileName, long lineNumber) {
if (expected != actual) {
std::stringstream ss;
ss << message << " (expected '" << expected << "', got '" << actual << "')";
throw TestFailException(ss.str(), std::string(fileName), lineNumber);
}
}
void Assertions::CharEquals(std::string message, char expected, char actual, const char* fileName, long lineNumber) {
if (expected != actual) {
std::stringstream ss;
ss << message << " (expected '" << expected << "', got '" << actual << "')";
throw TestFailException(ss.str(), std::string(fileName), lineNumber);
}
}
void Assertions::DoubleEquals(std::string message, double expected, double actual, double epsilon, const char* fileName, long lineNumber) {
if (abs(expected - actual) > epsilon) {
std::stringstream ss;
ss << message << " (expected '" << expected << "', got '" << actual << "')";
throw TestFailException(ss.str(), std::string(fileName), lineNumber);
}
}