Skip to content

Commit 37385bb

Browse files
authored
Merge pull request #1624 from bengesoff/add-min-spell
spell: add `min` alongside existing `max`
2 parents 710375f + e965e0b commit 37385bb

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

examples/spells/basicSpells.qnt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,23 @@ module basicSpells {
5050
assert(max(-5, -3) == -3),
5151
}
5252

53+
/// Compute the minimum of two integers.
54+
///
55+
/// - @param i first integer
56+
/// - @param j second integer
57+
/// - @returns the minimum of i and j
58+
pure def min(i: int, j: int): int = {
59+
if (i < j) i else j
60+
}
61+
62+
run minTest = all {
63+
assert(min(3, 4) == 3),
64+
assert(min(6, 3) == 3),
65+
assert(min(10, 10) == 10),
66+
assert(min(-3, -5) == -5),
67+
assert(min(-5, -3) == -5),
68+
}
69+
5370
/// Compute the absolute value of an integer
5471
///
5572
/// - @param i : an integer whose absolute value we are interested in

0 commit comments

Comments
 (0)