forked from core-plot/core-plot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCPTLayerTests.m
More file actions
163 lines (118 loc) · 4.55 KB
/
CPTLayerTests.m
File metadata and controls
163 lines (118 loc) · 4.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#import "CPTLayerTests.h"
#import "CPTLayer.h"
#import "CPTUtilities.h"
#import "NSNumberExtensions.h"
static const double precision = 1.0e-6;
@interface CPTLayerTests()
-(void)testPositionsWithScale:(CGFloat)scale anchorPoint:(CGPoint)anchor expected:(CPTNumberArray)expected;
@end
#pragma mark -
@implementation CPTLayerTests
@synthesize layer;
@synthesize positions;
#pragma mark -
#pragma mark Setup
-(void)setUp
{
// starting layer positions for each test
self.positions = @[@10.49999, @10.5, @10.50001, @10.99999, @11.0, @11.00001];
CPTLayer *newLayer = [[CPTLayer alloc] initWithFrame:CPTRectMake(0.0, 0.0, 99.0, 99.0)];
self.layer = newLayer;
}
-(void)tearDown
{
}
#pragma mark - Pixel alignment @1x
-(void)testPixelAlign1xLeft
{
CPTNumberArray expected = @[@10.0, @10.0, @11.0, @11.0, @11.0, @11.0];
[self testPositionsWithScale:CPTFloat(1.0)
anchorPoint:CGPointZero
expected:expected];
}
-(void)testPixelAlign1xLeftMiddle
{
CPTNumberArray expected = @[@10.75, @10.75, @10.75, @10.75, @10.75, @10.75];
[self testPositionsWithScale:CPTFloat(1.0)
anchorPoint:CPTPointMake(0.25, 0.25)
expected:expected];
}
-(void)testPixelAlign1xMiddle
{
CPTNumberArray expected = @[@10.5, @10.5, @10.5, @10.5, @10.5, @11.5];
[self testPositionsWithScale:CPTFloat(1.0)
anchorPoint:CPTPointMake(0.5, 0.5)
expected:expected];
}
-(void)testPixelAlign1xRightMiddle
{
CPTNumberArray expected = @[@10.25, @10.25, @10.25, @11.25, @11.25, @11.25];
[self testPositionsWithScale:CPTFloat(1.0)
anchorPoint:CPTPointMake(0.75, 0.75)
expected:expected];
}
-(void)testPixelAlign1xRight
{
CPTNumberArray expected = @[@10.0, @10.0, @11.0, @11.0, @11.0, @11.0];
[self testPositionsWithScale:CPTFloat(1.0)
anchorPoint:CPTPointMake(1.0, 1.0)
expected:expected];
}
#pragma mark - Pixel alignment @2x
-(void)testPixelAlign2xLeft
{
CPTNumberArray expected = @[@10.5, @10.5, @10.5, @11.0, @11.0, @11.0];
[self testPositionsWithScale:CPTFloat(2.0)
anchorPoint:CGPointZero
expected:expected];
}
-(void)testPixelAlign2xLeftMiddle
{
CPTNumberArray expected = @[@10.25, @10.25, @10.75, @10.75, @10.75, @11.25];
[self testPositionsWithScale:CPTFloat(2.0)
anchorPoint:CPTPointMake(0.25, 0.25)
expected:expected];
}
-(void)testPixelAlign2xMiddle
{
CPTNumberArray expected = @[@10.5, @10.5, @10.5, @11.0, @11.0, @11.0];
[self testPositionsWithScale:CPTFloat(2.0)
anchorPoint:CPTPointMake(0.5, 0.5)
expected:expected];
}
-(void)testPixelAlign2xRightMiddle
{
CPTNumberArray expected = @[@10.25, @10.25, @10.75, @10.75, @10.75, @11.25];
[self testPositionsWithScale:CPTFloat(2.0)
anchorPoint:CPTPointMake(0.75, 0.75)
expected:expected];
}
-(void)testPixelAlign2xRight
{
CPTNumberArray expected = @[@10.5, @10.5, @10.5, @11.0, @11.0, @11.0];
[self testPositionsWithScale:CPTFloat(2.0)
anchorPoint:CPTPointMake(1.0, 1.0)
expected:expected];
}
#pragma mark - Utility methods
-(void)testPositionsWithScale:(CGFloat)scale anchorPoint:(CGPoint)anchor expected:(CPTNumberArray)expectedValues
{
NSUInteger positionCount = self.positions.count;
NSParameterAssert(expectedValues.count == positionCount);
self.layer.contentsScale = scale;
self.layer.anchorPoint = anchor;
for ( NSUInteger i = 0; i < positionCount; i++ ) {
CGFloat position = ( (NSNumber *)( (self.positions)[i] ) ).cgFloatValue;
CGPoint layerPosition = CGPointMake(position, position);
self.layer.position = layerPosition;
[self.layer pixelAlign];
CGPoint alignedPoint = self.layer.position;
CGFloat expected = ( (NSNumber *)(expectedValues[i]) ).cgFloatValue;
NSString *errMessage;
errMessage = [NSString stringWithFormat:@"pixelAlign at x = %g with scale %g and anchor %@", position, scale, CPTStringFromPoint(anchor)];
XCTAssertEqualWithAccuracy(alignedPoint.x, expected, precision, @"%@", errMessage);
errMessage = [NSString stringWithFormat:@"pixelAlign at y = %g with scale %g and anchor %@", position, scale, CPTStringFromPoint(anchor)];
XCTAssertEqualWithAccuracy(alignedPoint.y, expected, precision, @"%@", errMessage);
}
}
@end