Skip to content

Commit

Permalink
pedigree looking for child to root is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
vextorspace committed Jul 15, 2024
1 parent 70308b5 commit c91d2cf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package model.visitors

import model.Item

class PedigreeFinder(rootItem: Item) {
class PedigreeFinder(val rootItem: Item) {
private val familyTree = mutableListOf<Item>()

fun findPedigree(item: Item): List<Item> {
if(item != rootItem)
return emptyList()
return listOf(item)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package model.visitors

import io.kotest.matchers.collections.shouldBeEmpty
import io.kotest.matchers.collections.shouldContainExactly
import model.Item
import kotlin.test.Test
Expand All @@ -19,4 +20,19 @@ class PedigreeFinderTest {
pedigree.shouldContainExactly(root)
}

@Test
fun `looking for pedigree backwards returns empty list`() {
// Given
val root = Item("Root")
val child = Item("Child")
root.add(child)

val finder = PedigreeFinder(child)

// When
val pedigree = finder.findPedigree(root)

// Then
pedigree.shouldBeEmpty()
}
}

0 comments on commit c91d2cf

Please sign in to comment.