From b0135a816b271765ab6ef23691eccfc0fe48a07b Mon Sep 17 00:00:00 2001 From: CosynPa Date: Sun, 8 Nov 2015 17:19:54 +0800 Subject: [PATCH] Refactor test, replace 70 test functions with just one --- TZStackViewTests/TZStackViewTestCase.swift | 27 +- TZStackViewTests/TZStackViewTests.swift | 1036 ++------------------ 2 files changed, 77 insertions(+), 986 deletions(-) diff --git a/TZStackViewTests/TZStackViewTestCase.swift b/TZStackViewTests/TZStackViewTestCase.swift index e0a4c02..8fcf3f0 100644 --- a/TZStackViewTests/TZStackViewTestCase.swift +++ b/TZStackViewTests/TZStackViewTestCase.swift @@ -26,23 +26,36 @@ class TZStackViewTestCase: XCTestCase { override func setUp() { super.setUp() + recreateStackViews() + } + + override func tearDown() { + super.tearDown() + } + + func recreateStackViews() { + // clean old views otherwise some old spacer views and constraints are left + if uiStackView != nil { + uiStackView.removeFromSuperview() + } + + if tzStackView != nil { + tzStackView.removeFromSuperview() + } + // Create stack views with same views uiStackView = UIStackView(arrangedSubviews: createTestViews()) uiStackView.translatesAutoresizingMaskIntoConstraints = false tzStackView = TZStackView(arrangedSubviews: createTestViews()) tzStackView.translatesAutoresizingMaskIntoConstraints = false - + let window = UIApplication.sharedApplication().windows[0] window.addSubview(uiStackView) window.addSubview(tzStackView) - + configureStackViews(uiStackView, tzStackView) } - override func tearDown() { - super.tearDown() - } - func logAllConstraints() { print("================= UISTACKVIEW (\(uiStackView.constraints.count)) =================") print("subviews: \(uiStackView.subviews)") @@ -74,7 +87,9 @@ class TZStackViewTestCase: XCTestCase { func verifyConstraints(log log: Bool = false) { // Force constraints to be created + uiStackView.updateConstraintsIfNeeded() uiStackView.layoutIfNeeded() + tzStackView.updateConstraintsIfNeeded() tzStackView.layoutIfNeeded() if log { diff --git a/TZStackViewTests/TZStackViewTests.swift b/TZStackViewTests/TZStackViewTests.swift index 0d099c8..dff619a 100644 --- a/TZStackViewTests/TZStackViewTests.swift +++ b/TZStackViewTests/TZStackViewTests.swift @@ -23,994 +23,70 @@ class TZStackViewTests: TZStackViewTestCase { // views[2].hidden = true // views[3].hidden = true // views[4].hidden = true + return views } // Be careful to configure the same thing on the UIStackView as on the TZStackView, otherwise the test is unfair override func configureStackViews(uiStackView: UIStackView, _ tzStackView: TZStackView) { - uiStackView.layoutMarginsRelativeArrangement = false - tzStackView.layoutMarginsRelativeArrangement = false - } - - func testFillHorizontalFillEqually() { - uiStackView.axis = .Horizontal - uiStackView.distribution = .FillEqually - uiStackView.alignment = .Fill - tzStackView.axis = .Horizontal - tzStackView.distribution = .FillEqually - tzStackView.alignment = .Fill - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testFillVerticalFillEqually() { - uiStackView.axis = .Vertical - uiStackView.distribution = .FillEqually - uiStackView.alignment = .Fill - tzStackView.axis = .Vertical - tzStackView.distribution = .FillEqually - tzStackView.alignment = .Fill - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testFillHorizontalFill() { - uiStackView.axis = .Horizontal - uiStackView.distribution = .Fill - uiStackView.alignment = .Fill - tzStackView.axis = .Horizontal - tzStackView.distribution = .Fill - tzStackView.alignment = .Fill - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testFillVerticalFill() { - uiStackView.axis = .Vertical - uiStackView.distribution = .Fill - uiStackView.alignment = .Fill - tzStackView.axis = .Vertical - tzStackView.distribution = .Fill - tzStackView.alignment = .Fill - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testFillHorizontalFillProportionally() { - uiStackView.axis = .Horizontal - uiStackView.distribution = .FillProportionally - uiStackView.alignment = .Fill - tzStackView.axis = .Horizontal - tzStackView.distribution = .FillProportionally - tzStackView.alignment = .Fill - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testFillVerticalFillProportionally() { - uiStackView.axis = .Vertical - uiStackView.distribution = .FillProportionally - uiStackView.alignment = .Fill - tzStackView.axis = .Vertical - tzStackView.distribution = .FillProportionally - tzStackView.alignment = .Fill - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testFillHorizontalEqualSpacing() { - uiStackView.axis = .Horizontal - uiStackView.distribution = .EqualSpacing - uiStackView.alignment = .Fill - tzStackView.axis = .Horizontal - tzStackView.distribution = .EqualSpacing - tzStackView.alignment = .Fill - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testFillVerticalEqualSpacing() { - uiStackView.axis = .Vertical - uiStackView.distribution = .EqualSpacing - uiStackView.alignment = .Fill - tzStackView.axis = .Vertical - tzStackView.distribution = .EqualSpacing - tzStackView.alignment = .Fill - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testFillHorizontalEqualCentering() { - uiStackView.axis = .Horizontal - uiStackView.distribution = .EqualCentering - uiStackView.alignment = .Fill - tzStackView.axis = .Horizontal - tzStackView.distribution = .EqualCentering - tzStackView.alignment = .Fill - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testFillVerticalEqualCentering() { - uiStackView.axis = .Vertical - uiStackView.distribution = .EqualCentering - uiStackView.alignment = .Fill - tzStackView.axis = .Vertical - tzStackView.distribution = .EqualCentering - tzStackView.alignment = .Fill - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testCenterHorizontalFillEqually() { - uiStackView.axis = .Horizontal - uiStackView.distribution = .FillEqually - uiStackView.alignment = .Center - tzStackView.axis = .Horizontal - tzStackView.distribution = .FillEqually - tzStackView.alignment = .Center - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testCenterVerticalFillEqually() { - uiStackView.axis = .Vertical - uiStackView.distribution = .FillEqually - uiStackView.alignment = .Center - tzStackView.axis = .Vertical - tzStackView.distribution = .FillEqually - tzStackView.alignment = .Center - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testCenterHorizontalFill() { - uiStackView.axis = .Horizontal - uiStackView.distribution = .Fill - uiStackView.alignment = .Center - tzStackView.axis = .Horizontal - tzStackView.distribution = .Fill - tzStackView.alignment = .Center - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testCenterVerticalFill() { - uiStackView.axis = .Vertical - uiStackView.distribution = .Fill - uiStackView.alignment = .Center - tzStackView.axis = .Vertical - tzStackView.distribution = .Fill - tzStackView.alignment = .Center - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testCenterHorizontalFillProportionally() { - uiStackView.axis = .Horizontal - uiStackView.distribution = .FillProportionally - uiStackView.alignment = .Center - tzStackView.axis = .Horizontal - tzStackView.distribution = .FillProportionally - tzStackView.alignment = .Center - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testCenterVetricalFillProportionally() { - uiStackView.axis = .Vertical - uiStackView.distribution = .FillProportionally - uiStackView.alignment = .Center - tzStackView.axis = .Vertical - tzStackView.distribution = .FillProportionally - tzStackView.alignment = .Center - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testCenterHorizontalEqualSpacing() { - uiStackView.axis = .Horizontal - uiStackView.distribution = .EqualSpacing - uiStackView.alignment = .Center - tzStackView.axis = .Horizontal - tzStackView.distribution = .EqualSpacing - tzStackView.alignment = .Center - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testCenterVerticalEqualSpacing() { - uiStackView.axis = .Vertical - uiStackView.distribution = .EqualSpacing - uiStackView.alignment = .Center - tzStackView.axis = .Vertical - tzStackView.distribution = .EqualSpacing - tzStackView.alignment = .Center - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testCenterHorizontalEqualCentering() { - uiStackView.axis = .Horizontal - uiStackView.distribution = .EqualCentering - uiStackView.alignment = .Center - tzStackView.axis = .Horizontal - tzStackView.distribution = .EqualCentering - tzStackView.alignment = .Center - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testCenterVerticalEqualCentering() { - uiStackView.axis = .Vertical - uiStackView.distribution = .EqualCentering - uiStackView.alignment = .Center - tzStackView.axis = .Vertical - tzStackView.distribution = .EqualCentering - tzStackView.alignment = .Center - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testLeadingHorizontalFillEqually() { - uiStackView.axis = .Horizontal - uiStackView.distribution = .FillEqually - uiStackView.alignment = .Leading - tzStackView.axis = .Horizontal - tzStackView.distribution = .FillEqually - tzStackView.alignment = .Leading - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testLeadingHorizontalFill() { - uiStackView.axis = .Horizontal - uiStackView.distribution = .Fill - uiStackView.alignment = .Leading - tzStackView.axis = .Horizontal - tzStackView.distribution = .Fill - tzStackView.alignment = .Leading - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testLeadingHorizontalFillProportionally() { - uiStackView.axis = .Horizontal - uiStackView.distribution = .FillProportionally - uiStackView.alignment = .Leading - tzStackView.axis = .Horizontal - tzStackView.distribution = .FillProportionally - tzStackView.alignment = .Leading - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testLeadingHorizontalEqualSpacing() { - uiStackView.axis = .Horizontal - uiStackView.distribution = .EqualSpacing - uiStackView.alignment = .Leading - tzStackView.axis = .Horizontal - tzStackView.distribution = .EqualSpacing - tzStackView.alignment = .Leading - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testLeadingHorizontalEqualCentering() { - uiStackView.axis = .Horizontal - uiStackView.distribution = .EqualCentering - uiStackView.alignment = .Leading - tzStackView.axis = .Horizontal - tzStackView.distribution = .EqualCentering - tzStackView.alignment = .Leading - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testLeadingVerticalFillEqually() { - uiStackView.axis = .Vertical - uiStackView.distribution = .FillEqually - uiStackView.alignment = .Leading - tzStackView.axis = .Vertical - tzStackView.distribution = .FillEqually - tzStackView.alignment = .Leading - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testLeadingVerticalFill() { - uiStackView.axis = .Vertical - uiStackView.distribution = .Fill - uiStackView.alignment = .Leading - tzStackView.axis = .Vertical - tzStackView.distribution = .Fill - tzStackView.alignment = .Leading - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testLeadingVerticalFillProportionally() { - uiStackView.axis = .Vertical - uiStackView.distribution = .FillProportionally - uiStackView.alignment = .Leading - tzStackView.axis = .Vertical - tzStackView.distribution = .FillProportionally - tzStackView.alignment = .Leading - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testLeadingVerticalEqualSpacing() { - uiStackView.axis = .Vertical - uiStackView.distribution = .EqualSpacing - uiStackView.alignment = .Leading - tzStackView.axis = .Vertical - tzStackView.distribution = .EqualSpacing - tzStackView.alignment = .Leading - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testLeadingVerticalEqualCentering() { - uiStackView.axis = .Vertical - uiStackView.distribution = .EqualCentering - uiStackView.alignment = .Leading - tzStackView.axis = .Vertical - tzStackView.distribution = .EqualCentering - tzStackView.alignment = .Leading - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - func testTopHorizontalFillEqually() { - uiStackView.axis = .Horizontal - uiStackView.distribution = .FillEqually - uiStackView.alignment = .Top - tzStackView.axis = .Horizontal - tzStackView.distribution = .FillEqually - tzStackView.alignment = .Top - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testTopHorizontalFill() { - uiStackView.axis = .Horizontal - uiStackView.distribution = .Fill - uiStackView.alignment = .Top - tzStackView.axis = .Horizontal - tzStackView.distribution = .Fill - tzStackView.alignment = .Top - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testTopHorizontalFillProportionally() { - uiStackView.axis = .Horizontal - uiStackView.distribution = .FillProportionally - uiStackView.alignment = .Top - tzStackView.axis = .Horizontal - tzStackView.distribution = .FillProportionally - tzStackView.alignment = .Top - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testTopHorizontalEqualSpacing() { - uiStackView.axis = .Horizontal - uiStackView.distribution = .EqualSpacing - uiStackView.alignment = .Top - tzStackView.axis = .Horizontal - tzStackView.distribution = .EqualSpacing - tzStackView.alignment = .Top - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testTopHorizontalEqualCentering() { - uiStackView.axis = .Horizontal - uiStackView.distribution = .EqualCentering - uiStackView.alignment = .Top - tzStackView.axis = .Horizontal - tzStackView.distribution = .EqualCentering - tzStackView.alignment = .Top - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() } - func testTopHVerticalFillEqually() { - uiStackView.axis = .Vertical - uiStackView.distribution = .FillEqually - uiStackView.alignment = .Top - tzStackView.axis = .Vertical - tzStackView.distribution = .FillEqually - tzStackView.alignment = .Top - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testTopVerticalFill() { - uiStackView.axis = .Vertical - uiStackView.distribution = .Fill - uiStackView.alignment = .Top - tzStackView.axis = .Vertical - tzStackView.distribution = .Fill - tzStackView.alignment = .Top - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testTopVerticalFillProportionally() { - uiStackView.axis = .Vertical - uiStackView.distribution = .FillProportionally - uiStackView.alignment = .Top - tzStackView.axis = .Vertical - tzStackView.distribution = .FillProportionally - tzStackView.alignment = .Top - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testTopVerticalEqualSpacing() { - uiStackView.axis = .Vertical - uiStackView.distribution = .EqualSpacing - uiStackView.alignment = .Top - tzStackView.axis = .Vertical - tzStackView.distribution = .EqualSpacing - tzStackView.alignment = .Top - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testTopVerticalEqualCentering() { - uiStackView.axis = .Vertical - uiStackView.distribution = .EqualCentering - uiStackView.alignment = .Top - tzStackView.axis = .Vertical - tzStackView.distribution = .EqualCentering - tzStackView.alignment = .Top - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testTrailingHorizontalFillEqually() { - uiStackView.axis = .Horizontal - uiStackView.distribution = .FillEqually - uiStackView.alignment = .Trailing - tzStackView.axis = .Horizontal - tzStackView.distribution = .FillEqually - tzStackView.alignment = .Trailing - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testTrailingHorizontalFill() { - uiStackView.axis = .Horizontal - uiStackView.distribution = .Fill - uiStackView.alignment = .Trailing - tzStackView.axis = .Horizontal - tzStackView.distribution = .Fill - tzStackView.alignment = .Trailing - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testTrailingHorizontalFillProportionally() { - uiStackView.axis = .Horizontal - uiStackView.distribution = .FillProportionally - uiStackView.alignment = .Trailing - tzStackView.axis = .Horizontal - tzStackView.distribution = .FillProportionally - tzStackView.alignment = .Trailing - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testTrailingHorizontalEqualSpacing() { - uiStackView.axis = .Horizontal - uiStackView.distribution = .EqualSpacing - uiStackView.alignment = .Trailing - tzStackView.axis = .Horizontal - tzStackView.distribution = .EqualSpacing - tzStackView.alignment = .Trailing - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testTrailingHorizontalEqualCentering() { - uiStackView.axis = .Horizontal - uiStackView.distribution = .EqualCentering - uiStackView.alignment = .Trailing - tzStackView.axis = .Horizontal - tzStackView.distribution = .EqualCentering - tzStackView.alignment = .Trailing - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testTrailingVerticalFillEqually() { - uiStackView.axis = .Vertical - uiStackView.distribution = .FillEqually - uiStackView.alignment = .Trailing - tzStackView.axis = .Vertical - tzStackView.distribution = .FillEqually - tzStackView.alignment = .Trailing - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testTrailingVerticalFill() { - uiStackView.axis = .Vertical - uiStackView.distribution = .Fill - uiStackView.alignment = .Trailing - tzStackView.axis = .Vertical - tzStackView.distribution = .Fill - tzStackView.alignment = .Trailing - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testTrailingVerticalFillProportionally() { - uiStackView.axis = .Vertical - uiStackView.distribution = .FillProportionally - uiStackView.alignment = .Trailing - tzStackView.axis = .Vertical - tzStackView.distribution = .FillProportionally - tzStackView.alignment = .Trailing - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testTrailingVerticalEqualSpacing() { - uiStackView.axis = .Vertical - uiStackView.distribution = .EqualSpacing - uiStackView.alignment = .Trailing - tzStackView.axis = .Vertical - tzStackView.distribution = .EqualSpacing - tzStackView.alignment = .Trailing - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testTrailingVerticalEqualCentering() { - uiStackView.axis = .Vertical - uiStackView.distribution = .EqualCentering - uiStackView.alignment = .Trailing - tzStackView.axis = .Vertical - tzStackView.distribution = .EqualCentering - tzStackView.alignment = .Trailing - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testBottomHorizontalFillEqually() { - uiStackView.axis = .Horizontal - uiStackView.distribution = .FillEqually - uiStackView.alignment = .Bottom - tzStackView.axis = .Horizontal - tzStackView.distribution = .FillEqually - tzStackView.alignment = .Bottom - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testBottomHorizontalFill() { - uiStackView.axis = .Horizontal - uiStackView.distribution = .Fill - uiStackView.alignment = .Bottom - tzStackView.axis = .Horizontal - tzStackView.distribution = .Fill - tzStackView.alignment = .Bottom - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testBottomHorizontalFillProportionally() { - uiStackView.axis = .Horizontal - uiStackView.distribution = .FillProportionally - uiStackView.alignment = .Bottom - tzStackView.axis = .Horizontal - tzStackView.distribution = .FillProportionally - tzStackView.alignment = .Bottom - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testBottomHorizontalEqualSpacing() { - uiStackView.axis = .Horizontal - uiStackView.distribution = .EqualSpacing - uiStackView.alignment = .Bottom - tzStackView.axis = .Horizontal - tzStackView.distribution = .EqualSpacing - tzStackView.alignment = .Bottom - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testBottomHorizontalEqualCentering() { - uiStackView.axis = .Horizontal - uiStackView.distribution = .EqualCentering - uiStackView.alignment = .Bottom - tzStackView.axis = .Horizontal - tzStackView.distribution = .EqualCentering - tzStackView.alignment = .Bottom - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testBottomVerticalFillEqually() { - uiStackView.axis = .Vertical - uiStackView.distribution = .FillEqually - uiStackView.alignment = .Bottom - tzStackView.axis = .Vertical - tzStackView.distribution = .FillEqually - tzStackView.alignment = .Bottom - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testBottomVerticalFill() { - uiStackView.axis = .Vertical - uiStackView.distribution = .Fill - uiStackView.alignment = .Bottom - tzStackView.axis = .Vertical - tzStackView.distribution = .Fill - tzStackView.alignment = .Bottom - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testBottomVerticalFillProportionally() { - uiStackView.axis = .Vertical - uiStackView.distribution = .FillProportionally - uiStackView.alignment = .Bottom - tzStackView.axis = .Vertical - tzStackView.distribution = .FillProportionally - tzStackView.alignment = .Bottom - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testBottomVerticalEqualSpacing() { - uiStackView.axis = .Vertical - uiStackView.distribution = .EqualSpacing - uiStackView.alignment = .Bottom - tzStackView.axis = .Vertical - tzStackView.distribution = .EqualSpacing - tzStackView.alignment = .Bottom - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testBottomVerticalEqualCentering() { - uiStackView.axis = .Vertical - uiStackView.distribution = .EqualCentering - uiStackView.alignment = .Bottom - tzStackView.axis = .Vertical - tzStackView.distribution = .EqualCentering - tzStackView.alignment = .Bottom - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testFirstBaselineHorizontalFillEqually() { - uiStackView.axis = .Horizontal - uiStackView.distribution = .FillEqually - uiStackView.alignment = .FirstBaseline - tzStackView.axis = .Horizontal - tzStackView.distribution = .FillEqually - tzStackView.alignment = .FirstBaseline - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testFirstBaselineHorizontalFill() { - uiStackView.axis = .Horizontal - uiStackView.distribution = .Fill - uiStackView.alignment = .FirstBaseline - tzStackView.axis = .Horizontal - tzStackView.distribution = .Fill - tzStackView.alignment = .FirstBaseline - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testFirstBaselineHorizontalFillProportionally() { - uiStackView.axis = .Horizontal - uiStackView.distribution = .FillProportionally - uiStackView.alignment = .FirstBaseline - tzStackView.axis = .Horizontal - tzStackView.distribution = .FillProportionally - tzStackView.alignment = .FirstBaseline - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testFirstBaselineHorizontalEqualSpacing() { - uiStackView.axis = .Horizontal - uiStackView.distribution = .EqualSpacing - uiStackView.alignment = .FirstBaseline - tzStackView.axis = .Horizontal - tzStackView.distribution = .EqualSpacing - tzStackView.alignment = .FirstBaseline - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testFirstBaselineHorizontalEqualCentering() { - uiStackView.axis = .Horizontal - uiStackView.distribution = .EqualCentering - uiStackView.alignment = .FirstBaseline - tzStackView.axis = .Horizontal - tzStackView.distribution = .EqualCentering - tzStackView.alignment = .FirstBaseline - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testFirstBaselineVerticalFillEqually() { - uiStackView.axis = .Vertical - uiStackView.distribution = .FillEqually - uiStackView.alignment = .FirstBaseline - tzStackView.axis = .Vertical - tzStackView.distribution = .FillEqually - tzStackView.alignment = .FirstBaseline - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - logAllConstraints() - } - - func testFirstBaselineVerticalFill() { - uiStackView.axis = .Vertical - uiStackView.distribution = .Fill - uiStackView.alignment = .FirstBaseline - tzStackView.axis = .Vertical - tzStackView.distribution = .Fill - tzStackView.alignment = .FirstBaseline - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testFirstBaselineVerticalFillProportionally() { - uiStackView.axis = .Vertical - uiStackView.distribution = .FillProportionally - uiStackView.alignment = .FirstBaseline - tzStackView.axis = .Vertical - tzStackView.distribution = .FillProportionally - tzStackView.alignment = .FirstBaseline - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testFirstBaselineVerticalEqualSpacing() { - uiStackView.axis = .Vertical - uiStackView.distribution = .EqualSpacing - uiStackView.alignment = .FirstBaseline - tzStackView.axis = .Vertical - tzStackView.distribution = .EqualSpacing - tzStackView.alignment = .FirstBaseline - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() - } - - func testFirstBaselineVerticalEqualCentering() { - uiStackView.axis = .Vertical - uiStackView.distribution = .EqualCentering - uiStackView.alignment = .FirstBaseline - tzStackView.axis = .Vertical - tzStackView.distribution = .EqualCentering - tzStackView.alignment = .FirstBaseline - - uiStackView.spacing = 10 - tzStackView.spacing = 10 - - verifyConstraints() + func testSameConstraints() { + let margins = [false] + let axes = [ + (UILayoutConstraintAxis.Horizontal, "Horizontal"), + (.Vertical, "Vertical") + ] + let distributions = [ + (UIStackViewDistribution.Fill, TZStackViewDistribution.Fill, "Fill"), + (.FillEqually, .FillEqually, "FillEqually"), + (.FillProportionally, .FillProportionally, "FillProportionally"), + (.EqualSpacing, .EqualSpacing, "EqualSpacing"), + (.EqualCentering, .EqualCentering, "EqualCentering") + ] + let alignments = [ + (UIStackViewAlignment.Fill, TZStackViewAlignment.Fill, "Fill"), + (.Leading, .Leading, "Leading"), + (UIStackViewAlignment.Top, TZStackViewAlignment.Top, "Top"), + (.FirstBaseline, .FirstBaseline, "FirstBaseline"), + (.Center, .Center, "Center"), + (.Trailing, .Trailing, "Trailing"), + (UIStackViewAlignment.Bottom, TZStackViewAlignment.Bottom, "Bottom"), + // TODO: LastBaseline + ] + let spacings = [CGFloat(10)] + + let cases = margins * axes * distributions * alignments * spacings + + for aCase in cases { + let (tuple4, spacing) = aCase + let (tuple3, aligment) = tuple4 + let (tuple2, distribution) = tuple3 + let (tuple1, axis) = tuple2 + let margin = tuple1 + + print("Test for layoutMarginsRelativeArrangement=\(margin), axis=\(axis.1), distribution=\(distribution.2), aligment=\(aligment.2), spacing=\(spacing)\n") + + recreateStackViews() + + uiStackView.layoutMarginsRelativeArrangement = margin + tzStackView.layoutMarginsRelativeArrangement = margin + + uiStackView.axis = axis.0 + tzStackView.axis = axis.0 + + uiStackView.distribution = distribution.0 + tzStackView.distribution = distribution.1 + + uiStackView.alignment = aligment.0 + tzStackView.alignment = aligment.1 + + uiStackView.spacing = spacing + tzStackView.spacing = spacing + + verifyConstraints() + } } // MARK: - Maintaining Consistency Between the Arranged Views and Subviews