Skip to content

Commit

Permalink
Add test cases for extra credit 3 (see #14)
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Vanhoef authored and Peter Vanhoef committed Apr 2, 2017
1 parent 86e09ef commit 93fc2fc
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
23 changes: 16 additions & 7 deletions Calculator/Calculator/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="16D32" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="16E195" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
Expand Down Expand Up @@ -263,16 +263,25 @@
<rect key="frame" x="0.0" y="420" width="343" height="95"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Fxs-Lj-1vM">
<rect key="frame" x="0.0" y="0.0" width="60.5" height="95"/>
<rect key="frame" x="0.0" y="0.0" width="49" height="95"/>
<color key="backgroundColor" white="0.66666666666666663" alpha="1" colorSpace="calibratedWhite"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<state key="normal" title="Rand"/>
<connections>
<action selector="performOperation:" destination="BYZ-38-t0r" eventType="touchUpInside" id="nPD-0Z-Kqx"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="8Ha-iS-HQn">
<rect key="frame" x="59" y="0.0" width="48.5" height="95"/>
<color key="backgroundColor" white="0.66666666666666663" alpha="1" colorSpace="calibratedWhite"/>
<fontDescription key="fontDescription" type="system" pointSize="30"/>
<state key="normal" title="x⁻¹"/>
<connections>
<action selector="performOperation:" destination="BYZ-38-t0r" eventType="touchUpInside" id="nPD-0Z-Kqx"/>
<action selector="performOperation:" destination="BYZ-38-t0r" eventType="touchUpInside" id="d4b-jS-Hfw"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="OGw-se-LwE">
<rect key="frame" x="70.5" y="0.0" width="60.5" height="95"/>
<rect key="frame" x="117.5" y="0.0" width="49" height="95"/>
<color key="backgroundColor" white="0.66666666666666663" alpha="1" colorSpace="calibratedWhite"/>
<fontDescription key="fontDescription" type="system" pointSize="30"/>
<state key="normal" title=""/>
Expand All @@ -281,7 +290,7 @@
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="eb5-VH-801">
<rect key="frame" x="141" y="0.0" width="61" height="95"/>
<rect key="frame" x="176.5" y="0.0" width="49" height="95"/>
<color key="backgroundColor" red="0.90196079019999997" green="0.90196079019999997" blue="0.90196079019999997" alpha="1" colorSpace="calibratedRGB"/>
<fontDescription key="fontDescription" type="system" pointSize="30"/>
<state key="normal" title="."/>
Expand All @@ -290,7 +299,7 @@
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="siW-tm-oha">
<rect key="frame" x="212" y="0.0" width="60.5" height="95"/>
<rect key="frame" x="235.5" y="0.0" width="48.5" height="95"/>
<color key="backgroundColor" red="0.90196079019999997" green="0.90196079019999997" blue="0.90196079019999997" alpha="1" colorSpace="calibratedRGB"/>
<fontDescription key="fontDescription" type="system" pointSize="30"/>
<state key="normal" title="0"/>
Expand All @@ -299,7 +308,7 @@
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="OeV-vI-cY8">
<rect key="frame" x="282.5" y="0.0" width="60.5" height="95"/>
<rect key="frame" x="294" y="0.0" width="49" height="95"/>
<color key="backgroundColor" red="1" green="0.5" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<fontDescription key="fontDescription" type="system" pointSize="30"/>
<state key="normal" title="=">
Expand Down
15 changes: 15 additions & 0 deletions Calculator/CalculatorTests/CalculatorBrainTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -250,4 +250,19 @@ class CalculatorBrainTests: XCTestCase {
XCTAssertFalse(testBrain.resultIsPending)
XCTAssertTrue(abs(testBrain.result! - 5.123456) < 0.0001)
}

func testRandExtraCredit3() {
var testBrain = CalculatorBrain()

testBrain.setOperand(10)
testBrain.performOperation("+")
testBrain.performOperation("Rand")
testBrain.performOperation("=")
XCTAssertFalse(testBrain.resultIsPending)
if testBrain.result != nil {
XCTAssertTrue(abs(testBrain.result! - 10) <= 1)
} else {
XCTAssertFalse(testBrain.result == nil)
}
}
}
11 changes: 11 additions & 0 deletions Calculator/CalculatorUITests/CalculatorUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -439,4 +439,15 @@ class CalculatorUITests: XCTestCase {
XCTAssert(app.staticTexts["4.123457 + 1 ="].exists)
XCTAssert(app.staticTexts["5.123457"].exists)
}

func testRandExtraCredit3() {
let app = XCUIApplication()

app.buttons["Rand"].tap()
app.buttons["+"].tap()
app.buttons["4"].tap()
app.buttons["="].tap()
XCTAssertFalse(app.staticTexts["4 ="].exists)
XCTAssertFalse(app.staticTexts["4"].exists)
}
}

0 comments on commit 93fc2fc

Please sign in to comment.