Skip to content

Commit

Permalink
Merge branch 'release/0.0.4.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
ruimaciel committed Apr 12, 2020
2 parents c62ae69 + 9379614 commit 9900b04
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.1)

project(mropes
VERSION 0.0.4.0
VERSION 0.0.4.1
LANGUAGES C
)

Expand Down
4 changes: 2 additions & 2 deletions src/rope_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct mrope_branch_node *mrope_make_branch_node(struct mrope_node *lhs, struct
return node;
}

struct mrope_leaf_node * mrope_make_leaf_node()
struct mrope_leaf_node * mrope_make_leaf_node(void)
{
struct mrope_leaf_node * node = NULL;

Expand Down Expand Up @@ -248,7 +248,7 @@ char mrope_index_branch_node(struct mrope_branch_node *branch_node, const size_t
}

if(index < lhs_weight + branch_node->right->weight) {
return mrope_index_node( (struct mrope_node *) branch_node->right, lhs_weight + index);
return mrope_index_node( (struct mrope_node *) branch_node->right, index - lhs_weight );
}

return '\0';
Expand Down
2 changes: 1 addition & 1 deletion src/rope_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ void mrope_init_branch_node(struct mrope_branch_node *node, struct mrope_node *l
void mrope_init_leaf_node(struct mrope_leaf_node * node, char * text, const size_t length);

struct mrope_branch_node * mrope_make_branch_node(struct mrope_node *lhs, struct mrope_node *rhs);
struct mrope_leaf_node * mrope_make_leaf_node();
struct mrope_leaf_node * mrope_make_leaf_node(void);

enum mrope_error_code mrope_free_branch_node(struct mrope_branch_node * node);
enum mrope_error_code mrope_free_leaf_node(struct mrope_leaf_node * node);
Expand Down
1 change: 0 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ find_package(Threads REQUIRED)
find_package(check REQUIRED)
find_package(subunit REQUIRED)

message("")

include_directories(${PROJECT_SOURCE_DIR})

Expand Down
23 changes: 23 additions & 0 deletions tests/check_mropes_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,28 @@ START_TEST(test_rope_prepend_rope)
}
END_TEST

START_TEST(test_rope_When_prepend_rope_Then_length_is_equal_to_the_sum_of_both_ropes)
{
/* Given */
mrope_t rope_lhs;
mrope_init(&rope_lhs);
mrope_append_text(&rope_lhs, "foo");
const size_t lhs_size = mrope_length(&rope_lhs);

mrope_t rope_rhs;
mrope_init(&rope_rhs);
mrope_append_text(&rope_rhs, "bar");
const size_t rhs_size = mrope_length(&rope_rhs);

/* When */
mrope_prepend_rope(&rope_lhs, &rope_rhs);

/* Then */
size_t size = mrope_length(&rope_lhs);
ck_assert_int_eq(size, lhs_size+rhs_size);
}
END_TEST


START_TEST(test_rope_append_text)
{
Expand Down Expand Up @@ -230,6 +252,7 @@ Suite * mropes_suite(void)

tcase_add_test(tc_core, test_rope_init);
tcase_add_test(tc_core, test_rope_when_prepend_rope_then_lhs_is_null);
tcase_add_test(tc_core, test_rope_When_prepend_rope_Then_length_is_equal_to_the_sum_of_both_ropes);
tcase_add_test(tc_core, test_rope_prepend_rope);
tcase_add_test(tc_core, test_rope_append_text);
tcase_add_test(tc_core, test_rope_append_rope);
Expand Down
2 changes: 2 additions & 0 deletions tests/check_mropes_core_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ Suite * mropes_suite(void)
tcase_add_test(tc_core, test_Given_null_lhs_and_nonnull_rhs_When_make_branch_node_Then_rhs_is_null);
tcase_add_test(tc_core, test_mrope_split_leaf_node_Shall_return_lhs_with_index_length);
tcase_add_test(tc_core, test_mrope_split_leaf_node_Shall_return_rhs_with_index_length);
tcase_add_test(tc_core, test_mrope_split_leaf_node_Shall_return_rhs_with_first_index);
tcase_add_test(tc_core, test_rope_index_branch_node);
tcase_add_test(tc_core, test_rope_make_leaf_node);
tcase_add_test(tc_core, test_rope_make_leaf_node_from_text);
tcase_add_test(tc_core, test_rope_make_leaf_node_from_text_SHALL_own_text);
Expand Down

0 comments on commit 9900b04

Please sign in to comment.