Skip to content

Commit

Permalink
Fix test cases
Browse files Browse the repository at this point in the history
Merge branch 'fix-test' into 'develop'

See merge request persper/code-analytics!88
  • Loading branch information
hezyin committed May 26, 2019
2 parents b07b68f + a834459 commit 36c1571
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 22 deletions.
52 changes: 52 additions & 0 deletions test/test_analytics/patch_test_files/example7_new.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* added in H */
struct node
{
int data;
struct node *next;
}*head;

/* added in H, edited in I */
void append(int num)
{
struct node *temp, *prev;
temp=head;
while(temp!=NULL)
{
if(temp->data==num)
{
if(temp==head)
{
head=temp->next;
free(temp);
return 1;
}
else
{
prev->next=temp->next;
free(temp);
return 1;
}
}
else
{
prev=temp;
temp= temp->next;
}
}
return 0;
}

/* added in H, edited in G */
void add( int num )
{
struct node *temp;
temp=(struct node *)malloc(sizeof(struct node));
temp->data=num;
if (head== NULL)
{
head=temp;
head->next=NULL;
}
}

/* insert() is deleted in I */
65 changes: 65 additions & 0 deletions test/test_analytics/patch_test_files/example7_old.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* added in H */
struct node
{
int data;
struct node *next;
}*head;

/* added in H */
void append(int num)
{
struct node *temp,*right;
temp= (struct node *)malloc(sizeof(struct node));
temp->data=num;
right=(struct node *)head;
while(right->next != NULL)
right=right->next;
right->next =temp;
right=temp;
right->next=NULL;
}

/* added in H */
void add( int num )
{
struct node *temp;
temp=(struct node *)malloc(sizeof(struct node));
temp->data=num;
if (head== NULL)
{
head=temp;
head->next=NULL;
}
else
{
temp->next=head;
head=temp;
}
}

/* added in H */
void insert(int num)
{
int c=0;
struct node *temp;
temp=head;
if(temp==NULL)
{
add(num);
}
else
{
while(temp!=NULL)
{
if(temp->data<num)
c++;
temp=temp->next;
}
if(c==0)
add(num);
else if(c<count())
addafter(num,++c);
else
append(num);
}
}
27 changes: 14 additions & 13 deletions test/test_analytics/test_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,39 +32,40 @@ async def test_analyzer_master_only(az):

history_truth = {
'K': {
'display': {'adds': 0, 'dels': 5}
'display': {'adds': 0, 'dels': 5, 'added_units': 0, 'removed_units': 10}
},
'F': {
'display': {'adds': 14, 'dels': 0},
'count': {'adds': 12, 'dels': 0}
'display': {'adds': 14, 'dels': 0, 'added_units': 23, 'removed_units': 0},
'count': {'adds': 12, 'dels': 0, 'added_units': 19, 'removed_units': 0}
},
'E': {
'append': {'adds': 29, 'dels': 0},
'add': {'adds': 11, 'dels': 0}
'append': {'adds': 29, 'dels': 0, 'added_units': 44, 'removed_units': 0},
'add': {'adds': 11, 'dels': 0, 'added_units': 25, 'removed_units': 0}
},
'D': {
'str_replace': {'adds': 26, 'dels': 0}
'str_replace': {'adds': 26, 'dels': 0, 'added_units': 76, 'removed_units': 0}
},
# TODO: fix \No newline at the end of file
'C': {
'str_append_chr': {'adds': 30, 'dels': 4},
'str_equals': {'adds': 0, 'dels': 1}
'str_append_chr': {'adds': 30, 'dels': 4, 'added_units': 78, 'removed_units': 21},
'str_equals': {'adds': 0, 'dels': 1, 'added_units': 0, 'removed_units': 0}
},
# Commit `B` is an example of imperfect diff,
# it removes `str_append` and adds a new function `str_append_chr`
# but because they are too similar,
# diff doesn't separate these changes into two chunks
# please see here: https://github.com/UltimateBeaver/test_feature_branch/commit/caaac10f604ea7ac759c2147df8fb2b588ee2a27
'B': {
'str_append': {'adds': 6, 'dels': 3},
'str_append_chr': {'adds': 3, 'dels': 2},
'str_equals': {'adds': 11, 'dels': 0}
'str_append': {'adds': 6, 'dels': 3, 'added_units': 29, 'removed_units': 21},
'str_append_chr': {'adds': 3, 'dels': 2, 'added_units': 21, 'removed_units': 15},
'str_equals': {'adds': 11, 'dels': 0, 'added_units': 27, 'removed_units': 0}
},
'A': {
'str_append': {'adds': 7, 'dels': 0},
'str_len': {'adds': 6, 'dels': 0}
'str_append': {'adds': 7, 'dels': 0, 'added_units': 29, 'removed_units': 0},
'str_len': {'adds': 6, 'dels': 0, 'added_units': 13, 'removed_units': 0}
},


# # branch J from commit A, merge back through F
# 'J': {
# 'count': {'adds': 12, 'dels': 0},
Expand Down
8 changes: 4 additions & 4 deletions test/test_analytics/test_analyzer_cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ async def test_analyzer_files(az):

history_truth = {
'C': {
'printmessage': {'adds': 4, 'dels': 0},
'main': {'adds': 4, 'dels': 0}
'printmessage': {'adds': 4, 'dels': 0, 'added_units': 7, 'removed_units': 0},
'main': {'adds': 4, 'dels': 0, 'added_units': 3, 'removed_units': 0}
},
'B': {},
'A': {
'addition': {'adds': 6, 'dels': 0},
'main': {'adds': 6, 'dels': 0}
'addition': {'adds': 6, 'dels': 0, 'added_units': 13, 'removed_units': 0},
'main': {'adds': 6, 'dels': 0, 'added_units': 13, 'removed_units': 0}
},
}

Expand Down
22 changes: 17 additions & 5 deletions test/test_analytics/test_detect_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_detect_change():
assert func_ranges_result == func_ranges_truth

assert changed_result == get_changed_functions(
*func_ranges_result, *parsing_result)
*func_ranges_result, *parsing_result, None, None)


def test_get_changed_functions():
Expand All @@ -64,23 +64,35 @@ def test_get_changed_functions():
example_patch = f.read()
parsing_result = parser.parse(example_patch)

old_src, new_src = '', ''
with open(os.path.join(dir_path, 'patch_test_files/example7_old.c'), 'r') as f:
old_src = f.read()
with open(os.path.join(dir_path, 'patch_test_files/example7_new.c'), 'r') as f:
new_src = f.read()

changed_truth = {
'append': {
'adds': 26,
'dels': 9
'dels': 9,
'added_units': 40,
'removed_units': 33
},
'add': {
'adds': 0,
'dels': 5
'dels': 5,
'added_units': 0,
'removed_units': 6
},
'insert': {
'adds': 0,
'dels': 25
'dels': 25,
'added_units': 0,
'removed_units': 44
}

}
assert changed_truth == get_changed_functions(
*func_ranges_truth, *parsing_result, separate=True)
*func_ranges_truth, *parsing_result, old_src, new_src, separate=True)


def test_patch_parser():
Expand Down

0 comments on commit 36c1571

Please sign in to comment.