@@ -24,7 +24,7 @@ final class UIViewContrainAspectRatioTests: XCTestCase {
2424 XCTAssertEqual ( constraint. secondAttribute, . height)
2525 }
2626
27- func test_constrainAspectRatio_translatesAutoResizingMaskIsFalse ( ) {
27+ func test_constrainAspectRatio_translatesAutoresizingMaskIntoConstraintsIsFalse ( ) {
2828 // Arrange
2929 let sut = makeSUT ( )
3030 // Act
@@ -33,38 +33,34 @@ final class UIViewContrainAspectRatioTests: XCTestCase {
3333 XCTAssertFalse ( sut. translatesAutoresizingMaskIntoConstraints)
3434 }
3535
36- func test_constrainAspectRatio_deliversMultiplierForTheGivenRatio ( ) {
36+ func test_constrainAspectRatio_multiplierAndRatioMatches ( ) {
3737 // Arrange
3838 let sut = makeSUT ( )
39+ let ratio = 0.5
3940 // Act
40- let constraint = sut. constrainAspectRatio ( 0.5 )
41+ let constraint = sut. constrainAspectRatio ( ratio )
4142 // Assert
42- XCTAssertEqual ( constraint. multiplier, 0.5 )
43+ XCTAssertEqual ( constraint. multiplier, ratio )
4344 }
4445
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+ }
6864}
6965
7066private extension UIViewContrainAspectRatioTests {
0 commit comments