Last active
November 26, 2020 09:41
-
-
Save kryptt/bcd9c654aa5ae3c8c8a6d3139365a5f7 to your computer and use it in GitHub Desktop.
validation-examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object ModelXValidation { | |
def validateMotor(motor: Motor): Boolean = | |
motor.engine.fold(validateElecticEngine, validateCombustionEngine) | |
def validateElectricEngine(engine: ElectricEngine): Boolean = engine match { | |
case eh:HybridElectricEngine => false | |
case ElectricEngine(coils) => expectedCoils.contains(coils) | |
} | |
def validateCombustionEngine(engine: CombustionEngine): Boolean = false | |
val expectedCoils = Array(`1500Coils`, `1800Coils`) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object ModelXValidation2 { | |
def validateMotor(motor: Motor2): Boolean = { | |
if (motor.electricEngine.isEmpty && motor.combustionEngine.isEmpty) | |
false | |
else if (motor.combustionEngine.isDefined) | |
false | |
else | |
motor.electricEngine match { | |
Some(HybridElectricEngine(_, _)) => false | |
Some(ElectricEngine(coils)) => expectedCoils.contains(coils) | |
_ => false | |
} | |
} | |
val expectedCoils = Array(`1500Coils`, `1800Coils`) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment