Skip to content

Instantly share code, notes, and snippets.

@SURYAKANTSHARMA
Created May 3, 2019 17:32
Show Gist options
  • Save SURYAKANTSHARMA/b866cd152fb1675a5e37068ed75fff73 to your computer and use it in GitHub Desktop.
Save SURYAKANTSHARMA/b866cd152fb1675a5e37068ed75fff73 to your computer and use it in GitHub Desktop.
Appraisal
typealias Amount = Float
struct User {
let name: String
let salary: Amount
}
enum PerformanceRating {
enum Result {
case warning(letter: String)
case bonus(amount: Amount)
}
case superExceptional
case exceptional
case exceedExpection
case meetExpection
case partlyMeetExpection
case needImprovement
var bonusPercentage: Float {
switch self {
case .superExceptional:
return 2
case .exceptional:
return 1.5
case .exceedExpection:
return 1
case .meetExpection:
return 0.5
case .partlyMeetExpection, .needImprovement:
return 0
}
}
func giveResult(user: User) -> Result {
switch self {
case .superExceptional, .exceptional, .exceedExpection, .meetExpection:
return Result.bonus(amount: bonusPercentage * user.salary)
case .partlyMeetExpection:
return Result.warning(letter: "Partly Meet expectation")
case .needImprovement:
return Result.warning(letter: "Need Improvement")
}
}
}
struct Appraisal {
let user: User
let rating: PerformanceRating
func perform() -> PerformanceRating.Result {
return rating.giveResult(user: user)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment