ruler-triangleThe Triangle

This page offers the most thorough testing solution to the classic "Triangle Testing Challenge" you will find on the internet! (as of February 2026) It also shows the thinking behind the gradual construction of the test suite.

circle-check

Requirements: Takes three integers representing the lengths of the sides of a triangle and tells you if it is:

  • Equilateral: all sides are equal,

  • Isosceles: 2 equal sides, or

  • Scalene: no equal sides

If the input is invalid in any way, the program must print "Invalid triangle".

There are two common challenge variations:

  1. The program is a command-line tool

  2. The program is a browser app with 3 input boxes

Both variations offer different additional scenarios, but let's go with (1) the command-line tool to avoid considerations related to browser web testing.

The AI illusion

"I can just prompt AI, and it will write test cases for me".

And indeed, this is a sample of what Google Gemini produced to a simple prompt about the triangle challenge:

The "Trap": While it sounds easy, most people miss critical edge cases, such as: Invalid Triangles: Sides like (1, 2, 4) where the sum of two sides is not greater than the third. Zeros or Negatives: Inputs like (0, 0, 0) or (-1, 5, 5). Non-Integer Inputs: Entering decimals, letters, or leaving fields blank. Boundary Values: Very large numbers or values right on the edge of validity (e.g., 3, 4, 7).

Is this enough? Are all edge cases covered?

Just like with anything, if you're not qualified to review AI output, how can you have confidence in the coverage offered by AI? The more you know, the more qualified you are. So let's see how the above AI output can be drastically improved.

Non-exhaustive solution

Asking questions

For practically any challenge, it's a good habit to read the requirement carefully, think through the problem, and ASK QUESTIONS. You may or may not get clarifications, but at least it helps test your own assumptions.

This solution does not frontload all the questions, but instead introduces them as it progresses.

The most obvious explicit variable is the input.

  • Integers: if it said "Numbers", we'd have a lot more testing to do with valid decimal number combinations, but it's useful to at least use decimal numbers as one of invalid inputs.

Bare minimum testing

Input
Expected result

1, 1, 1

Equilateral

5, 5, 8

Isosceles

5, 6, 8

Scalene

0, 1, 1

Invalid

All branches (and outputs) have been covered at least once.

Discovering implicit requirements

The requirements fail to explicitly mention the fundamental triangle inequality rule, which one should discover as part of the analysis:

  • For any triangle, the sum of the lengths of any two sides must be strictly greater than the length of the third side

  • Upon further research, you should find out that there's a degenerate triangle - a completely flat triangle with all points on a straight line

For sides a,b, and c, this rule can then be expressed as:

Normal Triangles
Degenerate Triangles considered

a + b > c a + c > b b + c > a

a + b ≥ c a + c ≥ b b + c ≥ a

This is the time to ask your Business Analyst how to treat this difference. There are at least three options:

  • Consider degenerate triangles as invalid

  • Consider degenerate triangles as valid

  • Introduce NEW output(s), e.g.,

    • "Degenerate triangle" for any set of otherwise valid inputs

    • "Degenerate scalene"

    • "Degenerate isosceles"

For the sake of the exercise, let's pick the simpler "consider degenerate triangles as invalid". We therefore adhere to the left column above (with > sign).

This can be tested exhaustively together with all isosceles permutations. To be efficient, we should also pick integers that test the > at the border, e.g., 5 + 5 > 9 tests at the "border". Changing any 5 to 4 will make the triangle degenerate.

Input
Expected result

9, 5, 5

Isosceles (border value)

5, 9, 5

Isosceles (border value)

5, 5, 9

Isosceles (border value; slightly more valuable than 5,5,8)

Also tests for degenerate triangle permutation with border values.

Input
Expected result

10, 5, 5

Invalid (degenerate)

5, 10, 5

Invalid (degenerate)

5, 5, 10

Invalid (degenerate)

Invalid values

Start with invalid integer combinations or values

Input
Expected result

1, 2, 4

Invalid (sum of two sides less than the third side)

0, 0, 0

Invalid (mustn’t output equilateral)

-1, -1, -1

Invalid (mustn’t output equilateral)

Outside of integers, there's a plethora of characters - letters, non-alphabetical characters, numbers with decimals, non-English characters from other languages (Chinese, Arabic, Hindi, etc.), emojis, etc. We want to be practical and avoid test count and combinatorial explosion.

Let's remember where the numbers are in the ASCII table:

ASCII position
Symbol

47

/

48

0

49

1

50

2

51

3

52

4

53

5

54

6

55

7

56

8

57

9

58

:

We can use the Elementary Comparison technique to "spread" out invalid values across all three inputs.

Input
Expected result

Decimal

3.5, 5, 5

Invalid (decimal, sides must be integers)

5, 0.99, 5

Invalid (decimal, sides must be integers)

