-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6f1303c
commit 87bd77a
Showing
8 changed files
with
379 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import gleam/int | ||
import gleamy/pairing_heap as heap | ||
import gleeunit/should | ||
|
||
pub fn find_test() { | ||
let heap = heap.new(int.compare) | ||
|
||
heap.find_min(heap) | ||
|> should.equal(Error(Nil)) | ||
|
||
let heap = heap.insert(heap, 3) | ||
|
||
heap.find_min(heap) | ||
|> should.equal(Ok(3)) | ||
|
||
let heap = heap.insert(heap, 1) | ||
|
||
heap.find_min(heap) | ||
|> should.equal(Ok(1)) | ||
|
||
let heap = heap.insert(heap, 4) | ||
|
||
heap.find_min(heap) | ||
|> should.equal(Ok(1)) | ||
} | ||
|
||
pub fn delete_test() { | ||
let heap = | ||
heap.new(int.compare) | ||
|> heap.insert(3) | ||
|> heap.insert(1) | ||
|> heap.insert(4) | ||
|> heap.insert(1) | ||
|> heap.insert(5) | ||
|
||
let assert Ok(#(x, heap)) = heap.delete_min(heap) | ||
should.equal(x, 1) | ||
|
||
let assert Ok(#(x, heap)) = heap.delete_min(heap) | ||
should.equal(x, 1) | ||
|
||
let assert Ok(#(x, heap)) = heap.delete_min(heap) | ||
should.equal(x, 3) | ||
|
||
let assert Ok(#(x, heap)) = heap.delete_min(heap) | ||
should.equal(x, 4) | ||
|
||
let assert Ok(#(x, heap)) = heap.delete_min(heap) | ||
should.equal(x, 5) | ||
|
||
heap.delete_min(heap) | ||
|> should.equal(Error(Nil)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import gleam/int | ||
import gleamy/leftist_heap as heap | ||
import gleeunit/should | ||
|
||
pub fn find_test() { | ||
let heap = heap.new(int.compare) | ||
|
||
heap.find_min(heap) | ||
|> should.equal(Error(Nil)) | ||
|
||
let heap = heap.insert(heap, 3) | ||
|
||
heap.find_min(heap) | ||
|> should.equal(Ok(3)) | ||
|
||
let heap = heap.insert(heap, 1) | ||
|
||
heap.find_min(heap) | ||
|> should.equal(Ok(1)) | ||
|
||
let heap = heap.insert(heap, 4) | ||
|
||
heap.find_min(heap) | ||
|> should.equal(Ok(1)) | ||
} | ||
|
||
pub fn delete_test() { | ||
let heap = | ||
heap.new(int.compare) | ||
|> heap.insert(3) | ||
|> heap.insert(1) | ||
|> heap.insert(4) | ||
|> heap.insert(1) | ||
|> heap.insert(5) | ||
|
||
let assert Ok(#(x, heap)) = heap.delete_min(heap) | ||
should.equal(x, 1) | ||
|
||
let assert Ok(#(x, heap)) = heap.delete_min(heap) | ||
should.equal(x, 1) | ||
|
||
let assert Ok(#(x, heap)) = heap.delete_min(heap) | ||
should.equal(x, 3) | ||
|
||
let assert Ok(#(x, heap)) = heap.delete_min(heap) | ||
should.equal(x, 4) | ||
|
||
let assert Ok(#(x, heap)) = heap.delete_min(heap) | ||
should.equal(x, 5) | ||
|
||
heap.delete_min(heap) | ||
|> should.equal(Error(Nil)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import gleam/string | ||
import gleamy/red_black_tree_map as map | ||
import gleeunit/should | ||
|
||
pub fn insert_and_find_test() { | ||
let map = map.new(string.compare) | ||
let updated_map = | ||
map | ||
|> map.insert("key1", "value1") | ||
|> map.insert("key2", "value2") | ||
|
||
updated_map | ||
|> map.find("key1") | ||
|> should.equal(Ok(#("key1", "value1"))) | ||
|
||
updated_map | ||
|> map.find("key2") | ||
|> should.equal(Ok(#("key2", "value2"))) | ||
} | ||
|
||
pub fn delete_test() { | ||
let map = | ||
map.new(string.compare) | ||
|> map.insert("key1", "value1") | ||
|> map.insert("key2", "value2") | ||
|
||
let updated_map = | ||
map | ||
|> map.delete("key1") | ||
|
||
updated_map | ||
|> map.find("key1") | ||
|> should.equal(Error(Nil)) | ||
|
||
updated_map | ||
|> map.find("key2") | ||
|> should.equal(Ok(#("key2", "value2"))) | ||
} | ||
|
||
pub fn fold_test() { | ||
let map = | ||
map.new(string.compare) | ||
|> map.insert("key1", "value1") | ||
|> map.insert("key2", "value2") | ||
|> map.insert("key3", "value3") | ||
|
||
let result = | ||
map | ||
|> map.fold(0, fn(a, _, _) { a + 1 }) | ||
|
||
result | ||
|> should.equal(3) | ||
} | ||
|
||
pub fn missing_keys_test() { | ||
let map = | ||
map.new(string.compare) | ||
|> map.insert("key1", "value1") | ||
|> map.insert("key2", "value2") | ||
|
||
map | ||
|> map.find("key3") | ||
|> should.equal(Error(Nil)) | ||
|
||
let updated_map = | ||
map | ||
|> map.delete("key3") | ||
|
||
updated_map | ||
|> map.find("key3") | ||
|> should.equal(Error(Nil)) | ||
} |
Oops, something went wrong.