Math Adventures/Triangle Test Cases/Test Cases

To ensure that the program correctly identifies whether the given lengths can form a triangle, we need to test various scenarios, including valid triangles, invalid triangles, and edge cases.[1] The comprehensive set of test cases should cover different types of triangles (equilateral, isosceles, and scalene), as well as scenarios where the input lengths do not form a triangle. Here is a comprehensive set of test cases:

Test Cases

  1. Valid Triangles (All types):
    • Equilateral Triangle:
      • Input: (3, 3, 3)
      • Output: "Is a triangle"
    • Isosceles Triangle:
      • Input: (5, 5, 8)
      • Output: "Is a triangle"
      • Input: (7, 7, 7)
      • Output: "Is a triangle"
    • Scalene Triangle:
      • Input: (3, 4, 5)
      • Output: "Is a triangle"
      • Input: (6, 8, 10)
      • Output: "Is a triangle"
  2. Invalid Triangles (Sum of two sides not greater than the third):
    • Input: (1, 2, 3)
      • Output: "Is not a triangle"
    • Input: (5, 1, 1)
      • Output: "Is not a triangle"
    • Input: (10, 2, 7)
      • Output: "Is not a triangle"
  3. Edge Cases:
    • Zero Length:
      • Input: (0, 5, 5)
      • Output: "Is not a triangle"
    • Negative Length:
      • Input: (-3, 4, 5)
      • Output: "Is not a triangle"
      • Input: (-1, -1, -1)
      • Output: "Is not a triangle"
    • Very Large Numbers:
      • Input: (1000000, 1000001, 1000002)
      • Output: "Is a triangle"
    • Floating Point Precision:
      • Input: (0.1, 0.1, 0.1)
      • Output: "Is a triangle"
      • Input: (0.1, 0.2, 0.3)
      • Output: "Is not a triangle"
  4. Boundary Cases:
    • Minimum Boundary for forming a triangle:
      • Input: (1, 1, 1.9999999999999998)
      • Output: "Is a triangle" (just barely a triangle due to floating point precision)
      • Input: (1, 1, 2)
      • Output: "Is not a triangle"
    • Sides forming a degenerate triangle (where sum of two sides equals the third):
      • Input: (1, 2, 3)
      • Output: "Is not a triangle"
      • Input: (2, 2, 4)
      • Output: "Is not a triangle"
  5. Mixed Valid and Invalid Inputs:
    • Input: (1, 1, 2.0000000001)
      • Output: "Is a triangle" (floating point precision just makes it a triangle)
    • Input: (100, 1, 1)
      • Output: "Is not a triangle"

Summary

  • Valid Triangles: Include a variety of equilateral, isosceles, and scalene triangles.
  • Invalid Triangles: Include cases where the sum of any two sides is not greater than the third side.
  • Edge Cases: Cover zero, negative, very large numbers, and floating-point precision issues.
  • Boundary Cases: Test the minimum boundary conditions and degenerate triangles.
  • Mixed Cases: Ensure mixed scenarios of almost valid/invalid triangles are covered.


These test cases ensure comprehensive coverage of different scenarios to verify the program's correctness in identifying valid and invalid triangles.

  1. ChatGPT generated this text responding to the prompt: “A program accepts 3 numbers representing the lengths of each side of a triangle as input and responds with ‘Is a triangle’ or ‘Is not a triangle’ as output. Generate a comprehensive set of test cases”