Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
bce53e6
test: add table information about coverage of each classes at library…
IlyaSuponev Apr 8, 2024
052e2bc
refactor: update format of coverage information
IlyaSuponev Apr 8, 2024
68ece3f
refactor: update test gradle task and change logging of it. Update in…
IlyaSuponev Apr 8, 2024
1a493ec
test: add test result printer to terminal and add run cmd at action w…
IlyaSuponev Apr 9, 2024
1a1a6c4
fix: update yml-script to continue execution on error at execution tests
IlyaSuponev Apr 9, 2024
a541b27
Update build-test.yml by change tasks line init
IlyaSuponev Apr 9, 2024
e299d15
fix: update build-test.yml to contiue on error at tests runtime(test …
IlyaSuponev Apr 9, 2024
3c5420b
refactor: update test result printer test
IlyaSuponev Apr 9, 2024
87b88fa
refactor: update yml-script to more-continue on error at same steps o…
IlyaSuponev Apr 9, 2024
410fdc3
test: add colorize output of tests result printer
IlyaSuponev Apr 9, 2024
cc7f891
test: add colorize output of tests coverage printer
IlyaSuponev Apr 9, 2024
2b6c419
refactor: set yml-script result checking of execution test task
IlyaSuponev Apr 9, 2024
9f52cf3
refactor: delete test that always crashes, used to check the output o…
IlyaSuponev Apr 9, 2024
e1956c7
refactor: update yml-script to minimaize checking of tests execution.…
IlyaSuponev Apr 9, 2024
092b89d
refactor: split display_test function into two parse_test_result and …
IlyaSuponev Apr 9, 2024
2185545
refactor: update names of steps at yml-script
IlyaSuponev Apr 9, 2024
054d6f8
test: update python-script for displaying test results and update it …
IlyaSuponev Apr 9, 2024
8a0b4ed
refactor: remove unnecessary variable type declarations
IlyaSuponev Apr 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,18 @@ jobs:
- name: Build source code
run: ./gradlew build -x test

- name: Run tests with jacoco
run: ./gradlew test
- name: Run tests
run: ./gradlew test >./test-res-out.log 2>./test-res-err.log
continue-on-error: true

- name: Display test results
run: python3 ./scripts/test-result-printer.py --dir ./lib/build/test-results/test --all-failures

- name: Run jacoco coverage report
run: ./gradlew jacocoTestReport >./test-res-out.log 2>./test-res-err.log

- name: Display info about coverage
run: python3 ./scripts/csv-reports-printer.py --input ./lib/build/reports/jacoco/info.csv --lib lib

- name: Clear tmpfiles of runnig tests
run: rm ./test-res-out.log && rm ./test-res-err.log
34 changes: 12 additions & 22 deletions lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ plugins {

// Code coverage plugin
jacoco

// Output project coverage
id("org.barfuin.gradle.jacocolog") version "3.1.0"
}

repositories {
Expand All @@ -17,6 +14,8 @@ repositories {
dependencies {
// This dependency is exported to consumers, that is to say found on their compile classpath.
api(libs.commons.math3)
// https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5")
// https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-params
testImplementation("org.junit.jupiter:junit-jupiter-params:5.10.2")
// This dependency is used internally, and not exposed to consumers on their own compile classpath.
Expand All @@ -30,32 +29,23 @@ java {
}
}

testing {
suites {
// Configure the built-in test suite
val test by getting(JvmTestSuite::class) {
// Use Kotlin Test framework
useKotlinTest("1.9.20")
}
}
}

tasks.named<Test>("test") {
useJUnitPlatform()
finalizedBy(tasks.jacocoTestReport)
}

tasks.withType<Test> {
testLogging {
events("PASSED", "SKIPPED", "FAILED")
showCauses = false
showStackTraces = false
showExceptions = false
}
}

tasks.named<JacocoReport>("jacocoTestReport") {
dependsOn(tasks.test)
val sep = File.separator
val jacocoReportsDirName = "reports${sep}jacoco"
reports {
csv.required = false
csv.required = true
xml.required = false
html.outputLocation = layout.buildDirectory.dir("jacocoHtml")
html.required = true
csv.outputLocation = layout.buildDirectory.file("${jacocoReportsDirName}${sep}info.csv")
html.outputLocation = layout.buildDirectory.dir("${jacocoReportsDirName}${sep}html")
}
}
}
30 changes: 15 additions & 15 deletions lib/src/main/kotlin/tree_tripper/binary_trees/RBTree.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public open class RBTree<K: Comparable<K>, V>: AbstractBSTree<K, V, RBTreeNode<K

val removeResult: Pair<RBTreeNode<K, V>?, V?>
var resultCompare: Int = key.compareTo(node.key)
var nodeCurrent: RBTreeNode<K, V> = node
var nodeCurrent = node
if (resultCompare < 0) {
if (!isRedColor(nodeCurrent.leftChild) && !isRedLeftChild(nodeCurrent.leftChild))
nodeCurrent = moveRedLeft(nodeCurrent)
Expand Down Expand Up @@ -105,13 +105,13 @@ public open class RBTree<K: Comparable<K>, V>: AbstractBSTree<K, V, RBTreeNode<K
* otherwise `node` switches places with the right child
*/
protected fun rotateLeft(node: RBTreeNode<K, V>): RBTreeNode<K, V> {
val rightChild: RBTreeNode<K, V> = node.rightChild ?: return node
node.rightChild = rightChild.leftChild
rightChild.leftChild = node
val nodeSwapped: RBTreeNode<K, V> = node.rightChild ?: return node
node.rightChild = nodeSwapped.leftChild
nodeSwapped.leftChild = node

rightChild.isRed = node.isRed
nodeSwapped.isRed = node.isRed
node.isRed = true
return rightChild
return nodeSwapped
}

/**
Expand All @@ -122,13 +122,13 @@ public open class RBTree<K: Comparable<K>, V>: AbstractBSTree<K, V, RBTreeNode<K
* otherwise `node` switches places with the left child
*/
protected fun rotateRight(node: RBTreeNode<K, V>): RBTreeNode<K, V> {
val leftChild: RBTreeNode<K, V> = node.leftChild ?: return node
node.leftChild = leftChild.rightChild
leftChild.rightChild = node
val nodeSwapped: RBTreeNode<K, V> = node.leftChild ?: return node
node.leftChild = nodeSwapped.rightChild
nodeSwapped.rightChild = node

leftChild.isRed = node.isRed
nodeSwapped.isRed = node.isRed
node.isRed = true
return leftChild
return nodeSwapped
}

/**
Expand All @@ -151,7 +151,7 @@ public open class RBTree<K: Comparable<K>, V>: AbstractBSTree<K, V, RBTreeNode<K
*/
protected fun moveRedRight(node: RBTreeNode<K, V>): RBTreeNode<K, V> {
if (node.rightChild == null) return node
var nodeCurrent: RBTreeNode<K, V> = node
var nodeCurrent = node

flipColors(nodeCurrent)
if (isRedLeftChild(nodeCurrent.leftChild)) {
Expand All @@ -170,13 +170,13 @@ public open class RBTree<K: Comparable<K>, V>: AbstractBSTree<K, V, RBTreeNode<K
*/
private fun moveRedLeft(node: RBTreeNode<K, V>): RBTreeNode<K, V> {
if (node.leftChild == null) return node
var nodeCurrent: RBTreeNode<K, V> = node
var nodeCurrent = node

flipColors(nodeCurrent)
if (isRedLeftChild(nodeCurrent.rightChild)) {
nodeCurrent.rightChild = notNullNodeAction(
node.rightChild, null
) {rightChild -> rotateRight(rightChild)}
) { rightChild -> rotateRight(rightChild) }
nodeCurrent = rotateLeft(nodeCurrent)
flipColors(nodeCurrent)
}
Expand All @@ -193,7 +193,7 @@ public open class RBTree<K: Comparable<K>, V>: AbstractBSTree<K, V, RBTreeNode<K
if (node == null) return null
val leftChild = node.leftChild ?: return node.rightChild

var nodeCurrent: RBTreeNode<K, V> = node
var nodeCurrent = node
if (!isRedColor(leftChild) && !isRedLeftChild(leftChild))
nodeCurrent = moveRedLeft(nodeCurrent)

Expand Down
12 changes: 6 additions & 6 deletions lib/src/test/kotlin/tree_tripper/binary_trees/AVLTreeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,42 +26,42 @@ class AVLTreeTest {
Assertions.assertEquals(0, tree.size)
}

@ParameterizedTest
@ParameterizedTest(name = "{displayName}[{index}] {argumentsWithNames}")
@MethodSource("testNodeCreationCases")
@DisplayName("node creation")
public fun testNodeCreation(key: Int, value: Int) {
tree.assertNodeCreation(key, value)
}

@ParameterizedTest
@ParameterizedTest(name = "{displayName}[{index}] {argumentsWithNames}")
@MethodSource("testBalanceTreeCases")
@DisplayName("check balance tree")
public fun testBalanceTree(expected: AVLTreeNode<Int, Int>, node: AVLTreeNode<Int, Int>) {
tree.assertBalanceTree(expected, node)
}

@ParameterizedTest
@ParameterizedTest(name = "{displayName}[{index}] {argumentsWithNames}")
@MethodSource("checkBalanceFactor")
@DisplayName("balance factor")
public fun checkBalanceFactor(expected: Int, node: AVLTreeNode<Int, Int>?) {
tree.assertBalanceFactor(expected, node)
}

@ParameterizedTest
@ParameterizedTest(name = "{displayName}[{index}] {argumentsWithNames}")
@MethodSource("testBalanceCases")
@DisplayName("balance case")
public fun testBalanceCase(expected: AVLTreeNode<Int, Int>, node: AVLTreeNode<Int, Int>) {
tree.assertBalance(expected, node)
}

@ParameterizedTest
@ParameterizedTest(name = "{displayName}[{index}] {argumentsWithNames}")
@MethodSource("testNodeRotateLeftCases")
@DisplayName("node rotate left case")
public fun testNodeRotateLeftCases(expected: AVLTreeNode<Int, Int>, node: AVLTreeNode<Int, Int>) {
tree.assertNodeLeftRotation(expected, node)
}

@ParameterizedTest
@ParameterizedTest(name = "{displayName}[{index}] {argumentsWithNames}")
@MethodSource("testNodeRotateRightCases")
@DisplayName("node rotate right case")
public fun testNodeRotateRightCase(expected: AVLTreeNode<Int, Int>, node: AVLTreeNode<Int, Int>) {
Expand Down
9 changes: 5 additions & 4 deletions lib/src/test/kotlin/tree_tripper/binary_trees/BSTreeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import tree_tripper.iterators.IterationOrders
import java.time.Duration
import kotlin.random.Random
import kotlin.test.Test
import kotlin.test.assertEquals


public class BSTreeTest {
Expand Down Expand Up @@ -59,7 +60,7 @@ public class BSTreeTest {
Assertions.assertEquals(tree.getRoot(), Pair(1, 0), "Incorrect change root")
}

@Test
@Test()
@DisplayName("insert children root")
public fun testInsertChildrenRoot() {
tree.insert(2, -2)
Expand All @@ -69,7 +70,7 @@ public class BSTreeTest {
Assertions.assertEquals(tree.size, 3, "Incorrect resizing tree size.")
}

@ParameterizedTest
@ParameterizedTest(name = "{displayName}[{index}] {argumentsWithNames}")
@MethodSource("getSizeAndTimeArguments")
@DisplayName("insert with size and time")
public fun testInsertWithSizeAndTime(size: Int, seconds: Long) {
Expand Down Expand Up @@ -115,7 +116,7 @@ public class BSTreeTest {
Assertions.assertEquals(tree.search(0), null, "Incorrect search a non-existent child root.")
}

@ParameterizedTest
@ParameterizedTest(name = "{displayName}[{index}] {argumentsWithNames}")
@MethodSource("getSizeAndTimeArguments")
@DisplayName("search with size and time")
public fun testSearchWithSizeAndTime(size: Int, seconds: Long) {
Expand Down Expand Up @@ -285,7 +286,7 @@ public class BSTreeTest {
Assertions.assertEquals(tree.search(3), -3, "Incorrect remove a root and lose the right child.")
}

@ParameterizedTest
@ParameterizedTest(name = "{displayName}[{index}] {argumentsWithNames}")
@MethodSource("getSizeAndTimeArguments")
@DisplayName("remove with size and time")
public fun testRemoveWithSizeAndTime(size: Int, seconds: Long) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import tree_tripper.nodes.binary_nodes.BSTreeNode
class BinarySearchTreeIteratorTest {
lateinit var iterator: BinarySearchTreeIterator<Int, Int, BSTreeNode<Int, Int>>

@ParameterizedTest
@ParameterizedTest(name = "{displayName}[{index}] {argumentsWithNames}")
@MethodSource("testIteratorCases")
@DisplayName("test iterator at width order")
public fun testWidthOrderIterator(expected: List<Int>, root: BSTreeNode<Int, Int>) {
Expand All @@ -24,7 +24,7 @@ class BinarySearchTreeIteratorTest {
}
}

@ParameterizedTest
@ParameterizedTest(name = "{displayName}[{index}] {argumentsWithNames}")
@MethodSource("testGetALotOfElementsCases")
@DisplayName("try get more elements than iterator has")
public fun testGetALotOfElements(order: IterationOrders) {
Expand All @@ -33,7 +33,7 @@ class BinarySearchTreeIteratorTest {
Assertions.assertThrows(NoSuchElementException::class.java) { iterator.next() }
}

@ParameterizedTest
@ParameterizedTest(name = "{displayName}[{index}] {argumentsWithNames}")
@MethodSource("testIteratorCases")
@DisplayName("test iterator at increase order")
public fun testIncreasingOrderIterator(expected: List<Int>, root: BSTreeNode<Int, Int>) {
Expand All @@ -47,7 +47,7 @@ class BinarySearchTreeIteratorTest {
}
}

@ParameterizedTest
@ParameterizedTest(name = "{displayName}[{index}] {argumentsWithNames}")
@MethodSource("testIteratorCases")
@DisplayName("test iterator at decrease order")
public fun testDecreasingOrderIterator(expected: List<Int>, root: BSTreeNode<Int, Int>) {
Expand Down
4 changes: 2 additions & 2 deletions lib/src/test/kotlin/tree_tripper/nodes/UtilsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import tree_tripper.nodes.binary_nodes.BSTreeNode

public class UtilsTest {

@ParameterizedTest
@ParameterizedTest(name = "{displayName}[{index}] {argumentsWithNames}")
@MethodSource("testNodeUpdateCases")
@DisplayName("util of node update")
public fun testNodeUpdate(expected: Boolean, node: BSTreeNode<Int, Int>?) {
Expand All @@ -19,7 +19,7 @@ public class UtilsTest {
Assertions.assertEquals(expected, isActivateAction)
}

@ParameterizedTest
@ParameterizedTest(name = "{displayName}[{index}] {argumentsWithNames}")
@MethodSource("testNodeActionCases")
@DisplayName("util of action on node")
public fun testNodeAction(expected: Boolean, node: BSTreeNode<Int, Int>?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class AVLTreeNodeTest {
Assertions.assertEquals(1, node.height) {"The height is not 1 by standard initialize."}
}

@ParameterizedTest
@ParameterizedTest(name = "{displayName}[{index}] {argumentsWithNames}")
@MethodSource("testUpdateHeight")
@DisplayName("update height")
public fun testUpdateHeight(expected: Int, node: AVLTreeNode<Int, Int>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.junit.jupiter.params.provider.MethodSource

public class RBTreeNodeTest {

@ParameterizedTest
@ParameterizedTest(name = "{displayName}[{index}] {argumentsWithNames}")
@MethodSource("testNodeSimpleInitializeCases")
@DisplayName("node simple initialization")
public fun testNodeSimpleInitialize(key: Int, value: Int?) {
Expand All @@ -22,7 +22,7 @@ public class RBTreeNodeTest {
Assertions.assertNull(node.rightChild) { "Right child of node is not null." }
}

@ParameterizedTest
@ParameterizedTest(name = "{displayName}[{index}] {argumentsWithNames}")
@MethodSource("testNodeColorTypeInitializeCases")
@DisplayName("node initialization with color")
public fun testNodeColorTypeInitialize(isRed: Boolean) {
Expand All @@ -32,7 +32,7 @@ public class RBTreeNodeTest {
Assertions.assertNull(node.rightChild) { "Right child of node is not null." }
}

@ParameterizedTest
@ParameterizedTest(name = "{displayName}[{index}] {argumentsWithNames}")
@MethodSource("testNodeFullInitializeCases")
@DisplayName("node initialization with color and children")
public fun testNodeFullInitialize(leftChild: RBTreeNode<Int, Int?>?, rightChild: RBTreeNode<Int, Int?>?) {
Expand All @@ -41,7 +41,7 @@ public class RBTreeNodeTest {
assertBinaryNodeDeepEquals(rightChild, node.rightChild) { n1, n2 -> n1.isRed == n2.isRed }
}

@ParameterizedTest
@ParameterizedTest(name = "{displayName}[{index}] {argumentsWithNames}")
@MethodSource("testToStringSimpleViewCases")
@DisplayName("to string simple view")
public fun testToStringSimpleView(expected: String, node: RBTreeNode<Int, Int?>) {
Expand Down
Loading