File tree Expand file tree Collapse file tree 2 files changed +40
-1
lines changed
main/kotlin/org/utbot/summary/clustering
test/kotlin/org/utbot/summary/clustering Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,9 @@ class ExecutionMetric : Metric<Iterable<Step>> {
99 * Minimum Edit Distance
1010 */
1111 private fun compareTwoPaths (path1 : Iterable <Step >, path2 : Iterable <Step >): Double {
12+ require(path1.count() > 0 ) { " Two paths can not be compared: path1 is empty!" }
13+ require(path2.count() > 0 ) { " Two paths can not be compared: path2 is empty!" }
14+
1215 val distances = Array (path1.count()) { i -> Array (path2.count()) { j -> i + j } }
1316
1417 for (i in 1 until path1.count()) {
@@ -22,7 +25,17 @@ class ExecutionMetric : Metric<Iterable<Step>> {
2225 distances[i][j] = minOf(d1, d2, d3)
2326 }
2427 }
25- return distances.last().last().toDouble()
28+
29+ if (distances.isNotEmpty()) {
30+ val last = distances.last()
31+ if (last.isNotEmpty()) {
32+ return last.last().toDouble()
33+ } else {
34+ throw IllegalStateException (" Last row in the distance matrix has 0 columns. It should contain more or equal 1 column." )
35+ }
36+ } else {
37+ throw IllegalStateException (" Distance matrix has 0 rows. It should contain more or equal 1 row." )
38+ }
2639 }
2740
2841 private fun distance (stmt1 : Step , stmt2 : Step ): Int {
Original file line number Diff line number Diff line change 1+ package org.utbot.summary.clustering
2+
3+ import org.junit.jupiter.api.Assertions
4+ import org.junit.jupiter.api.Test
5+
6+ import org.utbot.framework.plugin.api.Step
7+ import java.lang.IllegalArgumentException
8+
9+ internal class ExecutionMetricTest {
10+ @Test
11+ fun computeWithTwoEmptySteps () {
12+ val executionMetric = ExecutionMetric ()
13+ val object1 = listOf<Step >()
14+ val object2 = listOf<Step >()
15+
16+
17+ val exception = Assertions .assertThrows(IllegalArgumentException ::class .java) {
18+ executionMetric.compute(object1 = object1, object2 = object2)
19+ }
20+
21+ Assertions .assertEquals(
22+ " Two paths can not be compared: path1 is empty!" ,
23+ exception.message
24+ )
25+ }
26+ }
You can’t perform that action at this time.
0 commit comments