ac-library-hs-1.2.6.0: Data structures and algorithms
Safe HaskellSafe-Inferred
LanguageGHC2021

AtCoder.Internal.Assert

Description

Runtime assertion utility.

Example

Expand
>>> 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 !_ = checkIndexBounded "AtCoder.Internal.Assert.doctest" 2 1 3
>>> let !_ = checkIndexBounded "AtCoder.Internal.Assert.doctest" (-1) 1 3
*** Exception: AtCoder.Internal.Assert.doctest: given invalid index `-1` over bounds `[1, 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`
...
>>> let !_ = checkIntervalBounded "AtCoder.Internal.Assert.doctest"  2 4 0 5
>>> let !_ = checkIntervalBounded "AtCoder.Internal.Assert.doctest" (-1) 0 0 5
*** Exception: AtCoder.Internal.Assert.doctest: given invalid interval `[-1, 0)` over bounds `[0, 5)`
...
>>> let !_ = checkPoint2d "AtCoder.Internal.Assert.doctest"  1 1 2 2
>>> let !_ = checkPoint2d "AtCoder.Internal.Assert.doctest" 4 4 2 2
*** Exception: AtCoder.Internal.Assert.doctest: given invalid point `(4, 4)` for rectangle `[0, 2) x [0, 2)`
...
>>> let !_ = checkRect "AtCoder.Internal.Assert.doctest"  1 2 1 2 3 3
>>> let !_ = checkRect "AtCoder.Internal.Assert.doctest" 1 2 1 2 1 1
*** Exception: AtCoder.Internal.Assert.doctest: given invalid rectangle `[1, 2) x [1, 2)` for rectangle `[0, 1) x [0, 1)`
...

Since: 1.0.0.0

Synopsis

Runtime assertion

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

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

Since: 1.0.0.0

Tests

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

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

Since: 1.0.0.0

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

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

Since: 1.0.0.0

testIntervalBounded :: Int -> Int -> Int -> Int -> Bool Source #

\(O(1)\) Tests whether \([l, r)\) is a valid interval in \([l_0, r_0)\).

Since: 1.2.1.0

testPoint2d :: HasCallStack => Int -> Int -> Int -> Int -> Bool Source #

\(O(1)\) Tests \((x, y) \in [0, w) \times [0, h)\).

Since: 1.2.3.0

testRect :: HasCallStack => Int -> Int -> Int -> Int -> Int -> Int -> Bool Source #

\(O(1)\) Tests \([x_1, x_2) \times [y_1 y_2) \in [0, w) \times [0, h)\).

Since: 1.2.3.0

testRectShape :: HasCallStack => Int -> Int -> Int -> Int -> Bool Source #

\(O(1)\) Tests \(x_1 \le x_2\) and \(y_1 \le \y_2\).

Since: 1.2.3.0

Index assertions

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

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

Since: 1.0.0.0

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

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

Since: 1.0.0.0

checkIndexBounded :: HasCallStack => String -> Int -> Int -> Int -> () Source #

\(O(1)\) Asserts \(l_0 \leq i \lt r_0\) for an array index \(i\).

Since: 1.2.1.0

errorIndexBounded :: HasCallStack => String -> Int -> Int -> Int -> a Source #

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

Since: 1.2.1.0

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

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

Since: 1.0.0.0

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

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

Since: 1.0.0.0

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

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

Since: 1.0.0.0

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

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

Since: 1.0.0.0

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

\(O(1)\) Asserts index boundary with custom message.

Since: 1.0.0.0

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

\(O(1)\) Emis custom index error.

Since: 1.0.0.0

Interval assertions

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

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

Since: 1.0.0.0

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

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

Since: 1.0.0.0

checkIntervalBounded :: HasCallStack => String -> Int -> Int -> Int -> Int -> () Source #

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

Since: 1.2.1.0

errorIntervalBounded :: HasCallStack => String -> Int -> Int -> Int -> Int -> a Source #

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

Since: 1.2.1.0

Two-dimensional index assertions

checkPoint2d :: HasCallStack => String -> Int -> Int -> Int -> Int -> () Source #

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

Since: 1.2.3.0

errorPoint2d :: HasCallStack => String -> Int -> Int -> Int -> Int -> a Source #

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

Since: 1.2.3.0

checkRect :: HasCallStack => String -> Int -> Int -> Int -> Int -> Int -> Int -> () Source #

\(O(1)\) Asserts \([x_1, x_2) \times [y_1 y_2) \in [0, w) \times [0, h)\).

Since: 1.2.3.0

errorRect :: HasCallStack => String -> Int -> Int -> Int -> Int -> Int -> Int -> a Source #

\(O(1)\) Asserts rectangle boundary error.

Since: 1.2.3.0

checkRectShape :: HasCallStack => String -> Int -> Int -> Int -> Int -> () Source #

\(O(1)\) Asserts \(x_1 \le x_2\) and \(y_1 \le \y_2\).

Since: 1.2.3.0

errorRectShape :: HasCallStack => String -> Int -> Int -> Int -> Int -> a Source #

\(O(1)\) Asserts rectangle boundary error.

Since: 1.2.3.0