CSC/ECE 517 Fall 2021 - E2132. Add tests cases for review mapping helper.rb: Difference between revisions
No edit summary |
|||
Line 39: | Line 39: | ||
=== response_for_each_round? === | === response_for_each_round? === | ||
This method | This method returns in boolean function if the assignments are submitted on time. It is expected to return true only if every assignment is submitted on time. For the first part of unit test, one response is needed for a true result in one round. As for the second part, both responses are needed for a true result in two rounds. If any response is missing, it should return false. | ||
<pre> | <pre> | ||
it 'should return false if response wasnt submitted in every round' do | |||
create(:assignment_due_date, assignment: @assignment, parent_id: @assignment.id, round: 1) | |||
create(:assignment_due_date, assignment: @assignment, parent_id: @assignment.id, round: 2) | |||
create(:response, response_map: @response_map) | |||
check_response = response_for_each_round?(@response_map) | |||
expect(check_response).to eq(false) | |||
end | |||
#one round, one response | |||
it 'should return true if there is one response with one round' do | |||
create(:deadline_right, name: 'No') | |||
create(:deadline_right, name: 'Late') | |||
create(:deadline_right, name: 'OK') | |||
# make a team for the assignment | |||
create(:assignment_team, assignment: @assignment) | |||
response_map_with_reviewee = create(:review_response_map, reviewer: @reviewer, reviewee: @reviewee) | |||
create(:submission_record, assignment_id: @assignment.id, team_id: @reviewee.id, operation: 'Submit Hyperlink', content: 'random link', created_at: DateTime.now.in_time_zone - 7.day) | |||
create(:assignment_due_date, assignment: @assignment, parent_id: @assignment.id, round: 1, due_at: DateTime.now.in_time_zone - 5.day) | |||
create(:response, response_map: response_map_with_reviewee) | |||
check_response = response_for_each_round?(response_map_with_reviewee) | |||
expect(check_response).to eq(true) | |||
end | |||
#two round,two response | |||
it 'should return true if there were both response' do | |||
create(:deadline_right, name: 'No') | |||
create(:deadline_right, name: 'Late') | |||
create(:deadline_right, name: 'OK') | |||
# make a team for the assignment | |||
create(:assignment_team, assignment: @assignment) | |||
response_map_with_reviewee = create(:review_response_map, reviewer: @reviewer, reviewee: @reviewee) | |||
create(:submission_record, assignment_id: @assignment.id, team_id: @reviewee.id, operation: 'Submit Hyperlink', content: 'random link', created_at: DateTime.now.in_time_zone - 7.day) | |||
create(:submission_record, assignment_id: @assignment.id, team_id: @reviewee.id, operation: 'Submit Hyperlink', content: 'random link', created_at: DateTime.now.in_time_zone - 3.day) | |||
create(:assignment_due_date, assignment: @assignment, parent_id: @assignment.id, round: 1, due_at: DateTime.now.in_time_zone - 5.day) | |||
create(:assignment_due_date, assignment: @assignment, parent_id: @assignment.id, round: 2, due_at: DateTime.now.in_time_zone - 2.day) | |||
create(:response, response_map: response_map_with_reviewee, round: 1) | |||
create(:response, response_map: response_map_with_reviewee, round: 2) | |||
check_response = response_for_each_round?(response_map_with_reviewee) | |||
expect(check_response).to eq(true) | |||
end | |||
#two round, only have first response | |||
it 'should return false if only have first response' do | |||
create(:deadline_right, name: 'No') | |||
create(:deadline_right, name: 'Late') | |||
create(:deadline_right, name: 'OK') | |||
# make a team for the assignment | |||
create(:assignment_team, assignment: @assignment) | |||
response_map_with_reviewee = create(:review_response_map, reviewer: @reviewer, reviewee: @reviewee) | |||
create(:submission_record, assignment_id: @assignment.id, team_id: @reviewee.id, operation: 'Submit Hyperlink', content: 'random link', created_at: DateTime.now.in_time_zone - 2.day) | |||
create(:submission_record, assignment_id: @assignment.id, team_id: @reviewee.id, operation: 'Submit Hyperlink', content: 'random link', created_at: DateTime.now.in_time_zone - 3.day) | |||
create(:assignment_due_date, assignment: @assignment, parent_id: @assignment.id, round: 1, due_at: DateTime.now.in_time_zone - 5.day) | |||
create(:assignment_due_date, assignment: @assignment, parent_id: @assignment.id, round: 2, due_at: DateTime.now.in_time_zone + 6.day) | |||
create(:response, response_map: response_map_with_reviewee, round: 1) | |||
check_response = response_for_each_round?(response_map_with_reviewee) | |||
expect(check_response).to eq(false) | |||
end | |||
#two round,only have second response | |||
it 'should return false if only have second response' do | |||
create(:deadline_right, name: 'No') | |||
create(:deadline_right, name: 'Late') | |||
create(:deadline_right, name: 'OK') | |||
# make a team for the assignment | |||
create(:assignment_team, assignment: @assignment) | |||
response_map_with_reviewee = create(:review_response_map, reviewer: @reviewer, reviewee: @reviewee) | |||
create(:submission_record, assignment_id: @assignment.id, team_id: @reviewee.id, operation: 'Submit Hyperlink', content: 'random link', created_at: DateTime.now.in_time_zone - 7.day) | |||
create(:submission_record, assignment_id: @assignment.id, team_id: @reviewee.id, operation: 'Submit Hyperlink', content: 'random link', created_at: DateTime.now.in_time_zone - 1.day) | |||
create(:assignment_due_date, assignment: @assignment, parent_id: @assignment.id, round: 1, due_at: DateTime.now.in_time_zone - 5.day) | |||
create(:assignment_due_date, assignment: @assignment, parent_id: @assignment.id, round: 2, due_at: DateTime.now.in_time_zone - 2.day) | |||
create(:response, response_map: response_map_with_reviewee, round: 2) | |||
check_response = response_for_each_round?(response_map_with_reviewee) | |||
expect(check_response).to eq(false) | |||
end | |||
</pre> | |||
=== submitted_within_round? === | === submitted_within_round? === |
Revision as of 04:10, 16 October 2021
About Expertiza
Expertiza is an open source project based on Ruby on Rails framework that supports submission across different document types, including theURLs and wiki pages. It allows the instructor not only to create and customize new or existing assignments but also to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions.
Description about project
This page is a description of Expertiza OSS project E2132 which is adding unit tests for review_mapping_helper.rb. The ReviewMappingHelper works as a class that is responsible for mapping reviews and feedback to assignment teams and reviewers. Also, This helper class reports of the status of project reviews.
Team
Chen-Ni Liu (cliu43) Shao-Yo Chao (schao2) Fu-Jen Yen (fyen)
Files Involved
review_mapping_helper.rb
review_mapping_helper_spec.rb
Running Tests
rspec spec/helpers/review_mapping_helper_spec.rb
Relevant Methods
- response_for_each_round?
- submitted_within_round?
- submitted_hyperlink
- get_team_reviewed_link_name
- sort_reviewer_by_review_volume_desc
- list_review_submission
- list_hyperlink_submission
- get_certain_review_and_feedback_response_map
- get_css_style_for_calibration_report
response_for_each_round?
This method returns in boolean function if the assignments are submitted on time. It is expected to return true only if every assignment is submitted on time. For the first part of unit test, one response is needed for a true result in one round. As for the second part, both responses are needed for a true result in two rounds. If any response is missing, it should return false.
it 'should return false if response wasnt submitted in every round' do create(:assignment_due_date, assignment: @assignment, parent_id: @assignment.id, round: 1) create(:assignment_due_date, assignment: @assignment, parent_id: @assignment.id, round: 2) create(:response, response_map: @response_map) check_response = response_for_each_round?(@response_map) expect(check_response).to eq(false) end #one round, one response it 'should return true if there is one response with one round' do create(:deadline_right, name: 'No') create(:deadline_right, name: 'Late') create(:deadline_right, name: 'OK') # make a team for the assignment create(:assignment_team, assignment: @assignment) response_map_with_reviewee = create(:review_response_map, reviewer: @reviewer, reviewee: @reviewee) create(:submission_record, assignment_id: @assignment.id, team_id: @reviewee.id, operation: 'Submit Hyperlink', content: 'random link', created_at: DateTime.now.in_time_zone - 7.day) create(:assignment_due_date, assignment: @assignment, parent_id: @assignment.id, round: 1, due_at: DateTime.now.in_time_zone - 5.day) create(:response, response_map: response_map_with_reviewee) check_response = response_for_each_round?(response_map_with_reviewee) expect(check_response).to eq(true) end #two round,two response it 'should return true if there were both response' do create(:deadline_right, name: 'No') create(:deadline_right, name: 'Late') create(:deadline_right, name: 'OK') # make a team for the assignment create(:assignment_team, assignment: @assignment) response_map_with_reviewee = create(:review_response_map, reviewer: @reviewer, reviewee: @reviewee) create(:submission_record, assignment_id: @assignment.id, team_id: @reviewee.id, operation: 'Submit Hyperlink', content: 'random link', created_at: DateTime.now.in_time_zone - 7.day) create(:submission_record, assignment_id: @assignment.id, team_id: @reviewee.id, operation: 'Submit Hyperlink', content: 'random link', created_at: DateTime.now.in_time_zone - 3.day) create(:assignment_due_date, assignment: @assignment, parent_id: @assignment.id, round: 1, due_at: DateTime.now.in_time_zone - 5.day) create(:assignment_due_date, assignment: @assignment, parent_id: @assignment.id, round: 2, due_at: DateTime.now.in_time_zone - 2.day) create(:response, response_map: response_map_with_reviewee, round: 1) create(:response, response_map: response_map_with_reviewee, round: 2) check_response = response_for_each_round?(response_map_with_reviewee) expect(check_response).to eq(true) end #two round, only have first response it 'should return false if only have first response' do create(:deadline_right, name: 'No') create(:deadline_right, name: 'Late') create(:deadline_right, name: 'OK') # make a team for the assignment create(:assignment_team, assignment: @assignment) response_map_with_reviewee = create(:review_response_map, reviewer: @reviewer, reviewee: @reviewee) create(:submission_record, assignment_id: @assignment.id, team_id: @reviewee.id, operation: 'Submit Hyperlink', content: 'random link', created_at: DateTime.now.in_time_zone - 2.day) create(:submission_record, assignment_id: @assignment.id, team_id: @reviewee.id, operation: 'Submit Hyperlink', content: 'random link', created_at: DateTime.now.in_time_zone - 3.day) create(:assignment_due_date, assignment: @assignment, parent_id: @assignment.id, round: 1, due_at: DateTime.now.in_time_zone - 5.day) create(:assignment_due_date, assignment: @assignment, parent_id: @assignment.id, round: 2, due_at: DateTime.now.in_time_zone + 6.day) create(:response, response_map: response_map_with_reviewee, round: 1) check_response = response_for_each_round?(response_map_with_reviewee) expect(check_response).to eq(false) end #two round,only have second response it 'should return false if only have second response' do create(:deadline_right, name: 'No') create(:deadline_right, name: 'Late') create(:deadline_right, name: 'OK') # make a team for the assignment create(:assignment_team, assignment: @assignment) response_map_with_reviewee = create(:review_response_map, reviewer: @reviewer, reviewee: @reviewee) create(:submission_record, assignment_id: @assignment.id, team_id: @reviewee.id, operation: 'Submit Hyperlink', content: 'random link', created_at: DateTime.now.in_time_zone - 7.day) create(:submission_record, assignment_id: @assignment.id, team_id: @reviewee.id, operation: 'Submit Hyperlink', content: 'random link', created_at: DateTime.now.in_time_zone - 1.day) create(:assignment_due_date, assignment: @assignment, parent_id: @assignment.id, round: 1, due_at: DateTime.now.in_time_zone - 5.day) create(:assignment_due_date, assignment: @assignment, parent_id: @assignment.id, round: 2, due_at: DateTime.now.in_time_zone - 2.day) create(:response, response_map: response_map_with_reviewee, round: 2) check_response = response_for_each_round?(response_map_with_reviewee) expect(check_response).to eq(false) end
submitted_within_round?
This method checks the record if the assignment is submitted on time, that is, before due date. Setting up two submissions on two different due date, so in the unit test there would be four situations to discuss. If all the works are submitted on time, the response is expected to be true. Otherwise, the response depends on the last submission's status.
submitted_hyperlink
This method returns the hyperlink that is submitted on time. For one assignment, it returns the hyperlink that is submitted before due date. For multiple assignments, no matter how many assignments are submitted on time, it shows the hyperlink of the last submission that is submitted on time.
it 'should return https://wiki.archlinux.org/123 if works was submitted on time' do create(:deadline_right, name: 'No') create(:deadline_right, name: 'Late') create(:deadline_right, name: 'OK') create(:submission_record, assignment_id: @assignment.id, team_id: @reviewee.id, operation: 'Submit Hyperlink', content: 'https://wiki.archlinux.org/', created_at: DateTime.now.in_time_zone - 12.day) create(:submission_record, assignment_id: @assignment.id, team_id: @reviewee.id, operation: 'Submit Hyperlink', content: 'https://wiki.archlinux.org/123', created_at: DateTime.now.in_time_zone - 7.day) create(:response, response_map: @response_map) create(:assignment_due_date, assignment: @assignment, parent_id: @assignment.id, round: 1, due_at: DateTime.now.in_time_zone - 10.day) create(:assignment_due_date, assignment: @assignment, parent_id: @assignment.id, round: 2, due_at: DateTime.now.in_time_zone - 5.day) assignment_created = @assignment.created_at assignment_due_dates = DueDate.where(parent_id: @response_map.reviewed_object_id) hyper_link = submitted_hyperlink(@round, @response_map, assignment_created, assignment_due_dates) expect(hyper_link).to eq('https://wiki.archlinux.org/123') end it 'should return https://wiki.archlinux.org/123 if only a work was submitted on time' do create(:deadline_right, name: 'No') create(:deadline_right, name: 'Late') create(:deadline_right, name: 'OK') create(:submission_record, assignment_id: @assignment.id, team_id: @reviewee.id, operation: 'Submit Hyperlink', content: 'https://wiki.archlinux.org/', created_at: DateTime.now.in_time_zone - 8.day) create(:submission_record, assignment_id: @assignment.id, team_id: @reviewee.id, operation: 'Submit Hyperlink', content: 'https://wiki.archlinux.org/123', created_at: DateTime.now.in_time_zone - 6.day) create(:response, response_map: @response_map) create(:assignment_due_date, assignment: @assignment, parent_id: @assignment.id, round: 1, due_at: DateTime.now.in_time_zone - 10.day) create(:assignment_due_date, assignment: @assignment, parent_id: @assignment.id, round: 2, due_at: DateTime.now.in_time_zone - 5.day) assignment_created = @assignment.created_at assignment_due_dates = DueDate.where(parent_id: @response_map.reviewed_object_id) hyper_link = submitted_hyperlink(@round, @response_map, assignment_created, assignment_due_dates) expect(hyper_link).to eq('https://wiki.archlinux.org/123') end it 'should return https://wiki.archlinux.org/ if only a work was submitted on time' do create(:deadline_right, name: 'No') create(:deadline_right, name: 'Late') create(:deadline_right, name: 'OK') create(:submission_record, assignment_id: @assignment.id, team_id: @reviewee.id, operation: 'Submit Hyperlink', content: 'https://wiki.archlinux.org/', created_at: DateTime.now.in_time_zone - 12.day) create(:submission_record, assignment_id: @assignment.id, team_id: @reviewee.id, operation: 'Submit Hyperlink', content: 'https://wiki.archlinux.org/123', created_at: DateTime.now.in_time_zone - 4.day) create(:response, response_map: @response_map) create(:assignment_due_date, assignment: @assignment, parent_id: @assignment.id, round: 1, due_at: DateTime.now.in_time_zone - 10.day) create(:assignment_due_date, assignment: @assignment, parent_id: @assignment.id, round: 2, due_at: DateTime.now.in_time_zone - 5.day) assignment_created = @assignment.created_at assignment_due_dates = DueDate.where(parent_id: @response_map.reviewed_object_id) hyper_link = submitted_hyperlink(@round, @response_map, assignment_created, assignment_due_dates) expect(hyper_link).to eq('https://wiki.archlinux.org/') end it 'should return https://wiki.archlinux.org/ if only a work was Submit Hyperlink' do create(:deadline_right, name: 'No') create(:deadline_right, name: 'Late') create(:deadline_right, name: 'OK') create(:submission_record, assignment_id: @assignment.id, team_id: @reviewee.id, operation: 'Submit Hyperlink', content: 'https://wiki.archlinux.org/', created_at: DateTime.now.in_time_zone - 12.day) create(:submission_record, assignment_id: @assignment.id, team_id: @reviewee.id, operation: 'Not Submit Hyperlink', content: 'https://wiki.archlinux.org/123', created_at: DateTime.now.in_time_zone - 6.day) create(:response, response_map: @response_map) create(:assignment_due_date, assignment: @assignment, parent_id: @assignment.id, round: 1, due_at: DateTime.now.in_time_zone - 10.day) create(:assignment_due_date, assignment: @assignment, parent_id: @assignment.id, round: 2, due_at: DateTime.now.in_time_zone - 5.day) assignment_created = @assignment.created_at assignment_due_dates = DueDate.where(parent_id: @response_map.reviewed_object_id) hyper_link = submitted_hyperlink(@round, @response_map, assignment_created, assignment_due_dates) expect(hyper_link).to eq('https://wiki.archlinux.org/') end
get_team_reviewed_link_name
This method checks if the max_team_size is 1 or not and gives appropriate team reviewed link name. Given the input max_team_size, response, reviewee_id, ip_address, if the team size is 1, it is expected to get the return of the student's name. If not, it is expected to return "Team 1".
it 'should return (Team_1) if max_team_size = 3' do max_team_size = 3 @response = create(:response, response_map: @response_map) ip_address = '0.0.0.0' reviewed_team_name = get_team_reviewed_link_name(max_team_size, @response, @reviewee.id, ip_address) expect(reviewed_team_name).to eq('(Team_1)') end it 'should return (Team_1) if max_team_size = 2' do max_team_size = 2 @response = create(:response, response_map: @response_map) ip_address = '0.0.0.0' reviewed_team_name = get_team_reviewed_link_name(max_team_size, @response, @reviewee.id, ip_address) expect(reviewed_team_name).to eq('(Team_1)') end it 'should return (Adam) if max_team_size = 1' do max_team_size = 1 student = create(:student, fullname: 'Adam') create(:team_user, user: student, team: @reviewee) @response = create(:response, response_map: @response_map) ip_address = '0.0.0.0' reviewed_team_name = get_team_reviewed_link_name(max_team_size, @response, @reviewee.id, ip_address) expect(reviewed_team_name).to eq('(Adam)') end it 'should return (Team_1) if max_team_size = 0' do max_team_size = 0 @response = create(:response, response_map: @response_map) ip_address = '0.0.0.0' reviewed_team_name = get_team_reviewed_link_name(max_team_size, @response, @reviewee.id, ip_address) expect(reviewed_team_name).to eq('(Team_1)') end
sort_reviewer_by_review_volume_desc
This method sorts the reviewer depending on the length of the content of the review. It is sorted in descent order, and follows the order of create if the length of the reviews are the same.
it 'the order should be 2-3-1 if the order of comment volume is 2 > 3 > 1' do @response_1 = create(:response, response_map: @response_map_1, additional_comment: 'good') @response_2 = create(:response, response_map: @response_map_2, additional_comment: 'Good job with clear code') @response_3 = create(:response, response_map: @response_map_3, additional_comment: 'goodclear code') @reviewers = Array[@reviewer_1, @reviewer_2, @reviewer_3] @reviewers_for_test = Array[@reviewer_2, @reviewer_3, @reviewer_1] sort_reviewer_by_review_volume_desc expect(@reviewers).to eq(@reviewers_for_test) end it 'the order should be 2-1-3 if the comment volume is 2 > 1 = 3' do @response_1 = create(:response, response_map: @response_map_1, additional_comment: 'good job') @response_2 = create(:response, response_map: @response_map_2, additional_comment: 'Good job with clear code') @response_3 = create(:response, response_map: @response_map_3, additional_comment: 'clear code') @reviewers = Array[@reviewer_1, @reviewer_2, @reviewer_3] @reviewers_for_test = Array[@reviewer_2, @reviewer_1, @reviewer_3] sort_reviewer_by_review_volume_desc expect(@reviewers).to eq(@reviewers_for_test) end it 'the order should be 1-2-3 if the comment volume is 1 = 2 = 3' do @response_1 = create(:response, response_map: @response_map_1, additional_comment: 'good job') @response_2 = create(:response, response_map: @response_map_2, additional_comment: 'clear code') @response_3 = create(:response, response_map: @response_map_3, additional_comment: 'nice bro') @reviewers = Array[@reviewer_1, @reviewer_2, @reviewer_3] @reviewers_for_test = Array[@reviewer_1, @reviewer_2, @reviewer_3] sort_reviewer_by_review_volume_desc expect(@reviewers).to eq(@reviewers_for_test) end
list_review_submission
This method returns the correct html tag if a review file exist. Otherwise, it should return an empty string when the file does not exist. In the first test, a sudo file created in AssignmentTeam is allowed to find and return a correct html that start with "<a href". In the second test, since the file does not exist, it returns an empty string.
it 'should return correct html a tag' do result = helper.list_review_submissions(@participant.id, @team.id, @response_map.id) expect(result).to start_with("<a href") end it 'should return an empty string when the file does not exist' do result = helper.list_review_submissions(@participant.id, @team.id, @response_map.id) expect(result).to eq('')
list_hyperlink_submission
This method returns an empty string when comment does not exist.
it 'should return an empty string when comment does not exist' do result = helper.list_hyperlink_submission(@response_map.id, @question.id) expect(result).to eq('') end
get_certain_review_and_feedback_response_map
it 'should return the number of responses given in round 1 reviews' do get_each_review_and_feedback_response_map(@reviewer) # rspan means the all peer reviews one student received, including unfinished one # retrieved from method call in review_mapping_helper.rb file expect(@rspan_round_one).to eq 1 end it 'should return the number of responses given in round 2 reviews' do get_each_review_and_feedback_response_map(@reviewer) # rspan means the all peer reviews one student received, including unfinished one # retrieved from method call in review_mapping_helper.rb file expect(@rspan_round_two).to eq 1 end it 'should return the number of responses given in round 3 reviews' do # have to add in third response, did not in before action for nil scenario @response_3 = create(:response, response_map: @response_map_3, round: 3) @response_list << @response_3 @feedback_response_map_list << FeedbackResponseMap.create(reviewed_object_id: @response_3.id, reviewer_id: @reviewer.id) @all_review_response_ids << @response_3.id get_each_review_and_feedback_response_map(@reviewer) # rspan means the all peer reviews one student received, including unfinished one # retrieved from method call in review_mapping_helper.rb file expect(@rspan_round_three).to eq 1 end it 'should return 0 responses for no round 3 reviews' do # no feedback responses set before method call get_each_review_and_feedback_response_map(@reviewer) # rspan means the all peer reviews one student received, including unfinished one # retrieved from method call in review_mapping_helper.rb file expect(@rspan_round_three).to eq 0 end
get_css_style_for_calibration_report
The method transfers the variable diff, the difference between the student's and the instructor's answer into css style. A dictionary is created as dict = {0 => 'c5',1 => 'c4',2 => 'c3',3 => 'c2'}. In the first unit test, "0" set as the the diff is expected to return c5. In the second test, "-1" is a negative integer, so the absolute value is used to return c4. In the third test, since "6" is not in the key of dict, according to the function, it should return c1.
it 'should return correct css class' do css_class_0 = helper.get_css_style_for_calibration_report(0) css_class_1 = helper.get_css_style_for_calibration_report(-1) css_class_6 = helper.get_css_style_for_calibration_report(6) expect(css_class_0). to eq('c5') expect(css_class_1). to eq('c4') expect(css_class_6). to eq('c1') end
Results
==