import spock.lang.* class IdenticalPairsSpecification extends Specification { def solution = new IdenticalPairs() @Unroll @TweakSequence( sequenceParameterName = "A" ) def "#iterationCount: result given input #A is #x"() { expect: solution.solution( A ) == x where: x | A 0 | [ ] 0 | [ 1 ] 0 | [ 3 ] 0 | [ 1, 2 ] 0 | [ 1, 2 ] 0 | [ 1, 3 ] 0 | [ 2, 3 ] 1 | [ 1, 1 ] 0 | [ 1, 2, 3 ] 1 | [ 1, 2, 1 ] 3 | [ 2, 2, 2 ] 4 | [ 2, 2, 2, 1, 1 ] 4 | [ 3, 5, 6, 3, 3, 5 ] 11 | [ 3, 5, 6, 3, 3, 5, 3, 3 ] 0 | [ 2, 3, 1, 5 ] 0 | [ 2, 3, 4, 1 ] 0 | [ -1_000_000_000, 3, 4, 1, 1_000_000_000 ] } @Unroll @TweakSequence def "#iterationCount: result is the expected #result"() { expect: solution.solution( sequence ) == result where: result | sequence | indexReplacements 10 | [ 1 ] * 5 | [ : ] 9 | [ 1, 2, 3 ] * 3 | [ : ] 18 | [ 1, 2, 3 ] * 4 | [ : ] 15 | [ 1, 2, 3, 4, 5 ] * 3 | [ : ] 50 | [ 1, 2, 3, 4, 5 ] * 5 | [ : ] 49995000 | [ 1 ] * 10_000 | [ : ] 1_000_000_000 | [ range: [ start: 0, end: 20, repeat: 10_000 ] ] | [ : ] 1_000_000_000 | [ range: [ start: -10, end: 10, repeat: 10_000 ] ] | [ : ] 1_000_000_000 | [ range: [ start: -10, end: 10, repeat: 9_999 ] ] | [ : ] 0 | [ range: [ start: 50_000, end: -49_999 ] ] | [ : ] 1 | [ range: [ start: 50_000, end: -49_999 ] ] | [ 0: 0 ] 5 | [ range: [ start: 50_000, end: -49_999 ] ] | [ 0: 0, 100: 1, 200: 2, 30_000: 3, 70_000: 4 ] 21 | [ range: [ start: 50_000, end: -49_999 ] ] | [ 0: 0, 100: 0, 200: 0, 30_000: 0, 70_000: 0, 90_000: 0 ] } }