Convert a grade out of 100 to a letter grade.
Here are the criteria: used in assessing:
90-100 points = A
80-89 points = B
70-79 points = C
60-69 points = D
0-59 points = F
Make sure to return "Not a grade" for integers that are not equal to or between 100.
func gradeCalc(_ score: Int) -> String { switch score { case 90...100: return "A" case 80..<90: return "B" case 70..<80: return "C" case 60..<70: return "D" case 0..<60: return "F" default: return "Not a grade" } }
func gradeCalc(_ score: Int) {// Your Code under here- func gradeCalc(_ score: Int) -> String {
- switch score {
- case 90...100: return "A"
- case 80..<90: return "B"
- case 70..<80: return "C"
- case 60..<70: return "D"
- case 0..<60: return "F"
- default: return "Not a grade"
- }
- }
import XCTest // XCTest Spec Example: // TODO: replace with your own tests (TDD), these are just how-to examples to get you started class SolutionTest: XCTestCase { static var allTests = [ ("Test Example", testExample), ] func testExample() { XCTAssertEqual(gradeCalc(100), "A") XCTAssertEqual(gradeCalc(96), "A") XCTAssertEqual(gradeCalc(90), "A") XCTAssertEqual(gradeCalc(30), "F") XCTAssertEqual(gradeCalc(70), "C") XCTAssertEqual(gradeCalc(79), "C") XCTAssertEqual(gradeCalc(80), "B") XCTAssertEqual(gradeCalc(-27), "Not a grade") XCTAssertEqual(gradeCalc(127), "Not a grade") } } XCTMain([ testCase(SolutionTest.allTests) ])
- import XCTest
- // XCTest Spec Example:
- // TODO: replace with your own tests (TDD), these are just how-to examples to get you started
- class SolutionTest: XCTestCase {
- static var allTests = [
- ("Test Example", testExample),
- ]
- func testExample() {
let actual = 1XCTAssertEqual(actual, 1)- XCTAssertEqual(gradeCalc(100), "A")
- XCTAssertEqual(gradeCalc(96), "A")
- XCTAssertEqual(gradeCalc(90), "A")
- XCTAssertEqual(gradeCalc(30), "F")
- XCTAssertEqual(gradeCalc(70), "C")
- XCTAssertEqual(gradeCalc(79), "C")
- XCTAssertEqual(gradeCalc(80), "B")
- XCTAssertEqual(gradeCalc(-27), "Not a grade")
- XCTAssertEqual(gradeCalc(127), "Not a grade")
- }
- }
- XCTMain([
- testCase(SolutionTest.allTests)
- ])