Commit d45db321 authored by Duncan Coutts's avatar Duncan Coutts
Browse files

Add checking of Version validity to the VersionIntervals invariant

Version numbers have to be a non-empty sequence of non-negataive ints.
parent 4f9b6073
......@@ -322,7 +322,7 @@ instance Ord UpperBound where
GT -> False
invariant :: VersionIntervals -> Bool
invariant (VersionIntervals intervals) = all nonEmpty intervals
invariant (VersionIntervals intervals) = all validInterval intervals
&& all doesNotTouch' adjacentIntervals
where
doesNotTouch' :: (VersionInterval, VersionInterval) -> Bool
......@@ -347,6 +347,17 @@ mkVersionIntervals intervals
| invariant (VersionIntervals intervals) = Just (VersionIntervals intervals)
| otherwise = Nothing
validVersion :: Version -> Bool
validVersion (Version [] _) = False
validVersion (Version vs _) = all (>=0) vs
validInterval i@(l, u) = validLower l && validUpper u && nonEmpty i
where
validLower NoLowerBound = True
validLower (LowerBound v _) = validVersion v
validUpper NoUpperBound = True
validUpper (UpperBound v _) = validVersion v
-- Check an interval is non-empty
--
nonEmpty :: VersionInterval -> Bool
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment