Skip to content

Commit

Permalink
fix congig.json and binary-search-tree tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Emmanuel Delaborde committed Oct 10, 2019
2 parents 63c61b1 + 73ac5d1 commit 713ec86
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 77 deletions.
7 changes: 7 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,7 @@
]
},
{
<<<<<<< HEAD
"slug": "simple-linked-list",
"uuid": "56a794de-40ee-4ff2-a1dd-f9b83f62d4b0",
"core": false,
Expand All @@ -847,6 +848,12 @@
"uuid": "a8f7f17e-567b-43ec-9ee5-6288367f0ae4",
"core": false,
"unlocked_by": "strain",
=======
"slug": "binary-search-tree",
"uuid": "a8f7f17e-567b-43ec-9ee5-6288367f0ae4",
"core": false,
"unlocked_by": null,
>>>>>>> 73ac5d1407a84e06c0c22ff31748d06aa74d3c99
"difficulty": 3,
"topics": [
"recursion",
Expand Down
161 changes: 84 additions & 77 deletions exercises/binary-search-tree/test/binary_search_tree_tests.erl
Original file line number Diff line number Diff line change
@@ -1,101 +1,108 @@
-module(binary_search_tree_tests).

-include_lib("erl_exercism/include/exercism.hrl").

-include_lib("eunit/include/eunit.hrl").

'1_data_is_retained_test'() ->
T =
binary_search_tree:insert(binary_search_tree:empty(),
4),
?assertMatch(4, (binary_search_tree:value(T))).
T = binary_search_tree:insert(binary_search_tree:empty(), 4),
?assertMatch(4, binary_search_tree:value(T)).

'2_smaller_number_at_left_node_test'() ->
T =
binary_search_tree:insert(binary_search_tree:insert(binary_search_tree:empty(),
4),
2),
?assertMatch(4, (binary_search_tree:value(T))),
?assertMatch(2,
(binary_search_tree:value(binary_search_tree:left(T)))).
T = binary_search_tree:insert(
binary_search_tree:insert(
binary_search_tree:empty(), 4),
2),
?assertMatch(4, binary_search_tree:value(T)),
?assertMatch(2, binary_search_tree:value(binary_search_tree:left(T))).

'3_same number_at_left_node_test'() ->
T =
binary_search_tree:insert(binary_search_tree:insert(binary_search_tree:empty(),
4),
4),
?assertMatch(4, (binary_search_tree:value(T))),
?assertMatch(4,
(binary_search_tree:value(binary_search_tree:left(T)))).
T = binary_search_tree:insert(
binary_search_tree:insert(
binary_search_tree:empty(), 4),
4),
?assertMatch(4, binary_search_tree:value(T)),
?assertMatch(4, binary_search_tree:value(binary_search_tree:left(T))).

'4_greater_number_at_right_node_test'() ->
T =
binary_search_tree:insert(binary_search_tree:insert(binary_search_tree:empty(),
4),
5),
?assertMatch(4, (binary_search_tree:value(T))),
?assertMatch(5,
(binary_search_tree:value(binary_search_tree:right(T)))).
T = binary_search_tree:insert(
binary_search_tree:insert(
binary_search_tree:empty(), 4),
5),
?assertMatch(4, binary_search_tree:value(T)),
?assertMatch(5, binary_search_tree:value(binary_search_tree:right(T))).

'5_can_create_complex_tree_test'() ->
T =
binary_search_tree:insert(binary_search_tree:insert(binary_search_tree:insert(binary_search_tree:insert(binary_search_tree:insert(binary_search_tree:insert(binary_search_tree:insert(binary_search_tree:empty(),
4),
2),
6),
1),
3),
5),
7),
?assertMatch(4, (binary_search_tree:value(T))),
?assertMatch(2,
(binary_search_tree:value(binary_search_tree:left(T)))),
?assertMatch(1,
(binary_search_tree:value(binary_search_tree:left(binary_search_tree:left(T))))),
?assertMatch(3,
(binary_search_tree:value(binary_search_tree:right(binary_search_tree:left(T))))),
?assertMatch(6,
(binary_search_tree:value(binary_search_tree:right(T)))),
?assertMatch(5,
(binary_search_tree:value(binary_search_tree:left(binary_search_tree:right(T))))),
?assertMatch(7,
(binary_search_tree:value(binary_search_tree:right(binary_search_tree:right(T))))).
T = binary_search_tree:insert(
binary_search_tree:insert(
binary_search_tree:insert(
binary_search_tree:insert(
binary_search_tree:insert(
binary_search_tree:insert(
binary_search_tree:insert(
binary_search_tree:empty(),
4),
2),
6),
1),
3),
5),
7),
?assertMatch(4, binary_search_tree:value(T)),
?assertMatch(2, binary_search_tree:value(binary_search_tree:left(T))),
?assertMatch(1, binary_search_tree:value(
binary_search_tree:left(
binary_search_tree:left(T)))),
?assertMatch(3, binary_search_tree:value(
binary_search_tree:right(
binary_search_tree:left(T)))),
?assertMatch(6, binary_search_tree:value(binary_search_tree:right(T))),
?assertMatch(5, binary_search_tree:value(
binary_search_tree:left(
binary_search_tree:right(T)))),
?assertMatch(7, binary_search_tree:value(
binary_search_tree:right(
binary_search_tree:right(T)))).

'6_can_sort_single_number_test'() ->
T =
binary_search_tree:insert(binary_search_tree:empty(),
2),
?assertMatch([2], (binary_search_tree:to_list(T))).
T = binary_search_tree:insert(binary_search_tree:empty(), 2),
?assertMatch([2], binary_search_tree:to_list(T)).

'7_can_sort_if_second_number_is_smaller_than_first_test'() ->
T =
binary_search_tree:insert(binary_search_tree:insert(binary_search_tree:empty(),
2),
1),
?assertMatch([1, 2], (binary_search_tree:to_list(T))).
T = binary_search_tree:insert(
binary_search_tree:insert(
binary_search_tree:empty(),
2),
1),
?assertMatch([1, 2], binary_search_tree:to_list(T)).

'8_can_sort_if_second_number_is_same_as_first_test'() ->
T =
binary_search_tree:insert(binary_search_tree:insert(binary_search_tree:empty(),
2),
2),
?assertMatch([2, 2], (binary_search_tree:to_list(T))).
T = binary_search_tree:insert(
binary_search_tree:insert(
binary_search_tree:empty(),
2),
2),
?assertMatch([2, 2], binary_search_tree:to_list(T)).

'9_can_sort_if_second_number_is_greater_than_first_test'() ->
T =
binary_search_tree:insert(binary_search_tree:insert(binary_search_tree:empty(),
2),
3),
?assertMatch([2, 3], (binary_search_tree:to_list(T))).
T = binary_search_tree:insert(
binary_search_tree:insert(
binary_search_tree:empty(),
2),
3),
?assertMatch([2, 3], binary_search_tree:to_list(T)).

'10_can_sort_complex_tree_test'() ->
T =
binary_search_tree:insert(binary_search_tree:insert(binary_search_tree:insert(binary_search_tree:insert(binary_search_tree:insert(binary_search_tree:insert(binary_search_tree:empty(),
2),
1),
3),
6),
7),
5),
?assertMatch([1, 2, 3, 5, 6, 7],
(binary_search_tree:to_list(T))).
T = binary_search_tree:insert(
binary_search_tree:insert(
binary_search_tree:insert(
binary_search_tree:insert(
binary_search_tree:insert(
binary_search_tree:insert(
binary_search_tree:empty(),
2),
1),
3),
6),
7),
5),
?assertMatch([1, 2, 3, 5, 6, 7], binary_search_tree:to_list(T)).

0 comments on commit 713ec86

Please sign in to comment.