ac-library-hs-1.4.0.0: Data structures and algorithms
Safe HaskellNone
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 Source #

Arguments

:: HasCallStack 
=> Int

\(i\)

-> Int

\(n\)

-> Bool

\(0 \le i \lt n\)

\(O(1)\) Tests \(0 \le i \lt n\).

Since: 1.0.0.0

testInterval Source #

Arguments

:: Int

\(l\)

-> Int

\(r\)

-> Int

\(n\)

-> Bool

\(0 \le l \le r \le n\).

\(O(1)\) Tests \(0 \le l \le r \le n\).

Since: 1.0.0.0

testIntervalBounded Source #

Arguments

:: Int

\(l\)

-> Int

\(r\)

-> Int

\(l_0\)

-> Int

\(r_0\)

-> Bool

\(l_0 \le l \le r \le r_0\)

\(O(1)\) Tests \(l_0 \le l \le r \le r_0\).

Since: 1.2.1.0

testPoint2d Source #

Arguments

:: HasCallStack 
=> Int

\(x\)

-> Int

\(y\)

-> Int

\(w\)

-> Int

\(h\)

-> Bool

\((x, y) \in [0, w) \times [0, h)\)

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

Since: 1.2.3.0

testRect Source #

Arguments

:: HasCallStack 
=> Int

\(x_1\)

-> Int

\(x_2\)

-> Int

\(y_1\)

-> Int

\(y_2\)

-> Int

\(w\)

-> Int

\(h\)

-> Bool

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

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

Since: 1.2.3.0

testRectShape Source #

Arguments

:: HasCallStack 
=> Int

\(x_1\)

-> Int

\(x_2\)

-> Int

\(y_1\)

-> Int

\(y_2\)

-> Bool

\(x_1 \le x_2 \land y_1 \le \y_2\).

\(O(1)\) Tests \(x_1 \le x_2 \land 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