Deny cyclic FSFolders #3

Merged
cyclane merged 2 commits from explicit-cyclic-logic into main 2024-01-07 14:56:17 +00:00
1 changed files with 42 additions and 0 deletions
Showing only changes of commit e53d96a74b - Show all commits

View File

@ -0,0 +1,42 @@
package filesystem
import org.junit.jupiter.api.Test
import kotlin.test.assertFalse
import kotlin.test.assertTrue
class FSEntryTest {
@Test
fun `non-cyclic folder`() {
val folder =
FSFolder(
"folder",
listOf(
FSFolder("folder", listOf()),
FSFile("text.txt", "Hello!"),
),
)
assertFalse(folder.isCyclic())
}
@Test
fun `cyclic folder`() {
val files = mutableListOf<FSEntry>()
val folder = FSFolder("folder", files)
files.add(folder)
assertTrue(folder.isCyclic())
}
@Test
fun `long cyclic folder`() {
val files = mutableListOf<FSEntry>()
val folder1 = FSFolder("folder", files)
val folder2 = FSFolder("folder2", listOf(folder1))
val folder3 = FSFolder("folder3", listOf(folder2))
val folder4 = FSFolder("folder4", listOf(folder3))
files.add(folder4)
assertTrue(folder1.isCyclic())
assertTrue(folder2.isCyclic())
assertTrue(folder3.isCyclic())
assertTrue(folder4.isCyclic())
}
}