Skip to content

Commit

Permalink
Merge pull request #60 from spbu-coding-2023/fixes-after-1st-review
Browse files Browse the repository at this point in the history
Fixes after 1st review
  • Loading branch information
sevenbunu authored Apr 8, 2024
2 parents 46945b3 + ac74e9d commit d557110
Show file tree
Hide file tree
Showing 33 changed files with 2,189 additions and 1,967 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ on:
branches:
- main
- develop
- fixes-after-1st-review
push:
branches:
- main
- develop
- fixes-after-1st-review
workflow_dispatch:

jobs:
Expand All @@ -17,15 +19,19 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Java JDK
uses: actions/setup-java@v4
with:
java-version: 17
cache: gradle
distribution: "temurin"

- name: Set up Gradle
uses: gradle/actions/setup-gradle@v3

- name: Build with Gradle
run: ./gradlew build

- name: Run tests
run: ./gradlew test
56 changes: 56 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Jacoco coverage

on:
pull_request:
branches:
- main
- develop
- fixes-after-1st-review
push:
branches:
- main
- develop
- fixes-after-1st-review
workflow_dispatch:

jobs:
coverage:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Java JDK
uses: actions/setup-java@v4
with:
java-version: 17
distribution: "temurin"

- name: Set up Gradle
uses: gradle/actions/setup-gradle@v3

- name: Run Coverage
run: ./gradlew jacocoTestReport

- name: Generate JaCoCo Report
uses: cicirello/jacoco-badge-generator@v2
with:
generate-branches-badge: true
jacoco-csv-file: lib/build/reports/jacoco/test/jacocoTestReport.csv

- name: Add coverage to PR
id: jacoco
uses: madrapps/[email protected]
with:
paths: |
${{ github.workspace }}/lib/build/reports/jacoco/test/jacocoTestReport.xml,
${{ github.workspace }}/**/build/reports/jacoco/**/debugCoverage.xml
token: ${{ secrets.GITHUB_TOKEN }}
title: '# 🇷🇺 Coverage Report'
update-comment: true
min-coverage-overall: 40
min-coverage-changed-files: 60
pass-emoji: '🥳'
fail-emoji: '🤡'
2 changes: 2 additions & 0 deletions .github/workflows/ktlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ on:
branches:
- main
- develop
- fixes-after-1st-review
push:
branches:
- main
- develop
- fixes-after-1st-review
workflow_dispatch:

jobs:
Expand Down
29 changes: 27 additions & 2 deletions lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ plugins {

// Code coverage plugin
jacoco

// Documentation generation
id("org.jetbrains.dokka") version "1.9.20"
}

repositories {
Expand All @@ -31,6 +34,8 @@ dependencies {
testImplementation(libs.junit.jupiter.engine)

testRuntimeOnly("org.junit.platform:junit-platform-launcher")

compileOnly("org.jetbrains.dokka:dokka-core:1.9.20")
}

// Apply a specific Java toolchain to ease working on different environments.
Expand All @@ -48,8 +53,28 @@ tasks.named<Test>("test") {
tasks.named<JacocoReport>("jacocoTestReport") {
dependsOn(tasks.test)
reports {
csv.required = false
xml.required = false
csv.required = true
xml.required = true
html.outputLocation = layout.buildDirectory.dir("jacocoHtml")
}
}

tasks.dokkaHtml {
outputDirectory.set(layout.buildDirectory.dir("documentation/html"))
}

tasks.dokkaGfm {
outputDirectory.set(layout.buildDirectory.dir("documentation/markdown"))
}

tasks.register<Jar>("dokkaHtmlJar") {
dependsOn(tasks.dokkaHtml)
from(tasks.dokkaHtml.flatMap { it.outputDirectory })
archiveClassifier.set("html-docs")
}

tasks.register<Jar>("dokkaJavadocJar") {
dependsOn(tasks.dokkaJavadoc)
from(tasks.dokkaJavadoc.flatMap { it.outputDirectory })
archiveClassifier.set("javadoc")
}
18 changes: 12 additions & 6 deletions lib/src/main/kotlin/iterator/TreeIterator.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
package main.iterator
package iterator

import main.vertexes.InterfaceBSTVertex
import java.util.LinkedList
import vertexes.InterfaceBSTVertex
import java.util.Stack

/**
* Iterator iterates over the vertices of the tree, visiting each vertex in the order of a depth-first traversal.
* Iterator interface implementation.
*
* [Iterator] interface implementation.
*
* @param K the type of keys in the tree
* @param V the type of values associated with the keys
* @param N the type of tree vertices implementing InterfaceBSTVertex
*/
open class TreeIterator<K, V, N : InterfaceBSTVertex<K, V, N>>(
vertex: N?,
) : Iterator<Pair<K, V>> {
protected val stack = LinkedList<N>()
protected val stack = Stack<N>()

init {
// Initialize the iterator with the given vertex by adding it to the stack
Expand All @@ -22,7 +24,9 @@ open class TreeIterator<K, V, N : InterfaceBSTVertex<K, V, N>>(

/**
* Returns true if the iterator has more elements.
*
* This method checks if there are more vertices to traverse in the tree.
*
* @return true if the iterator has more elements, otherwise false
*/
override fun hasNext(): Boolean {
Expand All @@ -31,11 +35,13 @@ open class TreeIterator<K, V, N : InterfaceBSTVertex<K, V, N>>(

/**
* Returns the next element in the iteration.
*
* This method returns the next vertex in the depth-first traversal of the tree.
*
* @return the next element in the iteration as a Pair containing the key and value of the vertex
*/
override fun next(): Pair<K, V> {
val nextVertex: N = stack.removeLast()
val nextVertex: N = stack.pop()
nextVertex.leftSon?.let { stack.add(it) }
nextVertex.rightSon?.let { stack.add(it) }
return Pair(nextVertex.key, nextVertex.value)
Expand Down
Loading

0 comments on commit d557110

Please sign in to comment.