ac-library-hs-1.0.0.0: Data structures and algorithms
Safe HaskellNone
LanguageGHC2021

AtCoder.Internal.Assert

Description

Runtime assertion utility.

Example

>>> let !_ = runtimeAssert False "errorMessage"
*** Exception: errorMessage
...
>>> let !_ = checkIndex "AtCoder.Internal.Assert.doctest" 0 3
>>> let !_ = checkIndex "AtCoder.Internal.Assert.doctest" (-1) 3
*** Exception: AtCoder.Internal.Assert.doctest: given invalid index `-1` over length `3`
...
>>> let !_ = checkVertex "AtCoder.Internal.Assert.doctest" 0 3
>>> let !_ = checkVertex "AtCoder.Internal.Assert.doctest" (-1) 3
*** Exception: AtCoder.Internal.Assert.doctest: given invalid vertex `-1` over the number of vertices `3`
...
>>> let !_ = checkEdge "AtCoder.Internal.Assert.doctest" 0 3
>>> let !_ = checkEdge "AtCoder.Internal.Assert.doctest" (-1) 3
*** Exception: AtCoder.Internal.Assert.doctest: given invalid edge index `-1` over the number of edges `3`
...
>>> let !_ = checkCustom "AtCoder.Internal.Assert.doctest" "index" 0 "set" 3
>>> let !_ = checkCustom "AtCoder.Internal.Assert.doctest" "index" (-1) "set" 3
*** Exception: AtCoder.Internal.Assert.doctest: given invalid index `-1` over set `3`
...
>>> let !_ = checkInterval "AtCoder.Internal.Assert.doctest" 0 3 3
>>> let !_ = checkInterval "AtCoder.Internal.Assert.doctest" 0 4 3
*** Exception: AtCoder.Internal.Assert.doctest: given invalid interval `[0, 4)` over length `3`
...

Since: 1.0.0

Synopsis

Runtime assertion

runtimeAssert :: HasCallStack => Bool -> String -> () #

\(O(1)\) Assertion that is never erased at compile time.

Since: 1.0.0

Tests

testIndex :: HasCallStack => Int -> Int -> Bool #

\(O(1)\) Tests \(i \in [0, n)\).

Since: 1.0.0

testInterval :: Int -> Int -> Int -> Bool #

\(O(1)\) Tests weather \([l, r)\) is a valid interval in \([0, n)\).

Since: 1.0.0

Index assertions

checkIndex :: HasCallStack => String -> Int -> Int -> () #

\(O(1)\) Asserts \(0 \leq i \lt n\) for an array index \(i\).

Since: 1.0.0

errorIndex :: HasCallStack => String -> Int -> Int -> a #

\(O(1)\) Emits index boundary error.

Since: 1.0.0

checkVertex :: HasCallStack => String -> Int -> Int -> () #

\(O(1)\) Asserts \(0 \leq i \lt n\) for a graph vertex \(i\).

Since: 1.0.0

errorVertex :: HasCallStack => String -> Int -> Int -> a #

\(O(1)\) Asserts \(0 \leq i \lt n\) for a graph vertex \(i\).

Since: 1.0.0

checkEdge :: HasCallStack => String -> Int -> Int -> () #

\(O(1)\) Asserts \(0 \leq i \lt m\) for an edge index \(i\).

Since: 1.0.0

errorEdge :: HasCallStack => String -> Int -> Int -> a #

\(O(1)\) Asserts \(0 \leq i \lt m\) for an edge index \(i\).

Since: 1.0.0

checkCustom :: HasCallStack => String -> String -> Int -> String -> Int -> () #

\(O(1)\) Asserts \(0 \leq i \lt m\) for an edge index \(i\).

Since: 1.0.0

errorCustom :: HasCallStack => String -> String -> Int -> String -> Int -> a #

\(O(1)\) Asserts \(0 \leq i \lt m\) for an edge index \(i\).

Since: 1.0.0

Interval assertion

checkInterval :: HasCallStack => String -> Int -> Int -> Int -> () #

\(O(1)\) Asserts \(0 \leq l \leq r \leq n\) for a half-open interval \([l, r)\).

Since: 1.0.0

errorInterval :: HasCallStack => String -> Int -> Int -> Int -> a #

\(O(1)\) Asserts \(0 \leq l \leq r \leq n\) for a half-open interval \([l, r)\).

Since: 1.0.0