-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
125 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
oni/src/test/scala/org/mbari/oni/jdbc/ConceptRowSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright (c) Monterey Bay Aquarium Research Institute 2024 | ||
* | ||
* oni code is non-public software. Unauthorized copying of this file, | ||
* via any medium is strictly prohibited. Proprietary and confidential. | ||
*/ | ||
|
||
package org.mbari.oni.jdbc | ||
|
||
import java.time.Instant | ||
import org.mbari.oni.domain.ConceptNameTypes | ||
|
||
class ConceptRowSuite extends munit.FunSuite: | ||
test("ConceptRow constructor works as expected") { | ||
val now = Instant.now() | ||
val conceptRow = | ||
ConceptRow( | ||
1, | ||
None, | ||
"name", | ||
Some("rankLevel"), | ||
Some("rankName"), | ||
ConceptNameTypes.PRIMARY.getType, | ||
Instant.EPOCH, | ||
now | ||
) | ||
assertEquals(conceptRow.id, 1L) | ||
assertEquals(conceptRow.rank, Some("rankLevelrankName")) | ||
assertEquals(conceptRow.nameType, ConceptNameTypes.PRIMARY.getType) | ||
assertEquals(conceptRow.lastUpdate, now) | ||
} |
87 changes: 87 additions & 0 deletions
87
oni/src/test/scala/org/mbari/oni/jdbc/MutableConceptSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package org.mbari.oni.jdbc | ||
|
||
import org.mbari.oni.domain.ConceptNameTypes | ||
|
||
class MutableConceptSuite extends munit.FunSuite { | ||
|
||
|
||
/* | ||
1 - root, object | ||
`- 2 - child2 | ||
|- 4 - child4 | ||
| |- 8 - child8 | ||
| `- 9 - child9 | ||
| `- 10 - child10 | ||
`- 5 - child5 | ||
`- 3 - child3 | ||
|- 6 - child6 | ||
`- 7 - child7 | ||
*/ | ||
val rows = Seq( | ||
ConceptRow(1, None, "root"), | ||
ConceptRow(1, None, "object", nameType = ConceptNameTypes.ALTERNATE.getType), | ||
ConceptRow(2, Some(1), "child2"), | ||
ConceptRow(3, Some(1), "child3"), | ||
ConceptRow(4, Some(2), "child4"), | ||
ConceptRow(5, Some(2), "child5"), | ||
ConceptRow(6, Some(3), "child6"), | ||
ConceptRow(7, Some(3), "child7"), | ||
ConceptRow(8, Some(4), "child8"), | ||
ConceptRow(9, Some(4), "child9"), | ||
ConceptRow(10, Some(9), "child10") | ||
) | ||
|
||
test("toTree") { | ||
val (rootOpt, nodes) = MutableConcept.toTree(rows) | ||
assert(rootOpt.isDefined) | ||
val root = rootOpt.get | ||
assertEquals(root.id.get, 1L) | ||
assertEquals(root.children.size, 2) | ||
assertEquals(nodes.size, 10) | ||
assertEquals(root.primaryName, Some("root")) | ||
assertEquals(root.names.map(_.name).sorted, Seq("object", "root")) | ||
} | ||
|
||
test("root") { | ||
val (rootOpt, nodes) = MutableConcept.toTree(rows) | ||
val root = rootOpt.get | ||
val child2 = root.children.head | ||
val child4 = child2.children.head | ||
val child8 = child4.children.head | ||
val child9 = child4.children(1) | ||
val child5 = root.children(1) | ||
val child3 = root.children(1) | ||
val child6 = child3.children.head | ||
val child7 = child3.children(1) | ||
assertEquals(child8.root().id.get, 1L) | ||
assertEquals(child9.root().id.get, 1L) | ||
assertEquals(child5.root().id.get, 1L) | ||
assertEquals(child6.root().id.get, 1L) | ||
assertEquals(child7.root().id.get, 1L) | ||
} | ||
|
||
test("copyUp") { | ||
val (rootOpt, nodes) = MutableConcept.toTree(rows) | ||
val child9 = nodes.find(_.id.get == 9).get | ||
val child9Copy = child9.copyUp() | ||
assertEquals(child9Copy.id, child9.id) | ||
assertEquals(child9Copy.rank, child9.rank) | ||
assertEquals(child9Copy.names, child9.names) | ||
assertEquals(child9Copy.children, Nil) | ||
assertEquals(child9Copy.parent.get.id, child9.parent.get.id) | ||
assertEquals(child9Copy.root().id.get, 1L) | ||
} | ||
|
||
test("toImmutable") { | ||
val (rootOpt, nodes) = MutableConcept.toTree(rows) | ||
val root = rootOpt.get | ||
val concept = root.toImmutable | ||
assertEquals(concept.name, "root") | ||
assertEquals(concept.rank, None) | ||
assertEquals(concept.alternativeNames, Seq("object")) | ||
assertEquals(concept.children.size, 2) | ||
assertEquals(concept.children.head.name, "child2") | ||
assertEquals(concept.children(1).name, "child3") | ||
} | ||
|
||
} |