Skip to content

Commit 3536370

Browse files
gertvvlunagl
authored andcommitted
Unit test for get_or_default
1 parent 713617b commit 3536370

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

test/glearray_test.gleam

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,25 @@ pub fn get_test() {
4747
|> should.be_error
4848
}
4949

50+
pub fn get_or_default_test() {
51+
let list = [5, 4, 3, 2, 1]
52+
let array = glearray.from_list(list)
53+
list.index_map(list, fn(element, index) {
54+
array
55+
|> glearray.get_or_default(index, -1)
56+
|> should.equal(element)
57+
})
58+
59+
glearray.get_or_default(array, -1, -1)
60+
|> should.equal(-1)
61+
glearray.get_or_default(array, glearray.length(array), 42)
62+
|> should.equal(42)
63+
glearray.get_or_default(array, 100, -1)
64+
|> should.equal(-1)
65+
glearray.get_or_default(glearray.new(), 0, 0)
66+
|> should.equal(0)
67+
}
68+
5069
pub fn set_test() {
5170
let array = glearray.from_list([1, 2, 3, 4])
5271
let assert Ok(modified) = glearray.copy_set(in: array, at: 1, value: 10)

0 commit comments

Comments
 (0)