re: Daily Challenge #68 - Grade Book VIEW POST

FULL DISCUSSION
 

Elm

module GradeBook exposing (gradeBook)


computeGradeSign : Int -> String
computeGradeSign mean =
    case compare (modBy 10 mean) 5 of
        EQ ->
            ""

        LT ->
            "-"

        GT ->
            "+"


gradeBook : Int -> Int -> Int -> String
gradeBook grade1 grade2 grade3 =
    let
        mean =
            toFloat (grade1 + grade2 + grade3) / 3

        gradeSign =
            computeGradeSign <| round mean
    in
    if mean < 60 then
        "F" ++ gradeSign

    else if mean < 70 then
        "D" ++ gradeSign

    else if mean < 80 then
        "C" ++ gradeSign

    else if mean < 90 then
        "B" ++ gradeSign

    else
        "A" ++ gradeSign

Tests

module GradeBookTest exposing (suite)

import Expect
import GradeBook exposing (gradeBook)
import Test exposing (Test)


suite : Test
suite =
    Test.describe "Grade Book"
        [ Test.test "It should return C- when passing 64, 55 & 92" <|
            \_ ->
                Expect.equal "C-" <| gradeBook 64 55 92
        , Test.test "It should return A- when passing 99, 89 & 93" <|
            \_ ->
                Expect.equal "A-" <| gradeBook 99 89 93
        , Test.test "It should return C+ when passing 33, 99 & 95" <|
            \_ ->
                Expect.equal "C+" <| gradeBook 33 99 95
        , Test.test "It should return C when passing 64, 70 & 92" <|
            \_ ->
                Expect.equal "C" <| gradeBook 64 70 92
        ]
code of conduct - report abuse