aboutsummaryrefslogtreecommitdiff
path: root/Foundation/GTMGeometryUtilsTest.m
diff options
context:
space:
mode:
authorGravatar dmaclach <dmaclach@google.com>2016-10-07 12:10:23 -0400
committerGravatar Thomas Van Lenten <thomasvl@google.com>2016-10-07 12:21:06 -0400
commit42124b3691197c3c4f52f069775fa0390a8ff942 (patch)
treeebd373d398ea64b45bdc1d196fa0a2c5f57cabfd /Foundation/GTMGeometryUtilsTest.m
parent57eeab4193210df8ab0c81e9d3f1ee1ad3e24492 (diff)
First cut at pruning things/updating things.
Remove a bunch of code that Google stopped using/maintaining rather than trying to update it it. Some would be hard to update, some actually has system provided replacements; others are patterns that just don't seem as common now. Prune out the code related to macOS <= 10.5, start pruning some of the really old iOS support also. Get the projects mostly limping again with modern Xcodes so tests can be run. If someone ends up on this commit via history for something they still find as useful, feel free to do a pull request to bring the snippet of code back to life and update it for current SDKs.
Diffstat (limited to 'Foundation/GTMGeometryUtilsTest.m')
-rw-r--r--Foundation/GTMGeometryUtilsTest.m162
1 files changed, 81 insertions, 81 deletions
diff --git a/Foundation/GTMGeometryUtilsTest.m b/Foundation/GTMGeometryUtilsTest.m
index f765526..f4cf731 100644
--- a/Foundation/GTMGeometryUtilsTest.m
+++ b/Foundation/GTMGeometryUtilsTest.m
@@ -6,9 +6,9 @@
// 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
@@ -28,49 +28,49 @@
- (void)testGTMNSRectToCGRect {
NSRect nsRect = NSMakeRect(4.6,3.2,22.1,45.0);
CGRect cgRect = GTMNSRectToCGRect(nsRect);
- STAssertTrue(CGRectEqualToRect(cgRect, *(CGRect*)&nsRect), nil);
+ XCTAssertTrue(CGRectEqualToRect(cgRect, *(CGRect*)&nsRect));
}
- (void)testGTMNSSizeToCGSize {
NSSize nsSize = {22,15};
CGSize cgSize = GTMNSSizeToCGSize(nsSize);
- STAssertTrue(CGSizeEqualToSize(cgSize, *(CGSize*)&nsSize), nil);
+ XCTAssertTrue(CGSizeEqualToSize(cgSize, *(CGSize*)&nsSize));
}
- (void)testGTMNSPointsOnRect {
NSRect rect = NSMakeRect(0, 0, 2, 2);
-
+
NSPoint point = GTMNSMidMinX(rect);
- STAssertEqualsWithAccuracy(point.y, (CGFloat)1.0, (CGFloat)0.01, nil);
- STAssertEqualsWithAccuracy(point.x, (CGFloat)0.0, (CGFloat)0.01, nil);
-
+ XCTAssertEqualWithAccuracy(point.y, 1.0, 0.01);
+ XCTAssertEqualWithAccuracy(point.x, 0.0, 0.01);
+
point = GTMNSMidMaxX(rect);
- STAssertEqualsWithAccuracy(point.y, (CGFloat)1.0, (CGFloat)0.01, nil);
- STAssertEqualsWithAccuracy(point.x, (CGFloat)2.0, (CGFloat)0.01, nil);
-
+ XCTAssertEqualWithAccuracy(point.y, 1.0, 0.01);
+ XCTAssertEqualWithAccuracy(point.x, 2.0, 0.01);
+
point = GTMNSMidMaxY(rect);
- STAssertEqualsWithAccuracy(point.y, (CGFloat)2.0, (CGFloat)0.01, nil);
- STAssertEqualsWithAccuracy(point.x, (CGFloat)1.0, (CGFloat)0.01, nil);
-
+ XCTAssertEqualWithAccuracy(point.y, 2.0, 0.01);
+ XCTAssertEqualWithAccuracy(point.x, 1.0, 0.01);
+
point = GTMNSMidMinY(rect);
- STAssertEqualsWithAccuracy(point.y, (CGFloat)0.0, (CGFloat)0.01, nil);
- STAssertEqualsWithAccuracy(point.x, (CGFloat)1.0, (CGFloat)0.01, nil);
+ XCTAssertEqualWithAccuracy(point.y, 0.0, 0.01);
+ XCTAssertEqualWithAccuracy(point.x, 1.0, 0.01);
point = GTMNSCenter(rect);
- STAssertEqualsWithAccuracy(point.y, (CGFloat)1.0, (CGFloat)0.01, nil);
- STAssertEqualsWithAccuracy(point.x, (CGFloat)1.0, (CGFloat)0.01, nil);
+ XCTAssertEqualWithAccuracy(point.y, 1.0, 0.01);
+ XCTAssertEqualWithAccuracy(point.x, 1.0, 0.01);
}
- (void)testGTMNSRectSize {
NSSize nsSize = GTMNSRectSize(NSMakeRect(1, 1, 10, 5));
- STAssertEqualsWithAccuracy(nsSize.width, (CGFloat)10.0, (CGFloat)0.01, nil);
- STAssertEqualsWithAccuracy(nsSize.height, (CGFloat)5.0, (CGFloat)0.01, nil);
+ XCTAssertEqualWithAccuracy(nsSize.width, 10.0, 0.01);
+ XCTAssertEqualWithAccuracy(nsSize.height, 5.0, 0.01);
}
- (void)testGTMNSRectOfSize {
NSRect outRect = GTMNSRectOfSize(NSMakeSize(10, 5));
NSRect expectedRect = NSMakeRect(0, 0, 10, 5);
- STAssertEquals(outRect, expectedRect, nil);
+ XCTAssertTrue(NSEqualRects(outRect, expectedRect));
}
- (void)testGTMNSAlignRectangles {
@@ -78,7 +78,7 @@
NSPoint expectedOrigin;
GTMRectAlignment alignment;
} TestData;
-
+
TestData data[] = {
{ {1,2}, GTMRectAlignTop },
{ {0,2}, GTMRectAlignTopLeft },
@@ -90,17 +90,17 @@
{ {2,1}, GTMRectAlignRight },
{ {1,1}, GTMRectAlignCenter },
};
-
+
NSRect rect1 = NSMakeRect(0, 0, 4, 4);
NSRect rect2 = NSMakeRect(0, 0, 2, 2);
-
+
NSRect expectedRect;
expectedRect.size = NSMakeSize(2, 2);
-
+
for (size_t i = 0; i < sizeof(data) / sizeof(TestData); i++) {
expectedRect.origin = data[i].expectedOrigin;
NSRect outRect = GTMNSAlignRectangles(rect2, rect1, data[i].alignment);
- STAssertEquals(outRect, expectedRect, nil);
+ XCTAssertTrue(NSEqualRects(outRect, expectedRect));
}
}
@@ -120,24 +120,25 @@
{ { 2.0, 2.0 }, { 2.0, 2.0 } },
{ { 0.0, 10.0 }, { 0.0, 0.0 } }
};
-
+
for (size_t i = 0; i < sizeof(tests) / sizeof(Test); ++i) {
NSRect result = GTMNSScaleRectangleToSize(rect, tests[i].size_,
GTMScaleProportionally);
- STAssertEquals(result, GTMNSRectOfSize(tests[i].newSize_), @"failed on test %zd", i);
+ XCTAssertTrue(NSEqualRects(result, GTMNSRectOfSize(tests[i].newSize_)),
+ @"failed on test %zd", i);
}
-
+
NSRect result = GTMNSScaleRectangleToSize(NSZeroRect, tests[0].size_,
GTMScaleProportionally);
- STAssertEquals(result, NSZeroRect, nil);
-
+ XCTAssertTrue(NSEqualRects(result, NSZeroRect));
+
result = GTMNSScaleRectangleToSize(rect, tests[0].size_,
GTMScaleToFit);
- STAssertEquals(result, GTMNSRectOfSize(tests[0].size_), nil);
-
+ XCTAssertTrue(NSEqualRects(result, GTMNSRectOfSize(tests[0].size_)));
+
result = GTMNSScaleRectangleToSize(rect, tests[0].size_,
GTMScaleNone);
- STAssertEquals(result, rect, nil);
+ XCTAssertTrue(NSEqualRects(result, rect));
}
@@ -147,20 +148,20 @@
GTMScaling scaling;
GTMRectAlignment alignment;
} TestData;
-
+
NSRect rect1 = NSMakeRect(0, 0, 4, 4);
NSRect rect2 = NSMakeRect(0, 0, 2, 1);
-
+
TestData data[] = {
{ NSMakeRect(2, 3, 2, 1), GTMScaleToFillProportionally, GTMRectAlignTopRight },
{ NSMakeRect(0, 0, 4, 4), GTMScaleToFit, GTMRectAlignCenter },
{ NSMakeRect(1, 1.5, 2, 1), GTMScaleNone, GTMRectAlignCenter },
{ NSMakeRect(1, 0, 2, 1), GTMScaleProportionally, GTMRectAlignBottom },
};
-
+
for (size_t i = 0; i < sizeof(data) / sizeof(TestData); i++) {
NSRect outRect = GTMNSScaleRectToRect(rect2, rect1, data[i].scaling, data[i].alignment);
- STAssertEquals(outRect, data[i].expectedRect, nil);
+ XCTAssertTrue(NSEqualRects(outRect, data[i].expectedRect));
}
}
@@ -168,18 +169,17 @@
- (void)testGTMNSDistanceBetweenPoints {
NSPoint pt1 = NSMakePoint(0, 0);
NSPoint pt2 = NSMakePoint(3, 4);
- STAssertEquals(GTMNSDistanceBetweenPoints(pt1, pt2), (CGFloat)5.0, nil);
- STAssertEquals(GTMNSDistanceBetweenPoints(pt2, pt1), (CGFloat)5.0, nil);
+ XCTAssertEqualWithAccuracy(GTMNSDistanceBetweenPoints(pt1, pt2), 5.0, 0.01);
+ XCTAssertEqualWithAccuracy(GTMNSDistanceBetweenPoints(pt2, pt1), 5.0, 0.01);
pt1 = NSMakePoint(1, 1);
pt2 = NSMakePoint(1, 1);
- STAssertEquals(GTMNSDistanceBetweenPoints(pt1, pt2), (CGFloat)0.0, nil);
+ XCTAssertEqualWithAccuracy(GTMNSDistanceBetweenPoints(pt1, pt2), 0.0, 0.01);
}
- (void)testGTMNSRectScaling {
NSRect rect = NSMakeRect(1.0f, 2.0f, 5.0f, 10.0f);
- NSRect rect2 = NSMakeRect((CGFloat)1.0, (CGFloat)2.0, (CGFloat)1.0, (CGFloat)12.0);
- STAssertEquals(GTMNSRectScale(rect, (CGFloat)0.2, (CGFloat)1.2),
- rect2, nil);
+ NSRect rect2 = NSMakeRect(1.0, 2.0, 1.0, 12.0);
+ XCTAssertTrue(NSEqualRects(GTMNSRectScale(rect, 0.2, 1.2), rect2));
}
#endif // !GTM_IPHONE_SDK
@@ -187,11 +187,11 @@
- (void)testGTMCGDistanceBetweenPoints {
CGPoint pt1 = CGPointMake(0, 0);
CGPoint pt2 = CGPointMake(3, 4);
- STAssertEquals(GTMCGDistanceBetweenPoints(pt1, pt2), (CGFloat)5.0, nil);
- STAssertEquals(GTMCGDistanceBetweenPoints(pt2, pt1), (CGFloat)5.0, nil);
+ XCTAssertEqualWithAccuracy(GTMCGDistanceBetweenPoints(pt1, pt2), 5.0, 0.01);
+ XCTAssertEqualWithAccuracy(GTMCGDistanceBetweenPoints(pt2, pt1), 5.0, 0.01);
pt1 = CGPointMake(1, 1);
pt2 = CGPointMake(1, 1);
- STAssertEquals(GTMCGDistanceBetweenPoints(pt1, pt2), (CGFloat)0.0, nil);
+ XCTAssertEqualWithAccuracy(GTMCGDistanceBetweenPoints(pt1, pt2), 0.0, 0.01);
}
- (void)testGTMCGAlignRectangles {
@@ -199,7 +199,7 @@
CGPoint expectedOrigin;
GTMRectAlignment alignment;
} TestData;
-
+
TestData data[] = {
{ {1,2}, GTMRectAlignTop },
{ {0,2}, GTMRectAlignTopLeft },
@@ -211,61 +211,60 @@
{ {2,1}, GTMRectAlignRight },
{ {1,1}, GTMRectAlignCenter },
};
-
+
CGRect rect1 = CGRectMake(0, 0, 4, 4);
CGRect rect2 = CGRectMake(0, 0, 2, 2);
-
+
CGRect expectedRect;
expectedRect.size = CGSizeMake(2, 2);
-
+
for (size_t i = 0; i < sizeof(data) / sizeof(TestData); i++) {
expectedRect.origin = data[i].expectedOrigin;
CGRect outRect = GTMCGAlignRectangles(rect2, rect1, data[i].alignment);
- STAssertEquals(outRect, expectedRect, nil);
+ XCTAssertTrue(CGRectEqualToRect(outRect, expectedRect));
}
}
- (void)testGTMCGPointsOnRect {
CGRect rect = CGRectMake(0, 0, 2, 2);
-
+
CGPoint point = GTMCGMidMinX(rect);
- STAssertEqualsWithAccuracy(point.y, (CGFloat)1.0, (CGFloat)0.01, nil);
- STAssertEqualsWithAccuracy(point.x, (CGFloat)0.0, (CGFloat)0.01, nil);
-
+ XCTAssertEqualWithAccuracy(point.y, 1.0, 0.01);
+ XCTAssertEqualWithAccuracy(point.x, 0.0, 0.01);
+
point = GTMCGMidMaxX(rect);
- STAssertEqualsWithAccuracy(point.y, (CGFloat)1.0, (CGFloat)0.01, nil);
- STAssertEqualsWithAccuracy(point.x, (CGFloat)2.0, (CGFloat)0.01, nil);
-
+ XCTAssertEqualWithAccuracy(point.y, 1.0, 0.01);
+ XCTAssertEqualWithAccuracy(point.x, 2.0, 0.01);
+
point = GTMCGMidMaxY(rect);
- STAssertEqualsWithAccuracy(point.y, (CGFloat)2.0, (CGFloat)0.01, nil);
- STAssertEqualsWithAccuracy(point.x, (CGFloat)1.0, (CGFloat)0.01, nil);
-
+ XCTAssertEqualWithAccuracy(point.y, 2.0, 0.01);
+ XCTAssertEqualWithAccuracy(point.x, 1.0, 0.01);
+
point = GTMCGMidMinY(rect);
- STAssertEqualsWithAccuracy(point.y, (CGFloat)0.0, (CGFloat)0.01, nil);
- STAssertEqualsWithAccuracy(point.x, (CGFloat)1.0, (CGFloat)0.01, nil);
-
+ XCTAssertEqualWithAccuracy(point.y, 0.0, 0.01);
+ XCTAssertEqualWithAccuracy(point.x, 1.0, 0.01);
+
point = GTMCGCenter(rect);
- STAssertEqualsWithAccuracy(point.y, (CGFloat)1.0, (CGFloat)0.01, nil);
- STAssertEqualsWithAccuracy(point.x, (CGFloat)1.0, (CGFloat)0.01, nil);
+ XCTAssertEqualWithAccuracy(point.y, 1.0, 0.01);
+ XCTAssertEqualWithAccuracy(point.x, 1.0, 0.01);
}
- (void)testGTMCGRectSize {
CGSize cgSize = GTMCGRectSize(CGRectMake(1, 1, 10, 5));
- STAssertEqualsWithAccuracy(cgSize.width, (CGFloat)10.0, (CGFloat)0.01, nil);
- STAssertEqualsWithAccuracy(cgSize.height, (CGFloat)5.0, (CGFloat)0.01, nil);
+ XCTAssertEqualWithAccuracy(cgSize.width, 10.0, 0.01);
+ XCTAssertEqualWithAccuracy(cgSize.height, 5.0, 0.01);
}
- (void)testGTMCGRectOfSize {
CGRect outRect = GTMCGRectOfSize(CGSizeMake(10, 5));
CGRect expectedRect = CGRectMake(0, 0, 10, 5);
- STAssertEquals(outRect, expectedRect, nil);
+ XCTAssertTrue(CGRectEqualToRect(outRect, expectedRect));
}
- (void)testGTMCGRectScaling {
CGRect rect = CGRectMake(1.0f, 2.0f, 5.0f, 10.0f);
- CGRect rect2 = CGRectMake((CGFloat)1.0, (CGFloat)2.0, (CGFloat)1.0, (CGFloat)12.0);
- STAssertEquals(GTMCGRectScale(rect, (CGFloat)0.2, (CGFloat)1.2),
- rect2, nil);
+ CGRect rect2 = CGRectMake(1.0, 2.0, 1.0, 12.0);
+ XCTAssertTrue(CGRectEqualToRect(GTMCGRectScale(rect, 0.2, 1.2), rect2));
}
- (void)testGTMCGScaleRectangleToSize {
@@ -284,24 +283,25 @@
{ { 2.0, 2.0 }, { 2.0, 2.0 } },
{ { 0.0, 10.0 }, { 0.0, 0.0 } }
};
-
+
for (size_t i = 0; i < sizeof(tests) / sizeof(Test); ++i) {
CGRect result = GTMCGScaleRectangleToSize(rect, tests[i].size_,
GTMScaleProportionally);
- STAssertEquals(result, GTMCGRectOfSize(tests[i].newSize_), @"failed on test %zd", i);
+ XCTAssertTrue(CGRectEqualToRect(result, GTMCGRectOfSize(tests[i].newSize_)),
+ @"failed on test %zd", i);
}
-
+
CGRect result = GTMCGScaleRectangleToSize(CGRectZero, tests[0].size_,
GTMScaleProportionally);
- STAssertEquals(result, CGRectZero, nil);
-
+ XCTAssertTrue(CGRectEqualToRect(result, CGRectZero));
+
result = GTMCGScaleRectangleToSize(rect, tests[0].size_,
GTMScaleToFit);
- STAssertEquals(result, GTMCGRectOfSize(tests[0].size_), nil);
-
+ XCTAssertTrue(CGRectEqualToRect(result, GTMCGRectOfSize(tests[0].size_)));
+
result = GTMCGScaleRectangleToSize(rect, tests[0].size_,
GTMScaleNone);
- STAssertEquals(result, rect, nil);
+ XCTAssertTrue(CGRectEqualToRect(result, rect));
}
@end