From f90dd4ffc4b679e61a2a8cf43853b7d3c72c3e83 Mon Sep 17 00:00:00 2001 From: randomguy3 Date: Tue, 17 Jan 2012 18:39:31 +0000 Subject: Calculate the head and tail of edges to be just where they contact the node (ie: behave more like tikz). git-svn-id: https://tikzit.svn.sourceforge.net/svnroot/tikzit/trunk@388 7c02a99a-9b00-45e3-bf44-6f3dd7fddb64 --- tikzit/src/common/test/test.m | 79 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 75 insertions(+), 4 deletions(-) (limited to 'tikzit/src/common/test/test.m') diff --git a/tikzit/src/common/test/test.m b/tikzit/src/common/test/test.m index 5e05c6e..8437646 100644 --- a/tikzit/src/common/test/test.m +++ b/tikzit/src/common/test/test.m @@ -57,13 +57,64 @@ static NSString *indents[6] = @end +BOOL fuzzyCompare(float f1, float f2) { + return (ABS(f1 - f2) <= 0.00001f * MAX(1.0f,MIN(ABS(f1), ABS(f2)))); +} + +BOOL fuzzyComparePoints (NSPoint p1, NSPoint p2) { + return fuzzyCompare (p1.x, p2.x) && fuzzyCompare (p1.y, p2.y); +} + +void pass(NSString *msg) { + PUTS(@"%@[%@PASS%@] %@", INDENT, GREEN, OFF, msg); + ++PASSES; +} + +void fail(NSString *msg) { + PUTS(@"%@[%@FAIL%@] %@", INDENT, RED, OFF, msg); + ++FAILS; +} + void TEST(NSString *msg, BOOL test) { if (test) { - PUTS(@"%@[%@PASS%@] %@", INDENT, GREEN, OFF, msg); - ++PASSES; + pass (msg); + } else { + fail (msg); + } +} + +void assertRectsEqual (NSString *msg, NSRect r1, NSRect r2) { + BOOL equal = fuzzyCompare (r1.origin.x, r2.origin.x) && + fuzzyCompare (r1.origin.y, r2.origin.y) && + fuzzyCompare (r1.size.width, r2.size.width) && + fuzzyCompare (r1.size.height, r2.size.height); + if (equal) { + pass (msg); + } else { + failFmt(@"%@ (expected (%f,%f:%fx%f) but got (%f,%f:%fx%f))", + msg, + r2.origin.x, r2.origin.y, r2.size.width, r2.size.height, + r1.origin.x, r1.origin.y, r1.size.width, r1.size.height); + } +} + +void assertPointsEqual (NSString *msg, NSPoint p1, NSPoint p2) { + BOOL equal = fuzzyCompare (p1.x, p2.x) && fuzzyCompare (p1.y, p2.y); + if (equal) { + pass (msg); } else { - PUTS(@"%@[%@FAIL%@] %@", INDENT, RED, OFF, msg); - ++FAILS; + failFmt(@"%@ (expected (%f,%f) but got (%f,%f)", + msg, + p2.x, p2.y, + p1.x, p1.y); + } +} + +void assertFloatsEqual (NSString *msg, float f1, float f2) { + if (fuzzyCompare (f1, f2)) { + pass (msg); + } else { + failFmt(@"%@ (expected %f but got %f", msg, f2, f1); } } @@ -102,3 +153,23 @@ void setColorEnabled(BOOL b) { OFF = @""; } } + +#ifdef STAND_ALONE +void runTests(); + +int main() { + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + + setColorEnabled (YES); + startTests(); + + runTests(); + + endTests(); + + [pool drain]; + return 0; +} +#endif + +// vim:ft=objc:ts=4:sts=4:sw=4:noet -- cgit v1.2.3