| 1 | package com.github.sanity.pav | |
| 2 | ||
| 3 | import java.util.* | |
| 4 | ||
| 5 | /** | |
| 6 | * Created by ian on 12/8/16. | |
| 7 | */ | |
| 8 | ||
| 9 | fun DoubleArray.betterBinarySearch(v: Double): BinarySearchResult { | |
| 10 |
4
1. betterBinarySearch : changed conditional boundary → KILLED 2. betterBinarySearch : changed conditional boundary → KILLED 3. betterBinarySearch : negated conditional → KILLED 4. betterBinarySearch : negated conditional → KILLED |
if (v < this.first() || v > this.last()) { |
| 11 | throw IllegalArgumentException("v ($v) is outside range of DoubleArray (${this.first()}0${this.last()})") | |
| 12 | } | |
| 13 | val result = this.binarySearch(v) | |
| 14 |
1
1. betterBinarySearch : mutated return of Object value for com/github/sanity/pav/UtilitiesKt::betterBinarySearch to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return toBinarySearchResult(result) |
| 15 | } | |
| 16 | ||
| 17 |
1
1. betterBinarySearch : mutated return of Object value for com/github/sanity/pav/UtilitiesKt::betterBinarySearch to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
fun <T> List<T>.betterBinarySearch(v: T, comparator: Comparator<T>) = toBinarySearchResult(this.binarySearch(v, comparator)) |
| 18 | ||
| 19 | fun <T> List<T>.toArrayList(): ArrayList<T> { | |
| 20 |
2
1. toArrayList : negated conditional → KILLED 2. toArrayList : mutated return of Object value for com/github/sanity/pav/UtilitiesKt::toArrayList to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return if (this is ArrayList) { |
| 21 | this | |
| 22 | } else { | |
| 23 | val r = ArrayList<T>() | |
| 24 | r.addAll(this) | |
| 25 | r | |
| 26 | } | |
| 27 | } | |
| 28 | ||
| 29 | sealed class BinarySearchResult { | |
| 30 |
1
1. getIndex : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
class Exact(val index: Int) : BinarySearchResult() { |
| 31 | override fun equals(other: Any?): Boolean { | |
| 32 |
2
1. equals : negated conditional → KILLED 2. equals : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return if (other is Exact) { |
| 33 |
1
1. equals : negated conditional → KILLED |
index == other.index |
| 34 | } else { | |
| 35 | false | |
| 36 | } | |
| 37 | } | |
| 38 | ||
| 39 | override fun toString(): String { | |
| 40 |
1
1. toString : mutated return of Object value for com/github/sanity/pav/BinarySearchResult$Exact::toString to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return "Exact($index)" |
| 41 | } | |
| 42 | } | |
| 43 |
2
1. getHighIndex : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED 2. getLowIndex : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
class Between(val lowIndex: Int, val highIndex: Int) : BinarySearchResult() { |
| 44 | override fun equals(other: Any?): Boolean { | |
| 45 |
2
1. equals : negated conditional → KILLED 2. equals : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return if (other is Between) { |
| 46 |
2
1. equals : negated conditional → KILLED 2. equals : negated conditional → KILLED |
lowIndex == other.lowIndex && highIndex == other.highIndex |
| 47 | } else { | |
| 48 | false | |
| 49 | } | |
| 50 | } | |
| 51 | ||
| 52 | override fun toString(): String { | |
| 53 |
1
1. toString : mutated return of Object value for com/github/sanity/pav/BinarySearchResult$Between::toString to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return "Between($lowIndex, $highIndex)" |
| 54 | } | |
| 55 | } | |
| 56 | } | |
| 57 | ||
| 58 | ||
| 59 | private fun toBinarySearchResult(result: Int): BinarySearchResult { | |
| 60 |
3
1. toBinarySearchResult : changed conditional boundary → KILLED 2. toBinarySearchResult : negated conditional → KILLED 3. toBinarySearchResult : mutated return of Object value for com/github/sanity/pav/UtilitiesKt::toBinarySearchResult to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return if (result >= 0) { |
| 61 | BinarySearchResult.Exact(result) | |
| 62 | } else { | |
| 63 |
2
1. toBinarySearchResult : removed negation → KILLED 2. toBinarySearchResult : Replaced integer subtraction with addition → KILLED |
val insertionPoint = -result - 1 |
| 64 |
1
1. toBinarySearchResult : Replaced integer subtraction with addition → KILLED |
BinarySearchResult.Between(insertionPoint - 1, insertionPoint) |
| 65 | } | |
| 66 | } | |
Mutations | ||
| 10 |
1.1 2.2 3.3 4.4 |
|
| 14 |
1.1 |
|
| 17 |
1.1 |
|
| 20 |
1.1 2.2 |
|
| 30 |
1.1 |
|
| 32 |
1.1 2.2 |
|
| 33 |
1.1 |
|
| 40 |
1.1 |
|
| 43 |
1.1 2.2 |
|
| 45 |
1.1 2.2 |
|
| 46 |
1.1 2.2 |
|
| 53 |
1.1 |
|
| 60 |
1.1 2.2 3.3 |
|
| 63 |
1.1 2.2 |
|
| 64 |
1.1 |