Skip to content

Commit 8d98f19

Browse files
author
Baris Sencan
committed
Test fast access properties
1 parent b1e1643 commit 8d98f19

File tree

2 files changed

+163
-30
lines changed

2 files changed

+163
-30
lines changed

ManualLayoutTests/FastAccessTests.swift

Lines changed: 157 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,85 +12,218 @@ import ManualLayout
1212

1313
class FastAccessTests: XCTestCase {
1414
let view = UIView(frame: CGRectZero)
15+
let defaultFrame = CGRect(x: 1, y: 3, width: 6, height: 8)
1516

1617
override func setUp() {
17-
view.frame = CGRectZero
18+
view.frame = defaultFrame
1819
}
1920

2021
func testOrigin() {
21-
let origin = CGPoint(x: 10, y: 10)
22-
view.origin = origin
23-
XCTAssertEqual(view.frame.origin, origin, "origin changes should modify frame origin")
24-
XCTAssertEqual(view.frame.size, CGSizeZero, "origin changes should not modify frame size")
22+
let newOrigin = CGPoint(x: 10, y: 10)
23+
view.origin = newOrigin
24+
XCTAssertEqual(
25+
view.frame.origin,
26+
newOrigin,
27+
"origin changes should modify frame origin")
28+
XCTAssertEqual(
29+
view.frame.size,
30+
defaultFrame.size,
31+
"origin changes should not modify frame size")
2532
}
2633

2734
func testX() {
2835
view.x = 10
29-
XCTAssertEqual(view.frame.origin, CGPoint(x: 10, y: 0), "x changes should just modify frame x")
30-
XCTAssertEqual(view.frame.size, CGSizeZero, "x changes should not modify frame size")
36+
XCTAssertEqual(
37+
view.frame.origin,
38+
CGPoint(x: 10, y: defaultFrame.origin.y),
39+
"x changes should just modify frame x")
40+
XCTAssertEqual(
41+
view.frame.size,
42+
defaultFrame.size,
43+
"x changes should not modify frame size")
3144
}
3245

3346
func testY() {
3447
view.y = 10
35-
XCTAssertEqual(view.frame.origin, CGPoint(x: 0, y: 10), "y changes should just modify frame y")
36-
XCTAssertEqual(view.frame.size, CGSizeZero, "y changes should not modify frame size")
48+
XCTAssertEqual(
49+
view.frame.origin,
50+
CGPoint(x: defaultFrame.origin.x, y: 10),
51+
"y changes should just modify frame y")
52+
XCTAssertEqual(
53+
view.frame.size,
54+
defaultFrame.size,
55+
"y changes should not modify frame size")
3756
}
3857

3958
func testCenter() {
40-
59+
view.layer.center = CGPoint(x: 10, y: 10)
60+
XCTAssertEqual(
61+
view.frame.origin,
62+
CGPoint(x: 7, y: 6),
63+
"center changes should center frame")
64+
XCTAssertEqual(
65+
view.frame.size,
66+
defaultFrame.size,
67+
"center changes should not modify frame size")
4168
}
4269

4370
func testCenterX() {
44-
71+
view.centerX = 10
72+
XCTAssertEqual(
73+
view.frame.origin,
74+
CGPoint(x: 7, y: defaultFrame.origin.y),
75+
"centerX changes should center frame")
76+
XCTAssertEqual(
77+
view.frame.size,
78+
defaultFrame.size,
79+
"centerX changes should not modify frame size")
4580
}
4681

4782
func testCenterY() {
48-
83+
view.centerY = 10
84+
XCTAssertEqual(
85+
view.frame.origin,
86+
CGPoint(x: defaultFrame.origin.x, y: 6),
87+
"centerY changes should center frame")
88+
XCTAssertEqual(
89+
view.frame.size,
90+
defaultFrame.size,
91+
"centerY changes should not modify frame size")
4992
}
5093

5194
func testSize() {
52-
95+
view.size = CGSizeZero
96+
XCTAssertEqual(
97+
view.frame.origin,
98+
defaultFrame.origin,
99+
"size changes should not modify frame origin")
100+
XCTAssertEqual(
101+
view.frame.size,
102+
CGSizeZero,
103+
"size changes should modify frame size")
53104
}
54105

55106
func testWidth() {
56-
107+
view.width = 10
108+
XCTAssertEqual(
109+
view.frame.origin,
110+
defaultFrame.origin,
111+
"width changes should not modify frame origin")
112+
XCTAssertEqual(
113+
view.frame.size,
114+
CGSize(width: 10, height: defaultFrame.size.height),
115+
"width changes should just modify frame width")
57116
}
58117

59118
func testHeight() {
60-
119+
view.height = 10
120+
XCTAssertEqual(
121+
view.frame.origin,
122+
defaultFrame.origin,
123+
"height changes should not modify frame origin")
124+
XCTAssertEqual(
125+
view.frame.size,
126+
CGSize(width: defaultFrame.size.width, height: 10),
127+
"height changes should just modify frame height")
61128
}
62129

63130
func testTop() {
64131
view.top = 10
65-
XCTAssertEqual(view.frame.origin, CGPoint(x: 0, y: 10), "top changes should just modify frame y")
66-
XCTAssertEqual(view.frame.size, CGSizeZero, "top changes should not modify frame size")
132+
XCTAssertEqual(
133+
view.frame.origin,
134+
CGPoint(x: defaultFrame.origin.x, y: 10),
135+
"top changes should just modify frame y")
136+
XCTAssertEqual(
137+
view.frame.size,
138+
defaultFrame.size,
139+
"top changes should not modify frame size")
67140
}
68141

69142
func testRight() {
70-
143+
view.right = 10
144+
XCTAssertEqual(
145+
view.frame.origin,
146+
CGPoint(x: 10 - defaultFrame.size.width, y: defaultFrame.origin.y),
147+
"right changes should just modify frame x")
148+
XCTAssertEqual(
149+
view.frame.size,
150+
defaultFrame.size,
151+
"right changes should not modify frame size")
71152
}
72153

73154
func testBottom() {
74-
155+
view.bottom = 10
156+
XCTAssertEqual(
157+
view.frame.origin,
158+
CGPoint(x: defaultFrame.origin.x, y: 10 - defaultFrame.size.height),
159+
"bottom changes should just modify frame y")
160+
XCTAssertEqual(
161+
view.frame.size,
162+
defaultFrame.size,
163+
"bottom changes should not modify frame size")
75164
}
76165

77166
func testLeft() {
78-
167+
view.left = 10
168+
XCTAssertEqual(
169+
view.frame.origin,
170+
CGPoint(x: 10, y: defaultFrame.origin.y),
171+
"left changes should just modify frame x")
172+
XCTAssertEqual(
173+
view.frame.size,
174+
defaultFrame.size,
175+
"left changes should not modify frame size")
79176
}
80177

81178
func testTop2() {
82-
179+
view.top2 = 5
180+
XCTAssertEqual(
181+
view.frame.origin,
182+
CGPoint(x: defaultFrame.origin.x, y: 5),
183+
"top2 changes without a swap should just modify frame y")
184+
XCTAssertEqual(
185+
view.frame.size,
186+
CGSize(width: defaultFrame.size.width, height: 6),
187+
"top2 changes without a swap should modify frame size")
188+
// TODO: Test swap behavior.
83189
}
84190

85191
func testRight2() {
86-
192+
view.right2 = 5
193+
XCTAssertEqual(
194+
view.frame.origin,
195+
defaultFrame.origin,
196+
"right2 changes without a swap should not modify frame origin")
197+
XCTAssertEqual(
198+
view.frame.size,
199+
CGSize(width: 4, height: defaultFrame.size.height),
200+
"right2 changes without a swap should modify frame size")
201+
// TODO: Test swap behavior.
87202
}
88203

89204
func testBottom2() {
90-
205+
view.bottom2 = 5
206+
XCTAssertEqual(
207+
view.frame.origin,
208+
defaultFrame.origin,
209+
"bottom2 changes without a swap should not modify frame origin")
210+
XCTAssertEqual(
211+
view.frame.size,
212+
CGSize(width: defaultFrame.size.width, height: 2),
213+
"bottom2 changes without a swap should modify frame size")
214+
// TODO: Test swap behavior.
91215
}
92216

93217
func testLeft2() {
94-
218+
view.left2 = 5
219+
XCTAssertEqual(
220+
view.frame.origin,
221+
CGPoint(x: 5, y: defaultFrame.origin.y),
222+
"left2 changes without a swap should just modify frame x")
223+
XCTAssertEqual(
224+
view.frame.size,
225+
CGSize(width: 2, height: defaultFrame.size.height),
226+
"left2 changes without a swap should modify frame size")
227+
// TODO: Test swap behavior.
95228
}
96229
}

