Added assertion to clamp (#17248)
Co-authored-by: flywind <xzsflywind@gmail.com>
This commit is contained in:
parent
81889fb84c
commit
f28dc2c61e
2 changed files with 7 additions and 2 deletions
|
|
@ -1190,6 +1190,8 @@ func clamp*[T](val: T, bounds: Slice[T]): T {.since: (1, 5), inline.} =
|
|||
type A = enum a0, a1, a2, a3, a4, a5
|
||||
assert a1.clamp(a2..a4) == a2
|
||||
assert clamp((3, 0), (1, 0) .. (2, 9)) == (2, 9)
|
||||
doAssertRaises(AssertionDefect): discard clamp(1, 3..2) # invalid bounds
|
||||
assert bounds.a <= bounds.b, $(bounds.a, bounds.b)
|
||||
clamp(val, bounds.a, bounds.b)
|
||||
|
||||
func lcm*[T](x: openArray[T]): T {.since: (1, 1).} =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue