Skip to content

Commit 58306ed

Browse files
author
Mike Amaral
committed
Added unit tests for groupAndAlign() vertical cases, and also fixed issue related to prior commit, but this time the bug was with vertical cases.
1 parent 06b9a9d commit 58306ed

File tree

2 files changed

+65
-7
lines changed

2 files changed

+65
-7
lines changed

NeonUnitTests/NeonUnitTests.swift

+61
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,67 @@ class NeonTests: XCTestCase {
471471
XCTAssert(CGRectEqualToRect(testSiblingView.frame, CGRectMake(105, 0, 20, 20)))
472472
XCTAssert(CGRectEqualToRect(testSiblingView2.frame, CGRectMake(105, 25, 20, 20)))
473473
XCTAssert(CGRectEqualToRect(testSiblingView3.frame, CGRectMake(105, 50, 20, 20)))
474+
475+
testSuperview.groupAndAlign(group: .Vertical, andAlign: .ToTheRightCentered, views: [testSiblingView, testSiblingView2, testSiblingView3], relativeTo: testAnchorView, padding: 5, width: 20, height: 20)
476+
XCTAssert(CGRectEqualToRect(testSiblingView.frame, CGRectMake(105, 15, 20, 20)))
477+
XCTAssert(CGRectEqualToRect(testSiblingView2.frame, CGRectMake(105, 40, 20, 20)))
478+
XCTAssert(CGRectEqualToRect(testSiblingView3.frame, CGRectMake(105, 65, 20, 20)))
479+
480+
testSuperview.groupAndAlign(group: .Vertical, andAlign: .ToTheRightMatchingBottom, views: [testSiblingView, testSiblingView2, testSiblingView3], relativeTo: testAnchorView, padding: 5, width: 20, height: 20)
481+
XCTAssert(CGRectEqualToRect(testSiblingView.frame, CGRectMake(105, 30, 20, 20)))
482+
XCTAssert(CGRectEqualToRect(testSiblingView2.frame, CGRectMake(105, 55, 20, 20)))
483+
XCTAssert(CGRectEqualToRect(testSiblingView3.frame, CGRectMake(105, 80, 20, 20)))
484+
485+
testAnchorView.anchorInCorner(.TopRight, xPad: 0, yPad: 0, width: 100, height: 100)
486+
487+
testSuperview.groupAndAlign(group: .Vertical, andAlign: .ToTheLeftMatchingTop, views: [testSiblingView, testSiblingView2, testSiblingView3], relativeTo: testAnchorView, padding: 5, width: 20, height: 20)
488+
XCTAssert(CGRectEqualToRect(testSiblingView.frame, CGRectMake(875, 0, 20, 20)))
489+
XCTAssert(CGRectEqualToRect(testSiblingView2.frame, CGRectMake(875, 25, 20, 20)))
490+
XCTAssert(CGRectEqualToRect(testSiblingView3.frame, CGRectMake(875, 50, 20, 20)))
491+
492+
testSuperview.groupAndAlign(group: .Vertical, andAlign: .ToTheLeftCentered, views: [testSiblingView, testSiblingView2, testSiblingView3], relativeTo: testAnchorView, padding: 5, width: 20, height: 20)
493+
XCTAssert(CGRectEqualToRect(testSiblingView.frame, CGRectMake(875, 15, 20, 20)))
494+
XCTAssert(CGRectEqualToRect(testSiblingView2.frame, CGRectMake(875, 40, 20, 20)))
495+
XCTAssert(CGRectEqualToRect(testSiblingView3.frame, CGRectMake(875, 65, 20, 20)))
496+
497+
testSuperview.groupAndAlign(group: .Vertical, andAlign: .ToTheLeftMatchingBottom, views: [testSiblingView, testSiblingView2, testSiblingView3], relativeTo: testAnchorView, padding: 5, width: 20, height: 20)
498+
XCTAssert(CGRectEqualToRect(testSiblingView.frame, CGRectMake(875, 30, 20, 20)))
499+
XCTAssert(CGRectEqualToRect(testSiblingView2.frame, CGRectMake(875, 55, 20, 20)))
500+
XCTAssert(CGRectEqualToRect(testSiblingView3.frame, CGRectMake(875, 80, 20, 20)))
501+
502+
testAnchorView.anchorInCorner(.TopLeft, xPad: 0, yPad: 0, width: 100, height: 100)
503+
504+
testSuperview.groupAndAlign(group: .Vertical, andAlign: .UnderMatchingLeft, views: [testSiblingView, testSiblingView2, testSiblingView3], relativeTo: testAnchorView, padding: 5, width: 20, height: 20)
505+
XCTAssert(CGRectEqualToRect(testSiblingView.frame, CGRectMake(0, 105, 20, 20)))
506+
XCTAssert(CGRectEqualToRect(testSiblingView2.frame, CGRectMake(0, 130, 20, 20)))
507+
XCTAssert(CGRectEqualToRect(testSiblingView3.frame, CGRectMake(0, 155, 20, 20)))
508+
509+
testSuperview.groupAndAlign(group: .Vertical, andAlign: .UnderCentered, views: [testSiblingView, testSiblingView2, testSiblingView3], relativeTo: testAnchorView, padding: 5, width: 20, height: 20)
510+
XCTAssert(CGRectEqualToRect(testSiblingView.frame, CGRectMake(40, 105, 20, 20)))
511+
XCTAssert(CGRectEqualToRect(testSiblingView2.frame, CGRectMake(40, 130, 20, 20)))
512+
XCTAssert(CGRectEqualToRect(testSiblingView3.frame, CGRectMake(40, 155, 20, 20)))
513+
514+
testSuperview.groupAndAlign(group: .Vertical, andAlign: .UnderMatchingRight, views: [testSiblingView, testSiblingView2, testSiblingView3], relativeTo: testAnchorView, padding: 5, width: 20, height: 20)
515+
XCTAssert(CGRectEqualToRect(testSiblingView.frame, CGRectMake(80, 105, 20, 20)))
516+
XCTAssert(CGRectEqualToRect(testSiblingView2.frame, CGRectMake(80, 130, 20, 20)))
517+
XCTAssert(CGRectEqualToRect(testSiblingView3.frame, CGRectMake(80, 155, 20, 20)))
518+
519+
testAnchorView.anchorInCorner(.BottomLeft, xPad: 0, yPad: 0, width: 100, height: 100)
520+
521+
testSuperview.groupAndAlign(group: .Vertical, andAlign: .AboveMatchingLeft, views: [testSiblingView, testSiblingView2, testSiblingView3], relativeTo: testAnchorView, padding: 5, width: 20, height: 20)
522+
XCTAssert(CGRectEqualToRect(testSiblingView.frame, CGRectMake(0, 825, 20, 20)))
523+
XCTAssert(CGRectEqualToRect(testSiblingView2.frame, CGRectMake(0, 850, 20, 20)))
524+
XCTAssert(CGRectEqualToRect(testSiblingView3.frame, CGRectMake(0, 875, 20, 20)))
525+
526+
testSuperview.groupAndAlign(group: .Vertical, andAlign: .AboveCentered, views: [testSiblingView, testSiblingView2, testSiblingView3], relativeTo: testAnchorView, padding: 5, width: 20, height: 20)
527+
XCTAssert(CGRectEqualToRect(testSiblingView.frame, CGRectMake(40, 825, 20, 20)))
528+
XCTAssert(CGRectEqualToRect(testSiblingView2.frame, CGRectMake(40, 850, 20, 20)))
529+
XCTAssert(CGRectEqualToRect(testSiblingView3.frame, CGRectMake(40, 875, 20, 20)))
530+
531+
testSuperview.groupAndAlign(group: .Vertical, andAlign: .AboveMatchingRight, views: [testSiblingView, testSiblingView2, testSiblingView3], relativeTo: testAnchorView, padding: 5, width: 20, height: 20)
532+
XCTAssert(CGRectEqualToRect(testSiblingView.frame, CGRectMake(80, 825, 20, 20)))
533+
XCTAssert(CGRectEqualToRect(testSiblingView2.frame, CGRectMake(80, 850, 20, 20)))
534+
XCTAssert(CGRectEqualToRect(testSiblingView3.frame, CGRectMake(80, 875, 20, 20)))
474535
}
475536

476537
// TODO: test groupAndFill()

Source/NeonGroupable.swift

+4-7
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ public extension Groupable {
400400

401401
var xOrigin : CGFloat = 0.0
402402
var yOrigin : CGFloat = 0.0
403-
var yAdjust : CGFloat = height + padding
403+
let yAdjust : CGFloat = height + padding
404404

405405
switch align {
406406
case .ToTheRightMatchingTop:
@@ -441,18 +441,15 @@ public extension Groupable {
441441

442442
case .AboveMatchingLeft:
443443
xOrigin = sibling.x
444-
yOrigin = sibling.y - height - padding
445-
yAdjust = -yAdjust
444+
yOrigin = sibling.y - (CGFloat(views.count) * height) - (CGFloat(views.count) * padding)
446445

447446
case .AboveMatchingRight:
448447
xOrigin = sibling.xMax - width
449-
yOrigin = sibling.y - height - padding
450-
yAdjust = -yAdjust
448+
yOrigin = sibling.y - (CGFloat(views.count) * height) - (CGFloat(views.count) * padding)
451449

452450
case .AboveCentered:
453451
xOrigin = sibling.xMid - (width / 2.0)
454-
yOrigin = sibling.y - height - padding
455-
yAdjust = -yAdjust
452+
yOrigin = sibling.y - (CGFloat(views.count) * height) - (CGFloat(views.count) * padding)
456453
}
457454

458455
for view in views {

0 commit comments

Comments
 (0)