Skip to content

Commit

Permalink
test: 💍 add test for shared functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Xanonymous-GitHub committed Jul 25, 2024
1 parent 0d47583 commit 20d96b0
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions core/src/test/kotlin/SharedFunctionTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import org.junit.jupiter.api.parallel.Execution
import org.junit.jupiter.api.parallel.ExecutionMode
import tw.xcc.gumtree.matchers.comparator.calculateDiceValue
import tw.xcc.gumtree.matchers.comparator.hasSameParent
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue

@Execution(ExecutionMode.CONCURRENT)
internal class SharedFunctionTest {
@Test
fun `test dice function`() {
val sizeA = 298347
val sizeB = 182764
val theirIntersectionSize = 67323

val expectDice = 0.2798647297609076
val actualDice = calculateDiceValue(theirIntersectionSize, sizeA, sizeB)

assertEquals(expectDice, actualDice, 0.0001)
}

@Test
fun `test dice function with zero size`() {
val sizeA = 0
val sizeB = 0
val theirIntersectionSize = 0

val expectDice = 1.0
val actualDice = calculateDiceValue(theirIntersectionSize, sizeA, sizeB)

assertEquals(expectDice, actualDice, 0.0001)
}

@Test
fun `test dice function with zero intersection`() {
val sizeA = 298347
val sizeB = 182764
val theirIntersectionSize = 0

val expectDice = 0.0
val actualDice = calculateDiceValue(theirIntersectionSize, sizeA, sizeB)

assertEquals(expectDice, actualDice, 0.0001)
}

@Test
fun `test has same parent`() {
val parent = FakeTinnyTree()
val child1 = FakeTinnyTree().also { it.setParentTo(parent) }
val child2 = FakeTinnyTree().also { it.setParentTo(parent) }
val child3 = FakeTinnyTree().also { it.setParentTo(parent) }
val child4 = FakeTinnyTree().also { it.setParentTo(parent) }

val m1 = child1 to child2
val m2 = child3 to child4

val actualResult = hasSameParent(m1, m2)

assertTrue(actualResult)
}
}

0 comments on commit 20d96b0

Please sign in to comment.