@@ -24,7 +24,7 @@ final class UIViewContrainAspectRatioTests: XCTestCase {
24
24
XCTAssertEqual ( constraint. secondAttribute, . height)
25
25
}
26
26
27
- func test_constrainAspectRatio_translatesAutoResizingMaskIsFalse ( ) {
27
+ func test_constrainAspectRatio_translatesAutoresizingMaskIntoConstraintsIsFalse ( ) {
28
28
// Arrange
29
29
let sut = makeSUT ( )
30
30
// Act
@@ -33,38 +33,34 @@ final class UIViewContrainAspectRatioTests: XCTestCase {
33
33
XCTAssertFalse ( sut. translatesAutoresizingMaskIntoConstraints)
34
34
}
35
35
36
- func test_constrainAspectRatio_deliversMultiplierForTheGivenRatio ( ) {
36
+ func test_constrainAspectRatio_multiplierAndRatioMatches ( ) {
37
37
// Arrange
38
38
let sut = makeSUT ( )
39
+ let ratio = 0.5
39
40
// Act
40
- let constraint = sut. constrainAspectRatio ( 0.5 )
41
+ let constraint = sut. constrainAspectRatio ( ratio )
41
42
// Assert
42
- XCTAssertEqual ( constraint. multiplier, 0.5 )
43
+ XCTAssertEqual ( constraint. multiplier, ratio )
43
44
}
44
45
45
- // func test_constrainAspectRatio_layoutsSUT() {
46
- // // Arrange
47
- // let containerView = UIView()
48
- // containerView.translatesAutoresizingMaskIntoConstraints = false
49
- //
50
- // containerView.heightAnchor.constraint(equalToConstant: 500).isActive = true
51
- // containerView.widthAnchor.constraint(equalToConstant: 500).isActive = true
52
- //
53
- // containerView.layoutIfNeeded()
54
- //
55
- //
56
- //
57
- // let sut = makeSUT()
58
- //
59
- // // Act
60
- // sut.constrainAspectRatio(0.5)
61
- //
62
- // sut.layoutIfNeeded()
63
- //
64
- //
65
- //
66
- // XCTAssertEqual(sut.frame.height, sut.frame.width * 0.5)
67
- // }
46
+ func test_constrainAspectRatio_resizesSUTWithGivenRatio( ) {
47
+ // Arrange
48
+ let containerView = UIView ( frame: CGRect ( origin: . zero, size: CGSize ( width: 500 , height: 500 ) ) )
49
+ let sut = makeSUT ( )
50
+ containerView. addSubview ( sut)
51
+
52
+ let ratio : CGFloat = 0.5
53
+ let height : CGFloat = 300
54
+ sut. constrain ( . heightAnchor, constant: height)
55
+
56
+ // Act
57
+ sut. constrainAspectRatio ( ratio)
58
+ sut. layoutIfNeeded ( )
59
+
60
+ // Assert
61
+ XCTAssertEqual ( sut. bounds. width, ratio * sut. bounds. height)
62
+ XCTAssertEqual ( sut. bounds. height, height)
63
+ }
68
64
}
69
65
70
66
private extension UIViewContrainAspectRatioTests {
0 commit comments