THINK FIRST·CODE LATER

← All labs

A tiny mutation-testing tool

Problem

Measure the strength of a test suite for StudyBuddy's pass rule:

A student passes if score >= 60 and attendance >= 75 (percent), or if score >= 90 (excellent score, whatever the attendance).

The original implementation is (score >= 60 && attendance >= 75) || score >= 90. Your program contains the original and these six mutants:

Mutant Code
M1 (score > 60 && attendance >= 75) || score >= 90
M2 (score >= 60 && attendance > 75) || score >= 90
M3 (score >= 60 || attendance >= 75) || score >= 90
M4 (score >= 60 && attendance >= 75) || score > 90
M5 (score >= 60 && attendance >= 75)
M6 (score >= 60 && attendance >= 75) && score >= 90

Input: test cases, one per line: score attendance expected (expected is true/false), until the end of input.

  1. First run every test on the original. If a test fails on the original, print Invalid test: score attendance expected for each such test and stop — a test that fails on correct code is itself wrong.
  2. Otherwise, for each mutant print M1: KILLED by test k (k = number of the first failing test, 1-based) or M1: SURVIVED.
  3. Print Mutation score: killed/6 (P%) with P = killed * 100 / 6 (integer division), and, if any mutant survived, Add tests for: M2, M4 (the survivors).

Input:

70 80 true
50 90 false
95 10 true

Output:

M1: SURVIVED
M2: SURVIVED
M3: KILLED by test 2
M4: SURVIVED
M5: KILLED by test 3
M6: KILLED by test 1
Mutation score: 3/6 (50%)
Add tests for: M1, M2, M4

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.

s9-1-data-1.txt

70 80 true
50 90 false
95 10 true
What your program must print for s9-1-data-1.txt
M1: SURVIVED
M2: SURVIVED
M3: KILLED by test 2
M4: SURVIVED
M5: KILLED by test 3
M6: KILLED by test 1
Mutation score: 3/6 (50%)
Add tests for: M1, M2, M4

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 < s9-1-data-1.txt

Windows PowerShell does not understand <:

Get-Content s9-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.