X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fvimcoder;a=blobdiff_plain;f=src%2Fcom%2Fdogcows%2Fresources%2FC%2B%2BDriver;h=9ca857968510527b6388536028a3a67e6dbf0a2d;hp=142fdac9d5745d375da6329e15e810427cbd0c87;hb=540c07677f84c2680c808ecfb6be4ad6bb61237e;hpb=a99a612f093719bc182b2e7952c6be9138931be7 diff --git a/src/com/dogcows/resources/C++Driver b/src/com/dogcows/resources/C++Driver index 142fdac..9ca8579 100644 --- a/src/com/dogcows/resources/C++Driver +++ b/src/com/dogcows/resources/C++Driver @@ -1,6 +1,8 @@ #include "$CLASSNAME$.cc" +#include +#include #include #include #include @@ -12,6 +14,7 @@ using namespace std; +const static double __EPSILON = 1e-9; static double __time = 0.0; static void __timer_start() @@ -99,6 +102,38 @@ std::istream& operator >> (std::istream& in, std::vector& vec) return in; } +template +bool __equals(const T& actual, const T& expected) +{ + return actual == expected; +} + +bool __equals(double actual, double expected) +{ + if (std::abs(actual - expected) < __EPSILON) + { + return true; + } + else + { + double minimum = std::min(expected * (1.0 - __EPSILON), expected * (1.0 + __EPSILON)); + double maximum = std::max(expected * (1.0 - __EPSILON), expected * (1.0 + __EPSILON)); + return actual > minimum && actual < maximum; + } +} + +bool __equals(const std::vector& actual, const std::vector& expected) +{ + if (actual.size() != expected.size()) + return false; + + for (size_t i = 0; i < actual.size(); ++i) + if (!__equals(actual[i], expected[i])) + return false; + + return true; +} + int main(int argc, char* argv[]) { @@ -127,7 +162,7 @@ int main(int argc, char* argv[]) double __t = __timer_stop(); - if (__actual == __expected) + if (__equals(__actual, __expected)) { std::cout << "[PASS] in " << __t << " seconds." << std::endl; ++__pass;