5, 5, 1.00000000000000001

Invalid (decimal, sides must be integers)

Non-numbers

/, 10, 10

Invalid (code point 47, just below 0)

10, :, 10

Invalid (code point 58, just above 9)

10, 10, 🚀

Invalid (a typical emoji is 4 bytes; non-numeric input)

Invalid input count

The program expects exactly 3 inputs. This is where we start creating tests with "questions to ask" instead of Expected Results.

Input
Expected result

Two inputs

Invalid triangle?

Four inputs

4th input is ignored? Entire input rReject with a special message?

10 million inputs

(Programming knowledge required) What if the first thing that the program does is store all inputs into an array and checks the length of the array? In such a case, the program might crash by hitting an "Out Of Memory Error" by trying to allocate too much contiguous memory.

Technical Gauging

(Programming knowledge required)

What are the limits of the "integer"? Is it meant as a non-decimal number, or does it specify the type at the level of a programming language? Is the input stored in a byte, short, int, long or something even bigger? See EP & BVA: Special Technical Numerical Valuesarrow-up-right section for potential MAX values that the program might process.

Just knowing the programming language and the variable type used to store the input would greatly help in writing non-redundant tests. Let's assume a 64-bit int for now, referenced as MAX_INT in tests.

Input
Expected result

MAX_INT + 1, 5, 5

Invalid?

5, MAX_INT + 1, 5, 5

Invalid?

5, MAX_INT + 1

Invalid?

Bonus question to ask: Does the program understand scientific notation? If so, more valid and invalid inputs can be used for further testing. See UI Test Catalog: Numbers section.

Usability

Explaining the reason for the error sometimes adds value to the user experience. "Invalid triangle"? Why? Some specific input is invalid? Missing input? Sum of two sides not equal to the third? Which check failed? Consider explaining why to the user so that they can correct the input.

Assessing the product with SFDIPOT

Beyond the input-output checking, we could test the tool's portability, installability, and so forth. The SFDIPOT mnemonic can be used to explore and test the program further.

chevron-rightSFDIPOT applied to the triangle softwarehashtag

Structure

  • How is the product distributed and how is it installed (single binary, script, package)?

  • Is there accompanying documentation or "help" manual? Is it complete, accurate, and written in a way that is clear to the end user?

Function

  • Business rules: valid triangle constraints (sum of 2 side lengths > length of 3rd side, valid and invalid inputs, etc.)

  • Multi-user: how will it behave when run by many users from many shells? What if it's invoked by other programs making many simultaneous calls?

  • Error Handling: If the user provides invalid values, is "Output: Invalid" really enough? Should we improve the program to output the reason why the triangle is invalid?

  • Any way to exit the app without force-closing it?

Data

  • Does the product output data to the terminal only? Or can it take extra arguments and save to a file or other? If so, all the usual file handling questions arise.

Interfaces

  • Are the triangle formulas hard-coded into code, or are they pulled from disk or network? If so, this leads to many corresponding questions - what if the file is not there, what if the file is locked, what if the remote request fails, etc.

Platform

  • What OS can the software run on? Windows, MacOs, Linux? What versions are supported?

  • What is the tech stack of the product?

    • Java? What version? What is the minimum JRE (Java Runtime Environment) version that the client machine must have? Do we assume the client machine has it already?

    • Similar questions if the software is written in C#(.NET), Python, or other languages

  • Does it work consistently across all supported shells (Bash, PowerShell, zsh) ?

  • Could the product be blocked during or after installation by an antivirus or another process?

Operations

  • Can the product itself, or some of its operations, be restricted to a user role (admin, guest, other)?

Time

  • How fast is the response? What is the slowest acceptable response time? How will it perform with 99% or 100% memory or disk usage?

  • What if you launch it and leave it for hours or days? Does it time out or leak resources?

Bonus testing

If the requirement said "Numbers", this would lead to more discovery and testing, because decimal numbers are now potentially in play (e.g., 3.15). This will include testing for:

  • equality for tiny differences, for example, only after the 18th digit after the decimal point.

  • sum such as 0.1 + 0.2, potentially not being strictly equal to 0.3

See Floating-point arithmetic to discover more.

Summary

A seemingly trivial program requires non-trivial knowledge and skills.

Having said that, the flaw of the above solution is that it does not (seem to) follow a structured, systematic approach. Equivalence classes for each input are not established, and test models that could serve as a basis for a structured test case creation are not established.

On the other hand, a full critical review of requirements and creation of formal "complete" test models (or test plans) may not be an option in fast-moving, iterative development environments.

For the sake of a testing exercise, the approach on this page may be considered as good enough.

Resources

  • UI triangle app: https://www.mathwarehouse.com/triangle-calculator/online.php

  • Triangle exercise: https://baseinfinity.github.io/triangle-exercise/

Last updated