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

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.