---
title: Test cases in programming questions
description: A test case pairs an input with an expected output to check a program automatically. Learn how sample test cases differ from internal test cases.
---

[Skip to content](https://help.hackerearth.com/test-cases#main-content)

![hackerearth-logo-light](https://help.hackerearth.com/hubfs/hackerearth-logo-light.svg)

Open main navigation

Close main navigation

 Hello. How can we help you?

- There are no suggestions because the search field is empty.

1. [Help Center](https://help.hackerearth.com/)
2. [Assessments: Candidates](https://help.hackerearth.com/assessments-candidates)
3. [Feedback and queries](https://help.hackerearth.com/assessments-candidates#feedback-and-queries)

# Test cases in programming questions

 

A test case consists of an input to the code and an expected output to verify a program’s actual output against its expected output. It helps in validating your code by evaluating it automatically.

In programming questions, input data is read from the [standard input](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)) stream (STDIN) and the results are printed to the [standard output](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)) stream (STDOUT).

![stdin\_stdout.jpg](https://help.hackerearth.com/hs-fs/hubfs/Knowledge%20Base%20Import/stdin_stdout-1.jpg?width=399&height=120&name=stdin_stdout-1.jpg)

For example, in an online coding test in C, the following code is used to read an integer from STDIN and print the result to STDOUT.

![c\_example\_stdin\_stdout.jpg](https://help.hackerearth.com/hs-fs/hubfs/Knowledge%20Base%20Import/c_example_stdin_stdout-1.jpg?width=393&height=183&name=c_example_stdin_stdout-1.jpg)

The online judge compares your output to the expected output, therefore, if you print an output that is different from the expected output, then an error will be displayed on the screen.

**Types of test cases**

Your code is run against 2 types of test cases: Sample and internal

## **Sample test cases**

- Usually available after the *Constraints* section
- Known as *Sample input* and *Sample output*

*![sample\_input\_output.jpg](https://help.hackerearth.com/hs-fs/hubfs/Knowledge%20Base%20Import/sample_input_output-1.jpg?width=378&height=119&name=sample_input_output-1.jpg)*

- Used to check the logic and validate your code instantly because you can see both the input and expected output values when your code is run against these test cases
- Your code is run against these test cases when you click **Compile & Test**

*Note*: Your code should be able to convert the sample input into the sample output. However, this is not enough to pass the challenge, because the code will be run against multiple, internal test cases too. Therefore, it is important that your code solves the problem statement.

## **Internal test cases**

- Not visible on the platform 
    - Contains multiple test cases that cover a number of scenarios in order to test your code in a holistic manner
      
      ***Example***

![internal\_test\_cases.jpg](https://help.hackerearth.com/hs-fs/hubfs/Knowledge%20Base%20Import/internal_test_cases-1.jpg?width=539&height=199&name=internal_test_cases-1.jpg)

- Your code is run against these test cases when you click **Submit**

*Note*: You cannot edit or change your code after you have submitted it.

**By default, when you compile your code, it is run against the sample test cases. However, if you want to test your code with more test cases, you can manually define these by using the custom input section. For more information, see [Testing your code](https://help.hackerearth.com/hc/en-us/articles/360002609913-testing-your-code).**

- [Assessments: Recruiters](https://help.hackerearth.com/assessments-recruiters#main-content)

    - [Getting started](https://help.hackerearth.com/assessments-recruiters#getting-started)
    - [Account settings](https://help.hackerearth.com/assessments-recruiters#account-settings)
    - [Admin management](https://help.hackerearth.com/assessments-recruiters#admin-management)
    - [Creating tests automatically](https://help.hackerearth.com/assessments-recruiters#creating-tests-automatically)
    - [Creating tests manually](https://help.hackerearth.com/assessments-recruiters#creating-tests-manually)
    - [Test settings](https://help.hackerearth.com/assessments-recruiters#test-settings)
    - [Sections and question pooling](https://help.hackerearth.com/assessments-recruiters#sections-and-question-pooling)
    - [Libraries](https://help.hackerearth.com/assessments-recruiters#libraries)
    - [Multiple Choice Questions (MCQs)](https://help.hackerearth.com/assessments-recruiters#multiple-choice-questions-mcqs)
    - [Programming](https://help.hackerearth.com/assessments-recruiters#programming)
    - [Project](https://help.hackerearth.com/assessments-recruiters#project)
    - [SQL](https://help.hackerearth.com/assessments-recruiters#sql)
    - [Data science](https://help.hackerearth.com/assessments-recruiters#data-science)
    - [Machine Learning (ML)](https://help.hackerearth.com/assessments-recruiters#machine-learning-ml)
    - [DevOps](https://help.hackerearth.com/assessments-recruiters#devops)
    - [Python project questions](https://help.hackerearth.com/assessments-recruiters#python-project-questions)
    - [Automation Testing](https://help.hackerearth.com/assessments-recruiters#automation-testing)
    - [Java Project](https://help.hackerearth.com/assessments-recruiters#java-project)
    - [C# project questions](https://help.hackerearth.com/assessments-recruiters#c-project-questions)
    - [Subjective](https://help.hackerearth.com/assessments-recruiters#subjective)
    - [Approximate](https://help.hackerearth.com/assessments-recruiters#approximate)
    - [Diagram](https://help.hackerearth.com/assessments-recruiters#diagram)
    - [File upload](https://help.hackerearth.com/assessments-recruiters#file-upload)
    - [Invites](https://help.hackerearth.com/assessments-recruiters#invites)
    - [Reports](https://help.hackerearth.com/assessments-recruiters#reports)
    - [Billing](https://help.hackerearth.com/assessments-recruiters#billing)
    - [HackerEarth Reports: Admins, Tests, and Teams](https://help.hackerearth.com/assessments-recruiters#hackerearth-reports-admins-tests-and-teams)
    - [Technical Content Updates](https://help.hackerearth.com/assessments-recruiters#technical-content-updates)
- [FaceCode](https://help.hackerearth.com/facecode#main-content)

    - [FaceCode and its features](https://help.hackerearth.com/facecode#facecode-and-its-features)
    - [Scheduling interviews on FaceCode](https://help.hackerearth.com/facecode#scheduling-interviews-on-facecode)
- [Assessments: ATS integrations](https://help.hackerearth.com/assessments-ats-integrations#main-content)

    - [Integration](https://help.hackerearth.com/assessments-ats-integrations#integration)
    - [iCIMS](https://help.hackerearth.com/assessments-ats-integrations#icims)
    - [Zoho Recruit](https://help.hackerearth.com/assessments-ats-integrations#zoho-recruit)
    - [SmartRecruiters](https://help.hackerearth.com/assessments-ats-integrations#smartrecruiters)
    - [EightFold](https://help.hackerearth.com/assessments-ats-integrations#eightfold)
    - [SuccessFactors](https://help.hackerearth.com/assessments-ats-integrations#successfactors)
    - [Greenhouse](https://help.hackerearth.com/assessments-ats-integrations#greenhouse)
    - [Lever](https://help.hackerearth.com/assessments-ats-integrations#lever)
    - [Linkedin Talent Hub](https://help.hackerearth.com/assessments-ats-integrations#linkedin-talent-hub)
    - [JazzHR](https://help.hackerearth.com/assessments-ats-integrations#jazzhr)
    - [Workable](https://help.hackerearth.com/assessments-ats-integrations#workable)
    - [Recruiterbox - Trakstar Hire](https://help.hackerearth.com/assessments-ats-integrations#recruiterbox-trakstar-hire)
    - [Jobvite](https://help.hackerearth.com/assessments-ats-integrations#jobvite)
    - [Ashby](https://help.hackerearth.com/assessments-ats-integrations#ashby)
- [Assessments: Product updates](https://help.hackerearth.com/assessments-product-updates#main-content)

    - [Release notes: HackerEarth Assessment](https://help.hackerearth.com/assessments-product-updates#release-notes-hackerearth-assessment)
    - [Root Cause Analysis (RCA)](https://help.hackerearth.com/assessments-product-updates#root-cause-analysis-rca)
    - [Content updates](https://help.hackerearth.com/assessments-product-updates#content-updates)
- [Assessments: Best practices](https://help.hackerearth.com/assessments-best-practices#main-content)

    - [Recruit](https://help.hackerearth.com/assessments-best-practices#recruit)
- [SSO](https://help.hackerearth.com/sso#main-content)

    - [SSO](https://help.hackerearth.com/sso#sso)
- [Upskilling](https://help.hackerearth.com/upskilling#main-content)

    - [Introduction: Upskilling](https://help.hackerearth.com/upskilling#introduction-upskilling)
- [Assessments: Candidates](https://help.hackerearth.com/assessments-candidates#main-content)

    - [Getting started](https://help.hackerearth.com/assessments-candidates#getting-started)
    - [Test environment](https://help.hackerearth.com/assessments-candidates#test-environment)
    - [Question types](https://help.hackerearth.com/assessments-candidates#question-types)
    - [FaceCode](https://help.hackerearth.com/assessments-candidates#facecode)
    - [Feedback and queries](https://help.hackerearth.com/assessments-candidates#feedback-and-queries)
- [Problem setting for HackerEarth](https://help.hackerearth.com/problem-setting-for-hackerearth#main-content)

    - [Rate cards](https://help.hackerearth.com/problem-setting-for-hackerearth#rate-cards)
- [Campus](https://help.hackerearth.com/campus#main-content)

    - [Recruiters](https://help.hackerearth.com/campus#recruiters)
    - [Recruiter FAQs](https://help.hackerearth.com/campus#recruiter-faqs)
    - [Candidate FAQs](https://help.hackerearth.com/campus#candidate-faqs)
- [Hackathons and Hiring Challenges](https://help.hackerearth.com/hackathons-and-hiring-challenges#main-content)

    - [Hackathons](https://help.hackerearth.com/hackathons-and-hiring-challenges#hackathons)
    - [Hiring challenges](https://help.hackerearth.com/hackathons-and-hiring-challenges#hiring-challenges)
- [Frequently Asked Questions (FAQs)](https://help.hackerearth.com/frequently-asked-questions-faqs#main-content)

    - [Assessments: Recruiters](https://help.hackerearth.com/frequently-asked-questions-faqs#assessments-recruiters)
    - [GDPR compliance (Candidates)](https://help.hackerearth.com/frequently-asked-questions-faqs#gdpr-compliance-candidates)
    - [GDPR compliance (Recruiters)](https://help.hackerearth.com/frequently-asked-questions-faqs#gdpr-compliance-recruiters)
    - [General](https://help.hackerearth.com/frequently-asked-questions-faqs#general)
    - [Assessments: Candidates](https://help.hackerearth.com/frequently-asked-questions-faqs#assessments-candidates)
    - [HackerEarth Vs ChatGPT](https://help.hackerearth.com/frequently-asked-questions-faqs#hackerearth-vs-chatgpt)
- [Profiles](https://help.hackerearth.com/profiles#main-content)

    - [Profiles - Recruiter](https://help.hackerearth.com/profiles#profiles-recruiter)
- [OnScreen](https://help.hackerearth.com/onscreen#main-content)

    - [OnScreen - Interview templates](https://help.hackerearth.com/onscreen#onscreen-interview-templates)
    - [OnScreen - Sending Invites](https://help.hackerearth.com/onscreen#onscreen-sending-invites)
    - [OnScreen - Download reports](https://help.hackerearth.com/onscreen#onscreen-download-reports)
    - [OnScreen - Interview Analytics](https://help.hackerearth.com/onscreen#onscreen-interview-analytics)
    - [OnScreen - Overview](https://help.hackerearth.com/onscreen#onscreen-overview)
    - [OnScreen - Interview Proctoring Settings](https://help.hackerearth.com/onscreen#onscreen-interview-proctoring-settings)

[![hackerearth-logo-light](https://help.hackerearth.com/hubfs/hackerearth-logo-light.svg "hackerearth-logo-light")](https://www.hackerearth.com/)

##### The skills intelligence platform for the AI era. Evaluate developers, candidates, and AI agents.

<https://www.linkedin.com/company/hackerearth/> <https://twitter.com/HackerEarth> <https://www.youtube.com/channel/UCYU6nvKyRYnE5kiG9JXkXpA>

© 2026 HackerEarth · All rights reserved