Created
August 1, 2019 10:44
-
-
Save geoHeil/4578c82a1c39930aa18f3628ec2d92bb to your computer and use it in GitHub Desktop.
Validate sequence of numbers within allowed range / bounds
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
val valuesRight = Seq(1, 2, 3, 4, 5, 6, 7) | |
val valuesWrong = Seq(1, 2, 5, 6, 7, 8, 9) | |
val allowedValues = Range(1, 8) | |
def containsNotAllowedValues(allowed: Range, input: Seq[Int]): Boolean = { | |
!allowed.containsSlice(input) | |
} | |
containsNotAllowedValues(allowedValues, valuesRight) // expected false as no wrong element contained | |
// result: false ==> correct | |
containsNotAllowedValues(allowedValues, valuesWrong) // expected true as at least single wrong element is contained | |
// result: true ==> correct | |
// ------------------------ | |
val valuesRightPartialMatch = Seq(1,3, 7) | |
containsNotAllowedValues(allowedValues, valuesRightPartialMatch) // expected true as at least single wrong element is contained | |
// result: true ==> incorrect, should also return false as no invalid number is found |
It was my mistake that I did not specify
val valuesRightPartialMatch = Seq(1,3, 7)
initially as well.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
see the discussion at https://stackoverflow.com/questions/57304958/validate-that-sequence-of-numbers-are-within-allowed-range/57305205?noredirect=1#comment101106747_57305205