THINK FIRST·CODE LATER

← All labs

Boundary-value test generator

Problem

Generate boundary-value tests for integer input fields.

Input: lines field min max until the end of input (the valid range is min..max, inclusive, min < max).

For each field print the field name followed by the test values, each with its expected classification, in this order: min-1, min, min+1, a nominal value (min + max) / 2 (integer division), max-1, max, max+1. Skip a value if it is equal to one already printed for this field (e.g., when the range is small). Format:

field:
  value -> VALID|INVALID

At the end print Total: t tests (v valid, i invalid).

Input:

titleLength 5 100
groupSize 2 6

Output:

titleLength:
  4 -> INVALID
  5 -> VALID
  6 -> VALID
  52 -> VALID
  99 -> VALID
  100 -> VALID
  101 -> INVALID
groupSize:
  1 -> INVALID
  2 -> VALID
  3 -> VALID
  4 -> VALID
  5 -> VALID
  6 -> VALID
  7 -> INVALID
Total: 14 tests (10 valid, 4 invalid)

Data for this lab

Your program reads its data from standard input. Download the file, then give it to your program as shown below. Start with data set 1: its expected output is given.

s8-1-data-1.txt

titleLength 5 100
groupSize 2 6
What your program must print for s8-1-data-1.txt
titleLength:
  4 -> INVALID
  5 -> VALID
  6 -> VALID
  52 -> VALID
  99 -> VALID
  100 -> VALID
  101 -> INVALID
groupSize:
  1 -> INVALID
  2 -> VALID
  3 -> VALID
  4 -> VALID
  5 -> VALID
  6 -> VALID
  7 -> INVALID
Total: 14 tests (10 valid, 4 invalid)

Run your program first, then open this and compare line by line: your output must contain these lines exactly.

How to give the file to my program

Terminal (macOS, Linux, or Windows Command Prompt), after compiling:

java Main < s8-1-data-1.txt

Windows PowerShell does not understand <:

Get-Content s8-1-data-1.txt | java Main

IntelliJ IDEA: Run → Edit Configurations → Redirect input from. Or simply paste the content of the file into the console when the program waits for input.

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.