ManualLayoutTests/ManualLayoutTests.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ internal class ManualLayoutTests: XCTestCase {
1515
let rect = CGRect(x: 0, y: 0, width: 10, height: 10)
1616

1717
func testGetOriginForCenteringRect() {
18-
let origin = ManualLayout.getOriginForCenteringRect(rect, inRect: otherRect)
19-
XCTAssertEqual(origin, CGPoint(x: 55, y: 65), "origin should be at (55, 65)")
18+
let o = ManualLayout.getOriginForCenteringRect(rect, inRect: otherRect)
19+
XCTAssertEqual(o, CGPoint(x: 55, y: 65), "o should equal center point")
2020
}
2121

2222
func testGetPositionForCenteringRect() {
23-
let positionX = ManualLayout.getPositionForCenteringRect(rect, dimension: .X, inRect: otherRect)
24-
XCTAssert(positionX == 55, "x position should be 55")
25-
let positionY = ManualLayout.getPositionForCenteringRect(rect, dimension: .Y, inRect: otherRect)
26-
XCTAssert(positionY == 65, "y position should be 65")
23+
let x = ManualLayout.getPositionForCenteringRect(rect, dimension: .X, inRect: otherRect)
24+
XCTAssert(x == 55, "x should be in center")
25+
let y = ManualLayout.getPositionForCenteringRect(rect, dimension: .Y, inRect: otherRect)
26+
XCTAssert(y == 65, "y should be in center")
2727
}
2828
}

0 commit comments

Comments
 (0)