Skip to content

Commit

Permalink
Completes task 9 (closes #9)
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Vanhoef authored and Peter Vanhoef committed May 15, 2017
1 parent a11cd82 commit 3333b1f
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 14 deletions.
27 changes: 23 additions & 4 deletions Calculator/Calculator/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<splitViewController id="fcY-c8-IEH" sceneMemberID="viewController">
<connections>
<segue destination="TDa-oR-bW1" kind="relationship" relationship="masterViewController" id="duf-bC-jqV"/>
<segue destination="Blb-hR-aDj" kind="relationship" relationship="detailViewController" id="jyr-Pc-8eS"/>
<segue destination="UDb-wa-Ofv" kind="relationship" relationship="detailViewController" id="jyr-Pc-8eS"/>
</connections>
</splitViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="17o-kj-Tfc" userLabel="First Responder" sceneMemberID="firstResponder"/>
Expand Down Expand Up @@ -137,7 +137,7 @@
<color key="titleColor" red="1" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
</state>
<connections>
<segue destination="Blb-hR-aDj" kind="showDetail" identifier="graph" id="Zbq-q6-BA9"/>
<segue destination="UDb-wa-Ofv" kind="showDetail" identifier="graph" id="Zbq-q6-BA9"/>
</connections>
</button>
</subviews>
Expand Down Expand Up @@ -476,13 +476,14 @@
<constraint firstItem="JcA-5Q-PcB" firstAttribute="top" secondItem="puX-M5-gZH" secondAttribute="top" id="uwf-4a-bNJ"/>
</constraints>
</view>
<navigationItem key="navigationItem" id="Byl-gt-gP5"/>
<connections>
<outlet property="graphingView" destination="JcA-5Q-PcB" id="Ylg-pt-MSa"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="rWH-Xh-Lu5" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="137" y="887"/>
<point key="canvasLocation" x="1076" y="886.50674662668678"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="0lk-22-Puh">
Expand All @@ -502,8 +503,26 @@
</objects>
<point key="canvasLocation" x="136.80000000000001" y="137.18140929535232"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="H1N-rL-x3A">
<objects>
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="UDb-wa-Ofv" sceneMemberID="viewController">
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" id="ZPK-pT-Z9r">
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
<connections>
<segue destination="Blb-hR-aDj" kind="relationship" relationship="rootViewController" id="FTt-lI-yuD"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="3YU-4j-vls" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="136.80000000000001" y="886.50674662668678"/>
</scene>
</scenes>
<inferredMetricsTieBreakers>
<segue reference="Zbq-q6-BA9"/>
<segue reference="jyr-Pc-8eS"/>
</inferredMetricsTieBreakers>
</document>
6 changes: 5 additions & 1 deletion Calculator/Calculator/CalculatorViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,17 @@ class CalculatorViewController: UIViewController {
// MARK: - Navigation

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let destinationViewController = segue.destination
var destinationViewController = segue.destination
if let navigationController = destinationViewController as? UINavigationController {
destinationViewController = navigationController.visibleViewController ?? destinationViewController
}
if let graphingViewController = destinationViewController as? GraphingViewController {
if let identifier = segue.identifier {
if identifier == "graph" {
graphingViewController.unaryFunction = { [weak weakSelf = self] operand in
let graphingDictionary: [String: Double] = ["M": operand]
return weakSelf?.brain.evaluate(using: graphingDictionary).result }
graphingViewController.navigationItem.title = self.brain.evaluate().description
}
}
}
Expand Down
48 changes: 39 additions & 9 deletions Calculator/CalculatorUITests/CalculatorUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -623,14 +623,22 @@ class CalculatorUITests: XCTestCase {
XCTAssertTrue(app.staticTexts["39"].exists)
}

func showCalculator() {
func showCalculator(navBarTitle: String = "Calculator.GraphingView") {
// Don't know if this is the best way to make the calculator visible ...
if XCUIApplication().navigationBars["Calculator.GraphingView"].exists {
XCUIApplication().navigationBars["Calculator.GraphingView"].buttons["Calculator"].tap()
} else {
if !XCUIApplication().navigationBars.element.isHittable {
if XCUIApplication().buttons["Graph"].exists {
if !XCUIApplication().buttons["Graph"].isHittable {
XCUIApplication().children(matching: .window).element(boundBy: 0).children(matching: .other).element.children(matching: .other).element(boundBy: 1).children(matching: .other).element.swipeRight()
}
} else {
if XCUIApplication().navigationBars[navBarTitle].exists {
if XCUIApplication().navigationBars[navBarTitle].buttons["Calculator"].exists {
XCUIApplication().navigationBars[navBarTitle].buttons["Calculator"].tap()
}
} else {
if !XCUIApplication().navigationBars.element.isHittable {
XCUIApplication().children(matching: .window).element(boundBy: 0).children(matching: .other).element.children(matching: .other).element(boundBy: 1).children(matching: .other).element.swipeRight()
}
}
}
}

Expand All @@ -640,15 +648,15 @@ class CalculatorUITests: XCTestCase {
app.buttons["M"].tap()
app.buttons["cos"].tap()
app.buttons["Graph"].tap()
showCalculator()
showCalculator(navBarTitle: "cos(M)")
XCTAssert(app.staticTexts["cos(M) ="].exists)
XCTAssert(app.staticTexts["1"].exists)
XCTAssert(app.staticTexts[" "].exists)

app.buttons["M"].tap()
app.buttons[""].tap()
app.buttons["Graph"].tap()
showCalculator()
showCalculator(navBarTitle: "√(M)")
XCTAssert(app.staticTexts["√(M) ="].exists)
XCTAssert(app.staticTexts["0"].exists)
XCTAssert(app.staticTexts[" "].exists)
Expand All @@ -660,17 +668,39 @@ class CalculatorUITests: XCTestCase {
XCTAssert(app.staticTexts["3"].exists)
XCTAssert(app.staticTexts["9"].exists)
app.buttons["Graph"].tap()
showCalculator()
showCalculator(navBarTitle: "√(M)")
XCTAssert(app.staticTexts["√(M) ="].exists)
XCTAssert(app.staticTexts["3"].exists)
XCTAssert(app.staticTexts["9"].exists)

app.buttons["M"].tap()
app.buttons["tan"].tap()
app.buttons["Graph"].tap()
showCalculator()
showCalculator(navBarTitle: "tan(M)")
XCTAssert(app.staticTexts["tan(M) ="].exists)
XCTAssert(app.staticTexts["-0.452316"].exists)
XCTAssert(app.staticTexts["9"].exists)
}

func testGraphTitleAssignment3Task8() {
let app = XCUIApplication()

app.buttons["M"].tap()
app.buttons["cos"].tap()
app.buttons["Graph"].tap()
XCTAssert(app.staticTexts["cos(M)"].exists)
showCalculator(navBarTitle: "cos(M)")
XCTAssert(app.staticTexts["cos(M) ="].exists)
XCTAssert(app.staticTexts["1"].exists)
XCTAssert(app.staticTexts[" "].exists)

app.buttons["M"].tap()
app.buttons[""].tap()
app.buttons["Graph"].tap()
XCTAssert(app.staticTexts["√(M)"].exists)
showCalculator(navBarTitle: "√(M)")
XCTAssert(app.staticTexts["√(M) ="].exists)
XCTAssert(app.staticTexts["0"].exists)
XCTAssert(app.staticTexts[" "].exists)
}
}

0 comments on commit 3333b1f

Please sign in to comment.