Skip to content

Commit

Permalink
include requested edits. ALSO note my comment in the tests regarding …
Browse files Browse the repository at this point in the history
…perhaps we should be more specific about the precision for testing. Also still waiting on word as to where to put sample solutions; the current ReadMe contains sample solutions for problems 1 + 2.
  • Loading branch information
Guy Ardito authored and Guy Ardito committed Jul 1, 2016
1 parent 884297e commit 82622ed
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 3 deletions.
Binary file modified .DS_Store
Binary file not shown.
48 changes: 48 additions & 0 deletions AllTheBasicsTests/VCTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,52 @@ class VCTests: QuickSpec {

let testVC = ViewController()


describe("averageIsAbove75(_:b:c:)") {
it("Takes three numbers and, if their average is over 75, returns true, otherwise returns false") {


expect( testVC.averageIsAbove75( 76.0, b: 75.0, c: 71.9 )).to(equal(false)) // NOTE we might want to get specific about the precision & rounding they should use (eg. is 75.4 > 75? 75.4 is *definitely* greater than 75.0)

expect( testVC.averageIsAbove75( 75.0, b: 75.0, c: 75.0 )).to(equal(false)) // must be *OVER* 75

expect( testVC.averageIsAbove75( 75.1, b: 75.0, c: 75.0 )).to(equal(true)) // they should be using Doubles, so this is *just* over 75

expect( testVC.averageIsAbove75( 80.0, b: 80.0, c: 80.0 )).to(equal(true))
}
}




describe("passwordCombo(_:password:)") {
it("Takes a String and an Int. If the String is equal to Jerry, Elaine or Michael, AND the Int is evenly divisible by 3, then it returns true, otherwise it returns false") {

expect( testVC.passwordCombo( "Jose", 3 ) ).to(equal(false)) // bad name

expect( testVC.passwordCombo( "Elain", 3 ) ).to(equal(false)) // slight misspelled name

expect( testVC.passwordCombo( "Jerry", 4 ) ).to(equal(false)) // bad number

expect( testVC.passwordCombo( "Jose", 4 ) ).to(equal(false)) // bad name and bad number


expect( testVC.passwordCombo( "Jerry", 3 ) ).to(equal(true))

expect( testVC.passwordCombo( "Elaine", 6 ) ).to(equal(true))

expect( testVC.passwordCombo( "Michael", 21 ) ).to(equal(true))

expect( testVC.passwordCombo( "Michael", 0 ) ).to(equal(true))



}
}




describe("doIt(_:b:)") {

it("Checks the validity of each paramters and returns their product as a double or, if there's a validation error, it returns 0") {
Expand All @@ -39,6 +85,8 @@ class VCTests: QuickSpec {
}




}


Expand Down
70 changes: 67 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,71 @@
## Fun with Basics!

##Instructions
Write a function "doIt" on the class ViewController which takes two paramters: "a" (which is of type String) and "b" (which is of type Float) and returns a Float.
In this final lab you'll be writing three functions.

**1** - Create a function named averageIsAbove75 that takes in three arguments all of type Double with a return type of type Bool. Create this function in the ViewController.swift file located in the .xcworkspace file included with this repo. Create this function in that file below where you see the following comment:

````Swift
// Implement your functions here
````
If you were to call on this function, it would yield the following results:

````Swift
averageIsAbove75(55, 25, 24)
// false

averageIsAbove75(100, 85, 90)
// true
````

Answer to the above question (tests would need to be written for this).

````Swift
func averageIsAbove75(a: Double, _ b: Double, _ c: Double) -> Bool {
let avg = (a + b + c) / 3
return avg > 75
}
````

**2** - Create a function named ````passwordCombo```` that takes in two arguments, one of type String which represents the username and the other of type ````Int```` which represents the password. This function will return a ````String```` letting the caller of this function know if the username/password combo passed into the function is correct!

What makes it correct? The conditions are.. the username ````String```` must be either 'Jerry', 'Elane', or 'Michael'. The password must be divisible by 3. If the username + password conditions pass, then return back the ````String```` "Welcome!". If either or both fail, then the String to be returned should be "Access Denied"

Calling this function should yield the following results:

````Swift
passwordCombo(username: "Bran", password: 22)
// "Access Denied

passwordCombo(username: "Elane", password: 20)
// "Access Denied"

passwordCombo(username: "Elane", password: 33)
// "Welcome!"
````

Answer to the above question (tests would need to be written for this).

````Swift
func passwordCombo(username username: String, password: Int) -> String {
switch username {
case "Jerry", "Elane", "Michael":

if password % 3 == 0 {
return "Welcome!"
} else {
return "Access Denied"
}

default: return "Access Denied"
}
}
````




**3** - Write a function ````doIt```` on the class ViewController which takes two paramters: "a" (which is of type ````String````) and "b" (which is of type ````Float````) and returns a ````Float````.

Here is how ````doIt```` should work:
* Return zero if "a" does not represent a whole number between 1 and 5 (inclusive).
Expand All @@ -20,10 +84,10 @@ let a = doIt("2", 10.5)
// a = 21.0

let b = doIt("9", 10.5)
// b = 0.0
// b = 0.0 because the first paramter is out of range

let c = doIt("2", 7)
// c = 0.0
// c = 0.0 because the second parameter is out of range
````


Expand Down

0 comments on commit 82622ed

Please sign in to comment.