Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor test #54

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions TZStackView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
5F50E9F2F7E5B2DA68C946E0 /* ExplicitIntrinsicContentSizeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F50E5EB8202F5247F8517F3 /* ExplicitIntrinsicContentSizeView.swift */; };
5F50EAD959E8ACC5929DBD75 /* NSLayoutConstraintExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB41AF691B294B8E003DB902 /* NSLayoutConstraintExtension.swift */; };
5F50EF474D670FC33E8E80EA /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5F50ED5A43FBFC32B9B9E1AA /* Images.xcassets */; };
7EF572D81BEE41100095237E /* Array+Product.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7EF572D71BEE41100095237E /* Array+Product.swift */; };
A45441C21B9B6D71002452BA /* TZStackView.h in Headers */ = {isa = PBXBuildFile; fileRef = A45441C11B9B6D71002452BA /* TZStackView.h */; settings = {ATTRIBUTES = (Public, ); }; };
A45441C61B9B6D71002452BA /* TZStackView.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A45441BF1B9B6D71002452BA /* TZStackView.framework */; };
A45441C71B9B6D71002452BA /* TZStackView.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = A45441BF1B9B6D71002452BA /* TZStackView.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
A45441D01B9B6D9C002452BA /* TZSpacerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A45441CC1B9B6D9C002452BA /* TZSpacerView.swift */; settings = {ASSET_TAGS = (); }; };
A45441D11B9B6D9C002452BA /* TZStackView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A45441CD1B9B6D9C002452BA /* TZStackView.swift */; settings = {ASSET_TAGS = (); }; };
A45441D21B9B6D9C002452BA /* TZStackViewAlignment.swift in Sources */ = {isa = PBXBuildFile; fileRef = A45441CE1B9B6D9C002452BA /* TZStackViewAlignment.swift */; settings = {ASSET_TAGS = (); }; };
A45441D31B9B6D9C002452BA /* TZStackViewDistribution.swift in Sources */ = {isa = PBXBuildFile; fileRef = A45441CF1B9B6D9C002452BA /* TZStackViewDistribution.swift */; settings = {ASSET_TAGS = (); }; };
A45441D01B9B6D9C002452BA /* TZSpacerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A45441CC1B9B6D9C002452BA /* TZSpacerView.swift */; };
A45441D11B9B6D9C002452BA /* TZStackView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A45441CD1B9B6D9C002452BA /* TZStackView.swift */; };
A45441D21B9B6D9C002452BA /* TZStackViewAlignment.swift in Sources */ = {isa = PBXBuildFile; fileRef = A45441CE1B9B6D9C002452BA /* TZStackViewAlignment.swift */; };
A45441D31B9B6D9C002452BA /* TZStackViewDistribution.swift in Sources */ = {isa = PBXBuildFile; fileRef = A45441CF1B9B6D9C002452BA /* TZStackViewDistribution.swift */; };
DB41AF6A1B294B8E003DB902 /* NSLayoutConstraintExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB41AF691B294B8E003DB902 /* NSLayoutConstraintExtension.swift */; };
DB5B70851B2A1963006043BD /* TestView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB5B70841B2A1963006043BD /* TestView.swift */; };
DB5B70871B2B8816006043BD /* TZStackViewTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB5B70861B2B8816006043BD /* TZStackViewTestCase.swift */; };
Expand Down Expand Up @@ -67,6 +68,7 @@
5F50EDEB0947F99E67140FC6 /* TZStackViewTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TZStackViewTests.swift; sourceTree = "<group>"; };
5F50EF54F01A3A6938C6CEA1 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
5F50EFD0C46B7C7F989F10E1 /* TZStackViewTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TZStackViewTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
7EF572D71BEE41100095237E /* Array+Product.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Array+Product.swift"; sourceTree = "<group>"; };
A45441BF1B9B6D71002452BA /* TZStackView.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = TZStackView.framework; sourceTree = BUILT_PRODUCTS_DIR; };
A45441C11B9B6D71002452BA /* TZStackView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TZStackView.h; sourceTree = "<group>"; };
A45441C31B9B6D71002452BA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -130,6 +132,7 @@
5F50EDEB0947F99E67140FC6 /* TZStackViewTests.swift */,
DB5B70841B2A1963006043BD /* TestView.swift */,
DB5B70861B2B8816006043BD /* TZStackViewTestCase.swift */,
7EF572D71BEE41100095237E /* Array+Product.swift */,
5F50E05A91CC731E5AFD4E94 /* Supporting Files */,
);
path = TZStackViewTests;
Expand Down Expand Up @@ -325,6 +328,7 @@
5F50E6EAC8DDE44079E03638 /* TZStackViewTests.swift in Sources */,
DB5B70871B2B8816006043BD /* TZStackViewTestCase.swift in Sources */,
DB5B70851B2A1963006043BD /* TestView.swift in Sources */,
7EF572D81BEE41100095237E /* Array+Product.swift in Sources */,
5F50EAD959E8ACC5929DBD75 /* NSLayoutConstraintExtension.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
21 changes: 21 additions & 0 deletions TZStackViewTests/Array+Product.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// Array+Product.swift
// TZStackView
//
// Created by Pan Yusheng on 11/7/15.
// Copyright © 2015 Tom van Zummeren. All rights reserved.
//

import Foundation

func * <E1, E2>(left: Array<E1>, right: Array<E2>) -> Array<(E1, E2)> {
var result = [(E1, E2)]()

for e1 in left {
for e2 in right {
result.append((e1, e2))
}
}

return result
}
27 changes: 21 additions & 6 deletions TZStackViewTests/TZStackViewTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
Expand Down Expand Up @@ -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 {
Expand Down
Loading