How to Test the Luhn Algorithm: Test Cases and Steps

Our Cards

Choose from any of our gift cards to give to your loved ones

related article

giftcardimage

Where to Use?

Redeem your gift cards at any of our Merchants

more on this topic

Where to Buy?

You can purchase a gift card from any of these locations

more on this topic

ABOUT US

about

What is ONYX GiftCards?

Onyx Gift Cards is a Grenadian company designed to introduce, market and manage gift cards systems in Grenada for retailers and corporations. We are enthusiastic about the effect and influence we will have on the local market. We intend to expand our systems regionally with a range of product offerings and services.

What is a Gift Card?

Gift cards are the preferred way of giving and receiving gifts. They carry a monetary value that can be redeemed for gifts at your favorite store.
Onyx GiftCards are “Open Gift Cards” which means that they can be redeemed at multiple merchant locations. They are standard credit card size, can fit into the average wallet and made of PVC plastic. Onyx GiftCards are Barcoded for security and safety for the consumer and bear a disclaimer at the back.
Onyx Giftcards can be bought with a branded Card backer which is black in colour and is designed to fit the card. There is an area to write a brief message to the recipient as well.

How it Works?

  • Buy an Onyx Gift Card at these local stores
  • Give your gift card to friends, family, co-workers, etc.
  • The recipient can shop at our select merchants nationwide
  • Your friends, family, co-workers, etc. will present their gift card at checkout to pay for your item(s)
  • They will walk away happy with the best gift ever...the gift of Choice

Why ONYX GiftCards?

  • Save TIME. No need to run around looking for the perfect gift
  • Redeem from a variety of business island-wide. We will continue adding businesses as fast as ONYX grows.
  • ONYX Gift Cards do not expire
  • Cards are valued at convinient amounts to meet every need and occasion

The fastest way to test a Luhn implementation is to run it against a fixed set of numbers with known outcomes: a few valid ones, the same numbers with one digit changed, and inputs that are not digits at all. If every case returns the expected result, the checksum logic is sound.

What the test has to prove

Luhn computes a check digit. Starting from the rightmost digit, it doubles every second digit, subtracts 9 from any result above 9, sums the digits, and checks that the total is a multiple of 10. Your tests should confirm that arithmetic and nothing more. Luhn catches typing errors. It does not prove a number was issued, is active, or belongs to anyone.

Prerequisites

Steps

  1. Create a test file with a list of inputs and expected booleans at the top, so the cases stay readable.
  2. Add one known-valid number. 79927398713 is the standard worked example.
  3. Add the invalid neighbours 79927398710 through 79927398719, expecting false for all except 79927398713.
  4. Add a second valid number from a different issuer range, such as 4242424242424242, to confirm the code handles varying lengths.
  5. Write a loop that changes each digit position in turn to every other digit and asserts that exactly one variant passes.
  6. Add a case with a leading zero, such as 0123456789, and verify the function treats it as a ten-digit string.
  7. Add a one-character input, 0, and decide whether it should pass. Document the choice in the test name.
  8. Add inputs containing spaces, hyphens, and letters. If the function strips separators, assert that behavior. If it rejects them, assert the rejection.
  9. Add empty string and null input, and assert that neither throws an unhandled exception.
  10. Add a property test: generate a random digit string of length 15, append the computed check digit, and assert that the result validates.
  11. Run the suite and confirm both the pass and fail branches are covered.

Edge cases worth a dedicated test

What a passing suite does not tell you

A green test run means the arithmetic matches the specification. It says nothing about whether a number is real, funded, or safe to charge. Treat the check as a formatting filter that runs before any real validation, and never as a security control.

Contact Us

Latest

Latest

new joker trailer url

Find the official new Joker trailer URL quickly: how to spot the real studio upload, what playback specs to expect, and how to skip mirror pages.

Read our complete guide: Should You Buy CVV From a Card Shop? The Honest Buyer's Guide