Testing scientific and data-analysis software means checking that code produces numerically correct answers within a stated tolerance, not just that it runs. In a 14-day internship you can do this by comparing outputs with trusted reference data, writing tolerance checks, and documenting every test with a repeatable template, all of which are provided below.
Why research code needs a different kind of testing
Most introductory testing material assumes a function has an obvious right answer: add two numbers, get a sum. Research code rarely works that way. A fitting routine, a spectrum-processing script or a simulation returns floating-point values that depend on the algorithm, the library version, the random seed and the order of operations. Two correct implementations can differ in the tenth decimal place. A wrong implementation can look plausible for years because nobody has an independent answer to compare with.
This is the core problem testers face in science: the “oracle problem”. You often do not know the exact expected output, so you must build confidence indirectly. The approaches in this article are the usual ways of doing that:
- Reference data comparison: compare output with a published result, an analytic solution, or output of a trusted independent tool.
- Tolerance checks: accept results within an explicit absolute or relative error rather than demanding exact equality.
- Property and invariant checks: verify things that must always hold, such as conservation of a quantity or symmetry.
- Convergence checks: confirm that error shrinks as step size or sample size improves.
- Regression checks: freeze a validated output and detect any later unexpected change.
- Edge-case and bad-input checks: empty arrays, NaN values, single data points, units mismatched.
Reference data comparison: choosing a trustworthy answer
A reference is only useful if it is more trustworthy than the code under test. Rank your options roughly like this, strongest first:
- Closed-form analytic results. For example, the sum of a known geometric series, the integral of a polynomial, or the eigenvalues of a small matrix you can solve by hand.
- Published benchmark values with a citation, such as tabulated constants or a worked example in a textbook or paper.
- An independent, well-established implementation (for instance a mature numerical library) run on identical inputs.
- A previous validated version of the same code. This protects against change, but not against an error that was already present.
Record where each reference came from, which version of any library produced it, and the exact input. A reference without provenance is just another unverified number.
Free 2-Week CareerSwami Internship
Online, 14 days, with a free offer letter and a free completion certificate once you finish the work. Check with your college that it fits your requirement before you enrol.
Tolerance checks: absolute, relative and when each fails
Exact equality on floating-point numbers is almost always the wrong test. Use a tolerance, and choose the type deliberately.
| Tolerance type | Condition | Good for | Where it breaks |
|---|---|---|---|
| Absolute | |actual − expected| ≤ atol | Values near zero, residuals, differences | Meaningless when values span many orders of magnitude |
| Relative | |actual − expected| ≤ rtol × |expected| | Quantities with a natural scale, such as energies or intensities | Fails when the expected value is zero or extremely small |
| Combined | |actual − expected| ≤ atol + rtol × |expected| | General-purpose array comparison | Needs both numbers justified, not guessed |
| ULP / machine-epsilon based | Difference measured in units of floating-point spacing | Testing basic arithmetic or special functions | Too strict for iterative or stochastic methods |
| Statistical | Result within k standard errors over many seeded runs | Monte Carlo and sampling code | Needs enough runs; can pass by luck if k is generous |
The hard question is where the number comes from. A tolerance of 1e-6 is not “correct” by itself. Justify it from the method: an iterative solver stopped at 1e-8 cannot be tested to 1e-12, and data measured to three significant figures cannot be validated to ten. Write the justification beside the test.
A test design template for numerical software
Use this template for each function or pipeline stage you test. Copy it into a spreadsheet or a markdown file in the project repository, one row or block per test.
| Field | What to write |
|---|---|
| Test ID | A short unique label, such as FIT-03 |
| Unit under test | Function, script or pipeline stage, with version or commit |
| Purpose | The single behaviour or risk being checked |
| Input | Exact data, file name and checksum, parameters, random seed |
| Environment | Language version, library versions, operating system |
| Reference and provenance | Expected value and where it came from |
| Tolerance and rationale | atol, rtol, and why these values suit the method |
| Check type | Reference, property, convergence, regression, edge case |
| Pass criterion | Precise rule, including handling of NaN and infinity |
| Result and date | Observed value, difference from expected, pass or fail |
| Notes | Anomalies, suspected causes, follow-up |
Checklist to apply before you trust any test
- Is the random seed fixed and recorded?
- Are units stated for every input and output?
- Does the test fail when you deliberately break the code? (Introduce a small bug on a scratch copy and confirm.)
- Is the tolerance tight enough to catch a real error but loose enough to survive a library upgrade?
- Would a colleague be able to rerun it from your notes alone?
Worked illustrative example: validating a least-squares line-fit routine
This example is illustrative. The numbers are constructed for teaching, and no code has been run for this article. Suppose a lab script fits a straight line y = m·x + c to measurement data and reports slope, intercept and R².
Step 1: build an exact-answer case. Generate five points that lie exactly on y = 2x + 1: (0, 1), (1, 3), (2, 5), (3, 7), (4, 9). The correct result is slope 2, intercept 1, R² of 1. Use an absolute tolerance of 1e-9, since a clean linear fit should be near machine precision.
Step 2: add an independent reference. Take a small noisy dataset and compute the fit with a second, established tool or by solving the normal equations by hand in a spreadsheet. Compare slope and intercept with a relative tolerance of 1e-6, and record the tool and version used.
Step 3: property checks.
- Scaling every y by 10 should scale slope and intercept by 10 and leave R² unchanged.
- Shifting every x by a constant should change the intercept but not the slope.
- Reordering the data rows should not change the result beyond the tolerance.
Step 4: edge cases. Test one point, two identical x values for all points (vertical line, undefined slope), an empty file, a NaN in one row, and text in a numeric column. Decide and document what correct behaviour is: a clear error, not a silent number.
Step 5: log it. A filled template row might read: Test ID FIT-01; purpose, exact linear recovery; input, five listed points; reference, analytic; tolerance, atol 1e-9 because no noise is present; pass criterion, slope, intercept and R² all within tolerance. If the vertical-line case returns a huge slope instead of raising an error, you have found a genuine defect worth reporting.
Handling randomness, large data and long runtimes
- Stochastic code: fix the seed for regression tests, and separately run statistical tests across many seeds to confirm the mean and spread match theory.
- Large datasets: build a small subset where the answer is knowable, and test the full dataset only for properties and regression.
- Slow simulations: create a reduced configuration (fewer steps, smaller grid) for routine tests, and keep full runs for scheduled checks.
- Parallel code: summation order can change floating-point results, so compare with a tolerance and not byte for byte.
- File-format code: round-trip a file (write, read, compare) and check metadata such as units and headers.
For IACS students: applying this to a research-institute setting
A Department of Science and Technology advertisement for the post of Director describes IACS, Kolkata 700032, as an autonomous body under the Department of Science & Technology, Government of India. The same document says it is a Deemed to be University under Section 3 of the UGC Act, 1956. Both points come from an excerpt, so check the current wording on the official IACS website.
What does that mean for this topic? A research-focused deemed university is a place where students are likely to meet home-grown analysis scripts, instrument-processing code and simulation tools written by researchers. That makes the validation habits above directly relevant, but it does not tell you how any programme at IACS treats internships. Rules on duration, credit, evaluation, permitted online internships and documentation have not been verified here, so do not assume that an internship will count towards your degree or that any particular department will recognise it.
If you want a low-risk way to practise, the free two-week online internship at CareerSwami offers a free offer letter and a free completion certificate after successful completion, and it is a 14-day format that fits the plan below. It is an independent programme, not connected to or endorsed by IACS.
Five steps to verify before you rely on an internship at IACS
- Ask your department office or programme coordinator in writing whether external or online internships are permitted during your programme, and request the relevant regulation or notice.
- Ask whether any internship carries credit or must be recorded on your transcript, and who signs off the evaluation.
- If you plan to test code your supervisor or lab wrote, get written permission before sharing data or code outside the lab.
- Check the official IACS website for the current programme list and syllabus, so you choose test topics that match your coursework.
- Confirm the academic calendar and break dates so your 14 days do not clash with examinations or lab commitments.
A 14-day plan for testing scientific code
| Days | Focus | Output |
|---|---|---|
| 1-2 | Choose a small open scientific or data-analysis program; read its documentation; set up the environment | Environment note with versions; list of functions to test |
| 3-4 | Find analytic and published reference cases | Reference table with provenance |
| 5-6 | Write reference-comparison tests with justified tolerances | First set of template rows |
| 7-8 | Add property, invariant and convergence checks | Property test list |
| 9-10 | Edge cases, bad input, units and NaN handling | Edge-case matrix with expected behaviour |
| 11 | Mutation exercise: break the code on a copy and confirm tests fail | Short note on which bugs were caught or missed |
| 12 | Regression baseline and rerun on a second environment | Frozen outputs; comparison across environments |
| 13 | Write defect reports and a validation summary | One-page report |
| 14 | Review, tidy and prepare a short presentation | Portfolio-ready repository |
How to report numerical defects so developers act on them
A report that says “the answer looks wrong” gets ignored. Include the exact input, the observed output, the expected output with its source, the size of the difference against your tolerance, and the environment. Suggest a minimal reproducing case. Separate three categories clearly: a definite bug (violates an analytic result), a precision concern (differs but within plausible method error), and a documentation gap (behaviour undefined for an edge case).
Frequently Asked Questions
What is the difference between verification and validation in scientific software?
Verification asks whether the code correctly solves the equations it claims to solve, using methods like analytic cases and convergence checks. Validation asks whether those equations describe reality, usually by comparing with experimental data. Most student testing projects focus on verification.
How do I pick a tolerance when I have no reference for the error?
Derive it from the method. Look at the solver’s stopping criterion, the precision of the input data and the conditioning of the problem. Start conservative, observe how much results vary across environments and seeds, then set the tolerance just above that natural variation and write the reasoning down.
Why does my test pass on one computer and fail on another?
Different library versions, processor instructions, compilers or parallel summation order can alter low-order digits. Record the environment, use tolerances instead of equality, and investigate any difference larger than your justified tolerance.
Can I use the code’s own output as the expected value?
Only for regression testing, and only after the output has been validated some other way. Otherwise the test just confirms that the code agrees with itself, including any existing error.
How do I test code that uses random numbers?
Fix and record the seed for repeatable regression tests. Then run many seeds and check that the mean, variance or other statistics fall within a few standard errors of the theoretical value.
What should I do if I find a likely bug in a research group’s code?
Reproduce it with the smallest possible input, document the expected value and its source, and report it privately to the code owner first. Do not share unpublished data or code publicly without permission.
Does a two-week testing project on scientific code make a useful portfolio piece?
Yes, if it shows a filled template, justified tolerances, a mutation exercise and a clear defect report. A short repository with those pieces demonstrates careful reasoning, which is the skill reviewers look for. The free two-week internship at CareerSwami gives a structure for producing such a piece, though outcomes depend on your own work.
Related Software Testing guides
- Lok Jagruti Kendra University Students: Test Case Review Checklist for Peer Feedback
- Central University of Kashmir Students: Handling Unreliable Internet During a Testing Internship
- Assam University Students: Choosing a Testing Specialisation Through a Two-Week Trial
- All Software Testing internship guides
Ready to put this into practice?
Join the free two-week CareerSwami online internship in Software Testing. The internship, the offer letter and the completion certificate are free.














