Skip to content

Commit

Permalink
test: 🚨 add some tests for red_black_tree
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbarsukov committed Oct 13, 2024
1 parent 3e63f33 commit b478225
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions test/red_black_tree_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ defmodule RedBlackTreeTest do
assert 7 == RedBlackTree.get(tree, :e)
assert 4 == RedBlackTree.get(tree, :g)
assert 5 == RedBlackTree.get(tree, :c)
assert 100_500 == RedBlackTree.get(tree, :no_such_key, 100_500)
end

test "delete" do
Expand Down Expand Up @@ -109,8 +110,10 @@ defmodule RedBlackTreeTest do

test "insert and get", %{tree: tree} do
tree = RedBlackTree.insert(tree, :a, 1)
tree = RedBlackTree.insert(tree, :c)
assert RedBlackTree.get(tree, :a) == 1
assert RedBlackTree.get(tree, :b) == nil
assert RedBlackTree.get(tree, :c) == nil
end

test "insert and member?", %{tree: tree} do
Expand All @@ -126,6 +129,14 @@ defmodule RedBlackTreeTest do
assert RedBlackTree.member?(new_tree, :a) == false
end

test "reduce", %{tree: tree} do
assert RedBlackTree.reduce(RedBlackTree.new(), 100, fn el, acc -> el + acc end) == 100

tree = RedBlackTree.insert(tree, :a, 1) |> RedBlackTree.insert(:b, 2)
result = RedBlackTree.reduce(tree, 0, fn {_, v}, acc -> acc + v end)
assert result == 3
end

test "fold_left", %{tree: tree} do
tree = RedBlackTree.insert(tree, :a, 1) |> RedBlackTree.insert(:b, 2)
result = RedBlackTree.fold_left(RedBlackTree.to_list(tree), 0, fn acc, {_, v} -> acc + v end)
Expand Down

0 comments on commit b478225

Please sign in to comment.