In your HackerRank coding tests, the “Test against custom inputs” option enables you to test the logic in your code using your custom input values. A custom test case uses the provided input values to validate the logic in your code and return an output.
There are two methods available to enter custom input values:
- Visual Format - This is an intuitive and easy method for candidates to enter input. It provides a ready-to-use format according to the input type expected by the given function. For instance, if a function expects array elements as input, then the visual format automatically displays the array format to enter values.
This is the default and recommended method for adding custom input values.
Note: The Visual Format is available only for coding questions that include a pre-defined function definition (code-stubs) which you're expected to complete with your logic to generate an output.
- Raw Format - In this method, you must know the input data type expected by the function and enter custom inputs accordingly. For instance, if a function expects array elements as input, you must specify the array size followed by the array elements.
This method is not recommended when you have longer input values.
Note: The downloaded sample test cases include input values in raw format.
Visual Format and Raw Format - Examples
Consider a question where you are expected to complete the logic of a given function, Sum (), which calculates the sum of the elements of an array. The function expects array elements as input values.
- Click Test against custom input.
- Just enter the array elements and press ENTER after adding each element. If the array size is 5, you must enter 5 elements.
- Click Run Code.
A custom test case executes the logic in the function with the given array elements and displays the output.
The Visual Format currently supports custom input values for the following data types:
- Long Integer
- Single Dimensional Array
- Single Linked List
- Click Raw Format.
- The first value in your custom input must specify the length of the array, followed by the equal number of array elements, as shown below.
- Click Run Code. A custom test case executes the logic in the function with the given array elements and displays the output.
Note: The "Test against custom input" option is available only if it is permitted in your test.