Skip to content

Commit

Permalink
Completed task 7 and closes #7
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Vanhoef authored and Peter Vanhoef committed Mar 25, 2017
1 parent 8800bb7 commit ca8d56c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
5 changes: 4 additions & 1 deletion Calculator/Calculator/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ViewController: UIViewController {
return Double(display.text!)!
}
set {
display.text = String(newValue)
display.text = String(format: "%g", newValue)
}
}

Expand All @@ -50,6 +50,9 @@ class ViewController: UIViewController {
if let result = brain.result {
displayValue = result
}
if let description = brain.description {
sequence.text = description + (brain.resultIsPending ? ( (description.characters.last != " ") ? "" : "") : " =")
}
}
}

26 changes: 13 additions & 13 deletions Calculator/CalculatorUITests/CalculatorUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ class CalculatorUITests: XCTestCase {
// cos(π) = -1
buttonPi.tap()
buttonCos.tap()
XCTAssert(app.staticTexts["-1.0"].exists)
XCTAssert(app.staticTexts["-1"].exists)

// 12 × 4 = 48
buttonDigit1.tap()
buttonDigit2.tap()
buttonMultiply.tap()
buttonDigit4.tap()
buttonEqual.tap()
XCTAssert(app.staticTexts["48.0"].exists)
XCTAssert(app.staticTexts["48"].exists)

// 568 + 78 = 646
buttonDigit5.tap()
Expand All @@ -79,21 +79,21 @@ class CalculatorUITests: XCTestCase {
buttonDigit7.tap()
buttonDigit8.tap()
buttonEqual.tap()
XCTAssert(app.staticTexts["646.0"].exists)
XCTAssert(app.staticTexts["646"].exists)

// 45 ÷ 5 = 9
buttonDigit4.tap()
buttonDigit5.tap()
buttonDivide.tap()
buttonDigit5.tap()
buttonEqual.tap()
XCTAssert(app.staticTexts["9.0"].exists)
XCTAssert(app.staticTexts["9"].exists)

// 23 ± = -23
buttonDigit2.tap()
buttonDigit3.tap()
app.buttons["±"].tap()
XCTAssert(app.staticTexts["-23.0"].exists)
XCTAssert(app.staticTexts["-23"].exists)

// 92736 - 123 = 92613
buttonDigit9.tap()
Expand All @@ -106,7 +106,7 @@ class CalculatorUITests: XCTestCase {
buttonDigit2.tap()
buttonDigit3.tap()
buttonEqual.tap()
XCTAssert(app.staticTexts["92613.0"].exists)
XCTAssert(app.staticTexts["92613"].exists)

// 8 × 0.5 = 4
buttonDigit8.tap()
Expand All @@ -115,15 +115,15 @@ class CalculatorUITests: XCTestCase {
buttonDecimalPoint.tap()
buttonDigit5.tap()
buttonEqual.tap()
XCTAssert(app.staticTexts["4.0"].exists)
XCTAssert(app.staticTexts["4"].exists)

// √(√(9)) = 3
buttonDigit8.tap()
buttonDigit1.tap()
buttonSqrt.tap()
XCTAssert(app.staticTexts["9.0"].exists)
XCTAssert(app.staticTexts["9"].exists)
buttonSqrt.tap()
XCTAssert(app.staticTexts["3.0"].exists)
XCTAssert(app.staticTexts["3"].exists)

}

Expand Down Expand Up @@ -220,16 +220,16 @@ class CalculatorUITests: XCTestCase {

app.buttons["0"].tap()
app.buttons["sin"].tap()
XCTAssert(app.staticTexts["0.0"].exists)
XCTAssert(app.staticTexts["0"].exists)

app.buttons["0"].tap()
app.buttons["tan"].tap()
XCTAssert(app.staticTexts["0.0"].exists)
XCTAssert(app.staticTexts["0"].exists)

app.buttons["1"].tap()
app.buttons["8"].tap()
app.buttons[""].tap()
XCTAssert(app.staticTexts["324.0"].exists)
XCTAssert(app.staticTexts["324"].exists)

app.buttons["4"].tap()
app.buttons["x⁻¹"].tap()
Expand Down Expand Up @@ -324,6 +324,6 @@ class CalculatorUITests: XCTestCase {
app.buttons["π"].tap()
app.buttons["="].tap()
XCTAssert(app.staticTexts["4 × π ="].exists)
//XCTAssert(app.staticTexts["12.5663706143592"].exists)
XCTAssert(app.staticTexts["12.5664"].exists)
}
}

0 comments on commit ca8d56c

Please sign in to comment.