Overview
HackerRank for Work enables you to implement a custom scoring method using weights for Full Stack project Questions. The purpose of weights is to assign adequate importance to complex scenarios which you want to evaluate in your Candidate’s solution to a problem. You can assign higher weights to critical test cases which will automatically score higher points over those with lesser weights.
You must define test case weights in the hackerrank.yml configuration file using the testcase_weights: attribute.
This article provides an example of how test cases are scored based on their weights and the steps to implement custom scoring for Full-Stack Questions.
Custom Scoring Sample
Consider that your Full Stack Question has an overall score of 50 points and you have 4 Test cases in your Question. The following table illustrates how different weights are added to each test case in the hackerrank.yml file and how the test cases score individual points upon successful execution in a Candidate's Test.
Test Case | Test case weight added in the hackerrank.yml config file | The score attained upon successful execution |
test1 | 0.1 | 5/5 |
test2 | 0.2 | 10/10 |
test3 | 0.2 | 10/10 |
test4 | 0.5 | 25/25 |
SUM | 1 | 50 |
Note: Test case weights must be defined as a decimal fraction of 1, and the sum of the weights must also add up to 1.
In HackerRank for Work, the Candidate's detailed Test report reflects the Question's overall score and the individual test scores as shown below:
Implementing Custom Scoring for Full Stack
- First, you must create a valid project for your Full-Stack Question and include the hackerrank.yml configuration file in the root directory. The following topics help you to understand how to create a Full Stack Question, set up a valid project for it, and configure the hackerrank.yml file,
- After creating the project, run it locally, and note the exact function or test case names from the unit.xml file. Ensure that test case names are unique across all the files in the project.
- In HackerRank for Work, create the Full Stack Question and upload the project. The following image illustrates a sample Back-end project Question based on Django.
- In the Setup Project tab of the Full Stack Question, click the hackerrank.yml file located in the root directory.
- Add the testcase_weights: attribute, and for each Test case define the weight in the following format.
<testcasename>: <weight>
The weights must be defined as a decimal fraction of 1.
Example: test1_create_existing_user: 0.2
- Ensure that you specify the exact test case names and the individual test case weights sum up to 1.
- After you have defined the test case weights, click CTRL + S to save the file.
- Click on the Validate and Save button. Project validation must be successful.
- Click on the Proceed button.
- As an optional step, you can click on the Try Question option to test your Question by launching the IDE.
- Click on the Save and Proceed button to save the Question.
Your Question now has a custom scoring pattern defined for all the test cases in the project. You can modify this by changing the weights appropriately in the hackerrank.yml file.
Tip: You can log in to an actual Test and attempt the Question with the correct solution to pass all the test cases. In HackerRank for Work, you can view the detailed test report for the particular attempt to understand how each test case has been scored based on the weights you have defined for them in the hackerrank.yml file.