From 025a838d038dd24e02c38e43e220c2aa582a49bf Mon Sep 17 00:00:00 2001 From: Kostya Date: Sun, 7 Apr 2024 01:04:24 +0300 Subject: [PATCH 01/15] feat: add test coverage --- .github/workflows/ci.yml | 2 ++ .github/workflows/coverage.yml | 45 ++++++++++++++++++++++++++++++++++ .github/workflows/ktlint.yml | 2 ++ 3 files changed, 49 insertions(+) create mode 100644 .github/workflows/coverage.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 25f9bf2..d0342fa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,10 +5,12 @@ on: branches: - main - develop + - fixes-after-1st-review push: branches: - main - develop + - fixes-after-1st-review workflow_dispatch: jobs: diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 0000000..dfa67a9 --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,45 @@ +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 + 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: Run Coverage + run: | + chmod +x gradlew + ./gradlew testCoverage + - name: Add coverage to PR + id: jacoco + uses: madrapps/jacoco-report@v1.6.1 + with: + paths: | + ${{ github.workspace }}/**/build/reports/jacoco/prodNormalDebugCoverage/prodNormalDebugCoverage.xml, + ${{ github.workspace }}/**/build/reports/jacoco/**/debugCoverage.xml + token: ${{ secrets.GITHUB_TOKEN }} + min-coverage-overall: 40 + min-coverage-changed-files: 60 + pass-emoji: 💪 + fail-emoji: 🤡 \ No newline at end of file diff --git a/.github/workflows/ktlint.yml b/.github/workflows/ktlint.yml index 8fcfbd4..f58f9f6 100644 --- a/.github/workflows/ktlint.yml +++ b/.github/workflows/ktlint.yml @@ -5,10 +5,12 @@ on: branches: - main - develop + - fixes-after-1st-review push: branches: - main - develop + - fixes-after-1st-review workflow_dispatch: jobs: From 92080c1a100457f9c2499838cedaa8232a9e65a1 Mon Sep 17 00:00:00 2001 From: Kostya Date: Sun, 7 Apr 2024 01:08:41 +0300 Subject: [PATCH 02/15] fix: delete extra code --- .github/workflows/coverage.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index dfa67a9..0004a55 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -28,9 +28,7 @@ jobs: - name: Set up Gradle uses: gradle/actions/setup-gradle@v3 - name: Run Coverage - run: | - chmod +x gradlew - ./gradlew testCoverage + run: ./gradlew testCoverage - name: Add coverage to PR id: jacoco uses: madrapps/jacoco-report@v1.6.1 From 166b79a1ec73ce89c4c57c6c3a504f291ecb42c3 Mon Sep 17 00:00:00 2001 From: Kostya Date: Sun, 7 Apr 2024 01:16:23 +0300 Subject: [PATCH 03/15] fix: change name of reports --- .github/workflows/coverage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 0004a55..0877d56 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -28,7 +28,7 @@ jobs: - name: Set up Gradle uses: gradle/actions/setup-gradle@v3 - name: Run Coverage - run: ./gradlew testCoverage + run: ./gradlew jacocoTestReport - name: Add coverage to PR id: jacoco uses: madrapps/jacoco-report@v1.6.1 From e4274a93f5d6ea5e75a76307c21227c7ae993ce2 Mon Sep 17 00:00:00 2001 From: Kostya Date: Sun, 7 Apr 2024 01:22:46 +0300 Subject: [PATCH 04/15] fix: add permissions --- .github/workflows/coverage.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 0877d56..00d7878 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -16,6 +16,8 @@ on: jobs: coverage: runs-on: ubuntu-latest + permissions: + pull-requests: write steps: - name: Checkout repository uses: actions/checkout@v4 From 2705e136305988d5c978a50e2cfc4a1138aae087 Mon Sep 17 00:00:00 2001 From: Kostya Date: Sun, 7 Apr 2024 01:39:18 +0300 Subject: [PATCH 05/15] feat: add emoji on tests --- .github/workflows/coverage.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 00d7878..7b79dae 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -41,5 +41,5 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} min-coverage-overall: 40 min-coverage-changed-files: 60 - pass-emoji: 💪 - fail-emoji: 🤡 \ No newline at end of file + pass-emoji: ':partying_face:' + fail-emoji: ':clown_face:' \ No newline at end of file From d140a3f7d02338b6f8fcbf098a1d041cf70f5860 Mon Sep 17 00:00:00 2001 From: Kostya Date: Sun, 7 Apr 2024 01:50:25 +0300 Subject: [PATCH 06/15] feat: add test report --- .github/workflows/ci.yml | 4 ++++ .github/workflows/coverage.yml | 15 ++++++++++++--- lib/build.gradle.kts | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d0342fa..c2df060 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,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 diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 7b79dae..36663ab 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -21,16 +21,25 @@ 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: Run Coverage run: ./gradlew jacocoTestReport + + - name: Generate JaCoCo Badge + uses: cicirello/jacoco-badge-generator@v2 + with: + generate-branches-badge: true + jacoco-csv-file: build/reports/jacoco/test/jacocoTestReport.csv + - name: Add coverage to PR id: jacoco uses: madrapps/jacoco-report@v1.6.1 @@ -41,5 +50,5 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} min-coverage-overall: 40 min-coverage-changed-files: 60 - pass-emoji: ':partying_face:' - fail-emoji: ':clown_face:' \ No newline at end of file + pass-emoji: '🥳' + fail-emoji: '🤡' \ No newline at end of file diff --git a/lib/build.gradle.kts b/lib/build.gradle.kts index dcb7919..aa9fc85 100644 --- a/lib/build.gradle.kts +++ b/lib/build.gradle.kts @@ -48,7 +48,7 @@ tasks.named("test") { tasks.named("jacocoTestReport") { dependsOn(tasks.test) reports { - csv.required = false + csv.required = true xml.required = false html.outputLocation = layout.buildDirectory.dir("jacocoHtml") } From 15caf8a96ad7f1b2bb00782ee396ad38c4cd68d4 Mon Sep 17 00:00:00 2001 From: Kostya Date: Sun, 7 Apr 2024 02:06:08 +0300 Subject: [PATCH 07/15] fix: change path to csv --- .github/workflows/coverage.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 36663ab..d55eb74 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -34,11 +34,11 @@ jobs: - name: Run Coverage run: ./gradlew jacocoTestReport - - name: Generate JaCoCo Badge + - name: Generate JaCoCo Report uses: cicirello/jacoco-badge-generator@v2 with: generate-branches-badge: true - jacoco-csv-file: build/reports/jacoco/test/jacocoTestReport.csv + jacoco-csv-file: lib/build/reports/jacoco/test/jacocoTestReport.csv - name: Add coverage to PR id: jacoco @@ -50,5 +50,4 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} min-coverage-overall: 40 min-coverage-changed-files: 60 - pass-emoji: '🥳' - fail-emoji: '🤡' \ No newline at end of file + \ No newline at end of file From b56cc5de85bcc19f12caa17a4302c054a4634ddd Mon Sep 17 00:00:00 2001 From: Kostya Date: Sun, 7 Apr 2024 02:11:19 +0300 Subject: [PATCH 08/15] feat: add emoji) --- .github/workflows/coverage.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index d55eb74..bb43dfa 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -49,5 +49,5 @@ jobs: ${{ github.workspace }}/**/build/reports/jacoco/**/debugCoverage.xml token: ${{ secrets.GITHUB_TOKEN }} min-coverage-overall: 40 - min-coverage-changed-files: 60 - \ No newline at end of file + pass-emoji: '🥳' + fail-emoji: '🤡' From 57b758b5e5f6a94a761daa1d025c690ffd142ca1 Mon Sep 17 00:00:00 2001 From: Kostya Date: Sun, 7 Apr 2024 02:21:25 +0300 Subject: [PATCH 09/15] feat: add title of report --- .github/workflows/coverage.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index bb43dfa..0718b07 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -48,6 +48,8 @@ jobs: ${{ github.workspace }}/**/build/reports/jacoco/prodNormalDebugCoverage/prodNormalDebugCoverage.xml, ${{ github.workspace }}/**/build/reports/jacoco/**/debugCoverage.xml token: ${{ secrets.GITHUB_TOKEN }} + title: '# :lobster: Coverage Report' + update-comment: true min-coverage-overall: 40 pass-emoji: '🥳' fail-emoji: '🤡' From 56362496f2aa97fb0be1319f0a6662a054e864ac Mon Sep 17 00:00:00 2001 From: Kostya Date: Sun, 7 Apr 2024 02:26:03 +0300 Subject: [PATCH 10/15] feat: add skip case --- .github/workflows/coverage.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 0718b07..b46c41b 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -48,8 +48,9 @@ jobs: ${{ github.workspace }}/**/build/reports/jacoco/prodNormalDebugCoverage/prodNormalDebugCoverage.xml, ${{ github.workspace }}/**/build/reports/jacoco/**/debugCoverage.xml token: ${{ secrets.GITHUB_TOKEN }} - title: '# :lobster: Coverage Report' + title: '# 🇷🇺 Coverage Report' update-comment: true + skip-if-no-changes: true min-coverage-overall: 40 pass-emoji: '🥳' fail-emoji: '🤡' From f41871e2b93c4652e1e22daa7755202acd424159 Mon Sep 17 00:00:00 2001 From: Kostya Date: Sun, 7 Apr 2024 02:31:32 +0300 Subject: [PATCH 11/15] test: comment some tests to see changes in report --- .github/workflows/coverage.yml | 2 +- .../kotlin/trees/rbTree/RBSearchTreeTest.kt | 390 +++++++++--------- 2 files changed, 196 insertions(+), 196 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index b46c41b..50383f3 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -48,7 +48,7 @@ jobs: ${{ github.workspace }}/**/build/reports/jacoco/prodNormalDebugCoverage/prodNormalDebugCoverage.xml, ${{ github.workspace }}/**/build/reports/jacoco/**/debugCoverage.xml token: ${{ secrets.GITHUB_TOKEN }} - title: '# 🇷🇺 Coverage Report' + title: '# 5⃣2⃣ Coverage Report' update-comment: true skip-if-no-changes: true min-coverage-overall: 40 diff --git a/lib/src/test/kotlin/trees/rbTree/RBSearchTreeTest.kt b/lib/src/test/kotlin/trees/rbTree/RBSearchTreeTest.kt index 3fdde9c..77258d6 100644 --- a/lib/src/test/kotlin/trees/rbTree/RBSearchTreeTest.kt +++ b/lib/src/test/kotlin/trees/rbTree/RBSearchTreeTest.kt @@ -178,201 +178,201 @@ class RBSearchTreeTest { ) } - @Test - fun `balance after remove - brother is right and black, brother's rightSon - red`() { - rbTree.put(7, "hi") - rbTree.put(4, "my") - rbTree.put(10, "name") - rbTree.put(3, "is") - rbTree.put(5, "chka") - rbTree.put(9, "chka") - rbTree.put(12, "chka") - rbTree.put(11, "Slim") - rbTree.put(13, "Shady") - rbTree.remove(9) - expectedResult = - listOf( - Pair(7, "hi"), - Pair(12, "chka"), - Pair(13, "Shady"), - Pair(10, "name"), - Pair(11, "Slim"), - Pair(4, "my"), - Pair(5, "chka"), - Pair(3, "is"), - ) - } - - @Test - fun `balance after remove - brother is right and black, brother's leftSon - red (rightSon - black)`() { - rbTree.put(7, "hi") - rbTree.put(4, "my") - rbTree.put(10, "name") - rbTree.put(3, "is") - rbTree.put(5, "chka") - rbTree.put(9, "chka") - rbTree.put(12, "Slim") - rbTree.put(11, "Shady") - rbTree.remove(9) - expectedResult = - listOf( - Pair(7, "hi"), - Pair(11, "Shady"), - Pair(12, "Slim"), - Pair(10, "name"), - Pair(4, "my"), - Pair(5, "chka"), - Pair(3, "is"), - ) - } - - @Test - fun `balance after remove - brother is right and black, both sons - black`() { - rbTree.put(7, "hi") - rbTree.put(4, "my") - rbTree.put(10, "name") - rbTree.put(9, "is") - rbTree.put(12, "Slim") - rbTree.put(11, "Shady") - rbTree.remove(11) - - // now vertexes with keys 9 and 12 are black - rbTree.remove(9) - - expectedResult = listOf(Pair(7, "hi"), Pair(10, "name"), Pair(12, "Slim"), Pair(4, "my")) - } - - @Test - fun `balance after remove - right brother is red`() { - rbTree.put(60, "sixty") - rbTree.put(33, "thirty-three") - rbTree.put(84, "eighty-four") - rbTree.put(15, "fifteen") - rbTree.put(51, "fifty-one") - rbTree.put(65, "sixty-five") - rbTree.put(96, "ninety-six") - rbTree.put(34, "thirty-four") - rbTree.put(52, "Alblack") - rbTree.put(94, "ninety-four") - rbTree.put(97, "ninety-seven") - rbTree.put(95, "ninety-five") - - // now vertex with key 96 is red, with key 65 - black - rbTree.remove(65) - - expectedResult = - listOf( - Pair(60, "sixty"), - Pair(96, "ninety-six"), - Pair(97, "ninety-seven"), - Pair(94, "ninety-four"), - Pair(95, "ninety-five"), - Pair(84, "eighty-four"), - Pair(33, "thirty-three"), - Pair(51, "fifty-one"), - Pair(52, "Alblack"), - Pair(34, "thirty-four"), - Pair(15, "fifteen"), - ) - } - - @Test - fun `balance after remove - brother is left and black, brother's rightSon - red`() { - rbTree.put(7, "hi") - rbTree.put(4, "my") - rbTree.put(10, "name") - rbTree.put(2, "is") - rbTree.put(5, "chka") - rbTree.put(9, "chka") - rbTree.put(12, "chka") - rbTree.put(1, "Slim") - rbTree.put(3, "Shady") - rbTree.remove(5) - expectedResult = - listOf( - Pair(7, "hi"), - Pair(10, "name"), - Pair(12, "chka"), - Pair(9, "chka"), - Pair(2, "is"), - Pair(4, "my"), - Pair(3, "Shady"), - Pair(1, "Slim"), - ) - } - - @Test - fun `balance after remove - brother is left and black, brother's rightSon - red (leftSon - black)`() { - rbTree.put(7, "hi") - rbTree.put(4, "my") - rbTree.put(10, "name") - rbTree.put(2, "is") - rbTree.put(5, "chka") - rbTree.put(9, "chka") - rbTree.put(12, "Slim") - rbTree.put(3, "Shady") - rbTree.remove(5) - expectedResult = - listOf( - Pair(7, "hi"), - Pair(10, "name"), - Pair(12, "Slim"), - Pair(9, "chka"), - Pair(3, "Shady"), - Pair(4, "my"), - Pair(2, "is"), - ) - } - - @Test - fun `balance after remove - brother is left and black, both sons - black`() { - rbTree.put(7, "hi") - rbTree.put(4, "my") - rbTree.put(10, "name") - rbTree.put(2, "is") - rbTree.put(5, "Slim") - rbTree.put(3, "Shady") - rbTree.remove(3) - - // now vertexes with keys 2 and 5 are black - rbTree.remove(5) - - expectedResult = listOf(Pair(7, "hi"), Pair(10, "name"), Pair(4, "my"), Pair(2, "is")) - } - - @Test - fun `balance after remove - left brother is red`() { - rbTree.put(60, "sixty") - rbTree.put(33, "thirty-three") - rbTree.put(84, "eighty-four") - rbTree.put(15, "fifteen") - rbTree.put(51, "fifty-one") - rbTree.put(65, "sixty-five") - rbTree.put(96, "ninety-six") - rbTree.put(5, "five") - rbTree.put(27, "twenty-seven") - rbTree.put(61, "sixty-one") - rbTree.put(69, "sixty-nine") - rbTree.put(17, "seventeen") - - // now vertex with key 15 is red, with key 51 - black - rbTree.remove(51) - - expectedResult = - listOf( - Pair(60, "sixty"), - Pair(84, "eighty-four"), - Pair(96, "ninety-six"), - Pair(65, "sixty-five"), - Pair(69, "sixty-nine"), - Pair(61, "sixty-one"), - Pair(15, "fifteen"), - Pair(27, "twenty-seven"), - Pair(33, "thirty-three"), - Pair(17, "seventeen"), - Pair(5, "five"), - ) - } +// @Test +// fun `balance after remove - brother is right and black, brother's rightSon - red`() { +// rbTree.put(7, "hi") +// rbTree.put(4, "my") +// rbTree.put(10, "name") +// rbTree.put(3, "is") +// rbTree.put(5, "chka") +// rbTree.put(9, "chka") +// rbTree.put(12, "chka") +// rbTree.put(11, "Slim") +// rbTree.put(13, "Shady") +// rbTree.remove(9) +// expectedResult = +// listOf( +// Pair(7, "hi"), +// Pair(12, "chka"), +// Pair(13, "Shady"), +// Pair(10, "name"), +// Pair(11, "Slim"), +// Pair(4, "my"), +// Pair(5, "chka"), +// Pair(3, "is"), +// ) +// } +// +// @Test +// fun `balance after remove - brother is right and black, brother's leftSon - red (rightSon - black)`() { +// rbTree.put(7, "hi") +// rbTree.put(4, "my") +// rbTree.put(10, "name") +// rbTree.put(3, "is") +// rbTree.put(5, "chka") +// rbTree.put(9, "chka") +// rbTree.put(12, "Slim") +// rbTree.put(11, "Shady") +// rbTree.remove(9) +// expectedResult = +// listOf( +// Pair(7, "hi"), +// Pair(11, "Shady"), +// Pair(12, "Slim"), +// Pair(10, "name"), +// Pair(4, "my"), +// Pair(5, "chka"), +// Pair(3, "is"), +// ) +// } +// +// @Test +// fun `balance after remove - brother is right and black, both sons - black`() { +// rbTree.put(7, "hi") +// rbTree.put(4, "my") +// rbTree.put(10, "name") +// rbTree.put(9, "is") +// rbTree.put(12, "Slim") +// rbTree.put(11, "Shady") +// rbTree.remove(11) +// +// // now vertexes with keys 9 and 12 are black +// rbTree.remove(9) +// +// expectedResult = listOf(Pair(7, "hi"), Pair(10, "name"), Pair(12, "Slim"), Pair(4, "my")) +// } +// +// @Test +// fun `balance after remove - right brother is red`() { +// rbTree.put(60, "sixty") +// rbTree.put(33, "thirty-three") +// rbTree.put(84, "eighty-four") +// rbTree.put(15, "fifteen") +// rbTree.put(51, "fifty-one") +// rbTree.put(65, "sixty-five") +// rbTree.put(96, "ninety-six") +// rbTree.put(34, "thirty-four") +// rbTree.put(52, "Alblack") +// rbTree.put(94, "ninety-four") +// rbTree.put(97, "ninety-seven") +// rbTree.put(95, "ninety-five") +// +// // now vertex with key 96 is red, with key 65 - black +// rbTree.remove(65) +// +// expectedResult = +// listOf( +// Pair(60, "sixty"), +// Pair(96, "ninety-six"), +// Pair(97, "ninety-seven"), +// Pair(94, "ninety-four"), +// Pair(95, "ninety-five"), +// Pair(84, "eighty-four"), +// Pair(33, "thirty-three"), +// Pair(51, "fifty-one"), +// Pair(52, "Alblack"), +// Pair(34, "thirty-four"), +// Pair(15, "fifteen"), +// ) +// } +// +// @Test +// fun `balance after remove - brother is left and black, brother's rightSon - red`() { +// rbTree.put(7, "hi") +// rbTree.put(4, "my") +// rbTree.put(10, "name") +// rbTree.put(2, "is") +// rbTree.put(5, "chka") +// rbTree.put(9, "chka") +// rbTree.put(12, "chka") +// rbTree.put(1, "Slim") +// rbTree.put(3, "Shady") +// rbTree.remove(5) +// expectedResult = +// listOf( +// Pair(7, "hi"), +// Pair(10, "name"), +// Pair(12, "chka"), +// Pair(9, "chka"), +// Pair(2, "is"), +// Pair(4, "my"), +// Pair(3, "Shady"), +// Pair(1, "Slim"), +// ) +// } +// +// @Test +// fun `balance after remove - brother is left and black, brother's rightSon - red (leftSon - black)`() { +// rbTree.put(7, "hi") +// rbTree.put(4, "my") +// rbTree.put(10, "name") +// rbTree.put(2, "is") +// rbTree.put(5, "chka") +// rbTree.put(9, "chka") +// rbTree.put(12, "Slim") +// rbTree.put(3, "Shady") +// rbTree.remove(5) +// expectedResult = +// listOf( +// Pair(7, "hi"), +// Pair(10, "name"), +// Pair(12, "Slim"), +// Pair(9, "chka"), +// Pair(3, "Shady"), +// Pair(4, "my"), +// Pair(2, "is"), +// ) +// } +// +// @Test +// fun `balance after remove - brother is left and black, both sons - black`() { +// rbTree.put(7, "hi") +// rbTree.put(4, "my") +// rbTree.put(10, "name") +// rbTree.put(2, "is") +// rbTree.put(5, "Slim") +// rbTree.put(3, "Shady") +// rbTree.remove(3) +// +// // now vertexes with keys 2 and 5 are black +// rbTree.remove(5) +// +// expectedResult = listOf(Pair(7, "hi"), Pair(10, "name"), Pair(4, "my"), Pair(2, "is")) +// } +// +// @Test +// fun `balance after remove - left brother is red`() { +// rbTree.put(60, "sixty") +// rbTree.put(33, "thirty-three") +// rbTree.put(84, "eighty-four") +// rbTree.put(15, "fifteen") +// rbTree.put(51, "fifty-one") +// rbTree.put(65, "sixty-five") +// rbTree.put(96, "ninety-six") +// rbTree.put(5, "five") +// rbTree.put(27, "twenty-seven") +// rbTree.put(61, "sixty-one") +// rbTree.put(69, "sixty-nine") +// rbTree.put(17, "seventeen") +// +// // now vertex with key 15 is red, with key 51 - black +// rbTree.remove(51) +// +// expectedResult = +// listOf( +// Pair(60, "sixty"), +// Pair(84, "eighty-four"), +// Pair(96, "ninety-six"), +// Pair(65, "sixty-five"), +// Pair(69, "sixty-nine"), +// Pair(61, "sixty-one"), +// Pair(15, "fifteen"), +// Pair(27, "twenty-seven"), +// Pair(33, "thirty-three"), +// Pair(17, "seventeen"), +// Pair(5, "five"), +// ) +// } @Test fun `test secondary constructor`() { From 2f03751127866aed46d5b86508b417c5b1e89016 Mon Sep 17 00:00:00 2001 From: Kostya Date: Sun, 7 Apr 2024 02:36:46 +0300 Subject: [PATCH 12/15] test: comment some rbtree code to see changes in jacoco report --- .github/workflows/coverage.yml | 1 + lib/src/main/kotlin/trees/RBSearchTree.kt | 154 +++---- .../kotlin/trees/rbTree/RBSearchTreeTest.kt | 390 +++++++++--------- 3 files changed, 273 insertions(+), 272 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 50383f3..4a4fa5b 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -52,5 +52,6 @@ jobs: update-comment: true skip-if-no-changes: true min-coverage-overall: 40 + min-coverage-changed-files: 60 pass-emoji: '🥳' fail-emoji: '🤡' diff --git a/lib/src/main/kotlin/trees/RBSearchTree.kt b/lib/src/main/kotlin/trees/RBSearchTree.kt index dfaaa7e..45bc2a1 100644 --- a/lib/src/main/kotlin/trees/RBSearchTree.kt +++ b/lib/src/main/kotlin/trees/RBSearchTree.kt @@ -61,7 +61,7 @@ class RBSearchTree : AbstractBinarySearchTree> { if (vertex == root && size == 0L) { root = null } else if (needToBalance(vertex)) { - balanceAfterRemove(vertex) +// balanceAfterRemove(vertex) } return value @@ -125,82 +125,82 @@ class RBSearchTree : AbstractBinarySearchTree> { * rotate left. We move conflict on level below, then we look at the previous cases * @param vertex The child vertex of the removed vertex or null if the removed vertex had no children. */ - private fun balanceAfterRemove(vertex: RBVertex?) { - var currentVertex = vertex - while (currentVertex != root && (currentVertex?.isRed == false || currentVertex == null)) { - var brother: RBVertex? - if (currentVertex == currentVertex?.parent?.leftSon) { - brother = currentVertex?.parent?.rightSon - - if (brother?.isRed == true) { - brother.isRed = false - currentVertex?.parent?.isRed = true - val vertexForRotate = currentVertex?.parent - vertexForRotate?.let { rotateLeft(vertexForRotate) } - brother = currentVertex?.parent?.rightSon - } - - if ((brother?.leftSon?.isRed == false || brother?.leftSon == null) && - (brother?.rightSon?.isRed == false || brother?.rightSon == null) - ) { - brother?.isRed = true - currentVertex = currentVertex?.parent - if (vertex == currentVertex?.leftSon) currentVertex?.leftSon = null - } else { - if (brother.rightSon?.isRed == false || brother.rightSon == null) { - brother.leftSon?.isRed = false - brother.isRed = true - rotateRight(brother) - brother = currentVertex?.parent?.rightSon - } - - val parentColor = currentVertex?.parent?.isRed - parentColor?.let { brother?.isRed = parentColor } - currentVertex?.parent?.isRed = false - brother?.rightSon?.isRed = false - val vertexForRotate = currentVertex?.parent - vertexForRotate?.let { rotateLeft(vertexForRotate) } - if (currentVertex == vertex) currentVertex?.parent?.leftSon = null - currentVertex = root - } - } else { - brother = currentVertex?.parent?.leftSon - - if (brother?.isRed == true) { - brother.isRed = false - currentVertex?.parent?.isRed = true - val vertexForRotate = currentVertex?.parent - vertexForRotate?.let { rotateRight(vertexForRotate) } - brother = currentVertex?.parent?.leftSon - } - - if ((brother?.leftSon?.isRed == false || brother?.leftSon == null) && - (brother?.rightSon?.isRed == false || brother?.rightSon == null) - ) { - brother?.isRed = true - currentVertex = currentVertex?.parent - if (vertex == currentVertex?.rightSon) currentVertex?.rightSon = null - } else { - if (brother.leftSon?.isRed == false || brother.leftSon == null) { - brother.rightSon?.isRed = false - brother.isRed = true - rotateLeft(brother) - brother = currentVertex?.parent?.leftSon - } - - val parentColor = currentVertex?.parent?.isRed - parentColor?.let { brother?.isRed = parentColor } - currentVertex?.parent?.isRed = false - brother?.leftSon?.isRed = false - val vertexForRotate = currentVertex?.parent - vertexForRotate?.let { rotateRight(vertexForRotate) } - if (currentVertex == vertex) currentVertex?.parent?.rightSon = null - currentVertex = root - } - } - } - currentVertex?.isRed = false - } +// private fun balanceAfterRemove(vertex: RBVertex?) { +// var currentVertex = vertex +// while (currentVertex != root && (currentVertex?.isRed == false || currentVertex == null)) { +// var brother: RBVertex? +// if (currentVertex == currentVertex?.parent?.leftSon) { +// brother = currentVertex?.parent?.rightSon +// +// if (brother?.isRed == true) { +// brother.isRed = false +// currentVertex?.parent?.isRed = true +// val vertexForRotate = currentVertex?.parent +// vertexForRotate?.let { rotateLeft(vertexForRotate) } +// brother = currentVertex?.parent?.rightSon +// } +// +// if ((brother?.leftSon?.isRed == false || brother?.leftSon == null) && +// (brother?.rightSon?.isRed == false || brother?.rightSon == null) +// ) { +// brother?.isRed = true +// currentVertex = currentVertex?.parent +// if (vertex == currentVertex?.leftSon) currentVertex?.leftSon = null +// } else { +// if (brother.rightSon?.isRed == false || brother.rightSon == null) { +// brother.leftSon?.isRed = false +// brother.isRed = true +// rotateRight(brother) +// brother = currentVertex?.parent?.rightSon +// } +// +// val parentColor = currentVertex?.parent?.isRed +// parentColor?.let { brother?.isRed = parentColor } +// currentVertex?.parent?.isRed = false +// brother?.rightSon?.isRed = false +// val vertexForRotate = currentVertex?.parent +// vertexForRotate?.let { rotateLeft(vertexForRotate) } +// if (currentVertex == vertex) currentVertex?.parent?.leftSon = null +// currentVertex = root +// } +// } else { +// brother = currentVertex?.parent?.leftSon +// +// if (brother?.isRed == true) { +// brother.isRed = false +// currentVertex?.parent?.isRed = true +// val vertexForRotate = currentVertex?.parent +// vertexForRotate?.let { rotateRight(vertexForRotate) } +// brother = currentVertex?.parent?.leftSon +// } +// +// if ((brother?.leftSon?.isRed == false || brother?.leftSon == null) && +// (brother?.rightSon?.isRed == false || brother?.rightSon == null) +// ) { +// brother?.isRed = true +// currentVertex = currentVertex?.parent +// if (vertex == currentVertex?.rightSon) currentVertex?.rightSon = null +// } else { +// if (brother.leftSon?.isRed == false || brother.leftSon == null) { +// brother.rightSon?.isRed = false +// brother.isRed = true +// rotateLeft(brother) +// brother = currentVertex?.parent?.leftSon +// } +// +// val parentColor = currentVertex?.parent?.isRed +// parentColor?.let { brother?.isRed = parentColor } +// currentVertex?.parent?.isRed = false +// brother?.leftSon?.isRed = false +// val vertexForRotate = currentVertex?.parent +// vertexForRotate?.let { rotateRight(vertexForRotate) } +// if (currentVertex == vertex) currentVertex?.parent?.rightSon = null +// currentVertex = root +// } +// } +// } +// currentVertex?.isRed = false +// } /** * Finds a vertex by corresponding key. If such vertex doesn't exist returns null. diff --git a/lib/src/test/kotlin/trees/rbTree/RBSearchTreeTest.kt b/lib/src/test/kotlin/trees/rbTree/RBSearchTreeTest.kt index 77258d6..3fdde9c 100644 --- a/lib/src/test/kotlin/trees/rbTree/RBSearchTreeTest.kt +++ b/lib/src/test/kotlin/trees/rbTree/RBSearchTreeTest.kt @@ -178,201 +178,201 @@ class RBSearchTreeTest { ) } -// @Test -// fun `balance after remove - brother is right and black, brother's rightSon - red`() { -// rbTree.put(7, "hi") -// rbTree.put(4, "my") -// rbTree.put(10, "name") -// rbTree.put(3, "is") -// rbTree.put(5, "chka") -// rbTree.put(9, "chka") -// rbTree.put(12, "chka") -// rbTree.put(11, "Slim") -// rbTree.put(13, "Shady") -// rbTree.remove(9) -// expectedResult = -// listOf( -// Pair(7, "hi"), -// Pair(12, "chka"), -// Pair(13, "Shady"), -// Pair(10, "name"), -// Pair(11, "Slim"), -// Pair(4, "my"), -// Pair(5, "chka"), -// Pair(3, "is"), -// ) -// } -// -// @Test -// fun `balance after remove - brother is right and black, brother's leftSon - red (rightSon - black)`() { -// rbTree.put(7, "hi") -// rbTree.put(4, "my") -// rbTree.put(10, "name") -// rbTree.put(3, "is") -// rbTree.put(5, "chka") -// rbTree.put(9, "chka") -// rbTree.put(12, "Slim") -// rbTree.put(11, "Shady") -// rbTree.remove(9) -// expectedResult = -// listOf( -// Pair(7, "hi"), -// Pair(11, "Shady"), -// Pair(12, "Slim"), -// Pair(10, "name"), -// Pair(4, "my"), -// Pair(5, "chka"), -// Pair(3, "is"), -// ) -// } -// -// @Test -// fun `balance after remove - brother is right and black, both sons - black`() { -// rbTree.put(7, "hi") -// rbTree.put(4, "my") -// rbTree.put(10, "name") -// rbTree.put(9, "is") -// rbTree.put(12, "Slim") -// rbTree.put(11, "Shady") -// rbTree.remove(11) -// -// // now vertexes with keys 9 and 12 are black -// rbTree.remove(9) -// -// expectedResult = listOf(Pair(7, "hi"), Pair(10, "name"), Pair(12, "Slim"), Pair(4, "my")) -// } -// -// @Test -// fun `balance after remove - right brother is red`() { -// rbTree.put(60, "sixty") -// rbTree.put(33, "thirty-three") -// rbTree.put(84, "eighty-four") -// rbTree.put(15, "fifteen") -// rbTree.put(51, "fifty-one") -// rbTree.put(65, "sixty-five") -// rbTree.put(96, "ninety-six") -// rbTree.put(34, "thirty-four") -// rbTree.put(52, "Alblack") -// rbTree.put(94, "ninety-four") -// rbTree.put(97, "ninety-seven") -// rbTree.put(95, "ninety-five") -// -// // now vertex with key 96 is red, with key 65 - black -// rbTree.remove(65) -// -// expectedResult = -// listOf( -// Pair(60, "sixty"), -// Pair(96, "ninety-six"), -// Pair(97, "ninety-seven"), -// Pair(94, "ninety-four"), -// Pair(95, "ninety-five"), -// Pair(84, "eighty-four"), -// Pair(33, "thirty-three"), -// Pair(51, "fifty-one"), -// Pair(52, "Alblack"), -// Pair(34, "thirty-four"), -// Pair(15, "fifteen"), -// ) -// } -// -// @Test -// fun `balance after remove - brother is left and black, brother's rightSon - red`() { -// rbTree.put(7, "hi") -// rbTree.put(4, "my") -// rbTree.put(10, "name") -// rbTree.put(2, "is") -// rbTree.put(5, "chka") -// rbTree.put(9, "chka") -// rbTree.put(12, "chka") -// rbTree.put(1, "Slim") -// rbTree.put(3, "Shady") -// rbTree.remove(5) -// expectedResult = -// listOf( -// Pair(7, "hi"), -// Pair(10, "name"), -// Pair(12, "chka"), -// Pair(9, "chka"), -// Pair(2, "is"), -// Pair(4, "my"), -// Pair(3, "Shady"), -// Pair(1, "Slim"), -// ) -// } -// -// @Test -// fun `balance after remove - brother is left and black, brother's rightSon - red (leftSon - black)`() { -// rbTree.put(7, "hi") -// rbTree.put(4, "my") -// rbTree.put(10, "name") -// rbTree.put(2, "is") -// rbTree.put(5, "chka") -// rbTree.put(9, "chka") -// rbTree.put(12, "Slim") -// rbTree.put(3, "Shady") -// rbTree.remove(5) -// expectedResult = -// listOf( -// Pair(7, "hi"), -// Pair(10, "name"), -// Pair(12, "Slim"), -// Pair(9, "chka"), -// Pair(3, "Shady"), -// Pair(4, "my"), -// Pair(2, "is"), -// ) -// } -// -// @Test -// fun `balance after remove - brother is left and black, both sons - black`() { -// rbTree.put(7, "hi") -// rbTree.put(4, "my") -// rbTree.put(10, "name") -// rbTree.put(2, "is") -// rbTree.put(5, "Slim") -// rbTree.put(3, "Shady") -// rbTree.remove(3) -// -// // now vertexes with keys 2 and 5 are black -// rbTree.remove(5) -// -// expectedResult = listOf(Pair(7, "hi"), Pair(10, "name"), Pair(4, "my"), Pair(2, "is")) -// } -// -// @Test -// fun `balance after remove - left brother is red`() { -// rbTree.put(60, "sixty") -// rbTree.put(33, "thirty-three") -// rbTree.put(84, "eighty-four") -// rbTree.put(15, "fifteen") -// rbTree.put(51, "fifty-one") -// rbTree.put(65, "sixty-five") -// rbTree.put(96, "ninety-six") -// rbTree.put(5, "five") -// rbTree.put(27, "twenty-seven") -// rbTree.put(61, "sixty-one") -// rbTree.put(69, "sixty-nine") -// rbTree.put(17, "seventeen") -// -// // now vertex with key 15 is red, with key 51 - black -// rbTree.remove(51) -// -// expectedResult = -// listOf( -// Pair(60, "sixty"), -// Pair(84, "eighty-four"), -// Pair(96, "ninety-six"), -// Pair(65, "sixty-five"), -// Pair(69, "sixty-nine"), -// Pair(61, "sixty-one"), -// Pair(15, "fifteen"), -// Pair(27, "twenty-seven"), -// Pair(33, "thirty-three"), -// Pair(17, "seventeen"), -// Pair(5, "five"), -// ) -// } + @Test + fun `balance after remove - brother is right and black, brother's rightSon - red`() { + rbTree.put(7, "hi") + rbTree.put(4, "my") + rbTree.put(10, "name") + rbTree.put(3, "is") + rbTree.put(5, "chka") + rbTree.put(9, "chka") + rbTree.put(12, "chka") + rbTree.put(11, "Slim") + rbTree.put(13, "Shady") + rbTree.remove(9) + expectedResult = + listOf( + Pair(7, "hi"), + Pair(12, "chka"), + Pair(13, "Shady"), + Pair(10, "name"), + Pair(11, "Slim"), + Pair(4, "my"), + Pair(5, "chka"), + Pair(3, "is"), + ) + } + + @Test + fun `balance after remove - brother is right and black, brother's leftSon - red (rightSon - black)`() { + rbTree.put(7, "hi") + rbTree.put(4, "my") + rbTree.put(10, "name") + rbTree.put(3, "is") + rbTree.put(5, "chka") + rbTree.put(9, "chka") + rbTree.put(12, "Slim") + rbTree.put(11, "Shady") + rbTree.remove(9) + expectedResult = + listOf( + Pair(7, "hi"), + Pair(11, "Shady"), + Pair(12, "Slim"), + Pair(10, "name"), + Pair(4, "my"), + Pair(5, "chka"), + Pair(3, "is"), + ) + } + + @Test + fun `balance after remove - brother is right and black, both sons - black`() { + rbTree.put(7, "hi") + rbTree.put(4, "my") + rbTree.put(10, "name") + rbTree.put(9, "is") + rbTree.put(12, "Slim") + rbTree.put(11, "Shady") + rbTree.remove(11) + + // now vertexes with keys 9 and 12 are black + rbTree.remove(9) + + expectedResult = listOf(Pair(7, "hi"), Pair(10, "name"), Pair(12, "Slim"), Pair(4, "my")) + } + + @Test + fun `balance after remove - right brother is red`() { + rbTree.put(60, "sixty") + rbTree.put(33, "thirty-three") + rbTree.put(84, "eighty-four") + rbTree.put(15, "fifteen") + rbTree.put(51, "fifty-one") + rbTree.put(65, "sixty-five") + rbTree.put(96, "ninety-six") + rbTree.put(34, "thirty-four") + rbTree.put(52, "Alblack") + rbTree.put(94, "ninety-four") + rbTree.put(97, "ninety-seven") + rbTree.put(95, "ninety-five") + + // now vertex with key 96 is red, with key 65 - black + rbTree.remove(65) + + expectedResult = + listOf( + Pair(60, "sixty"), + Pair(96, "ninety-six"), + Pair(97, "ninety-seven"), + Pair(94, "ninety-four"), + Pair(95, "ninety-five"), + Pair(84, "eighty-four"), + Pair(33, "thirty-three"), + Pair(51, "fifty-one"), + Pair(52, "Alblack"), + Pair(34, "thirty-four"), + Pair(15, "fifteen"), + ) + } + + @Test + fun `balance after remove - brother is left and black, brother's rightSon - red`() { + rbTree.put(7, "hi") + rbTree.put(4, "my") + rbTree.put(10, "name") + rbTree.put(2, "is") + rbTree.put(5, "chka") + rbTree.put(9, "chka") + rbTree.put(12, "chka") + rbTree.put(1, "Slim") + rbTree.put(3, "Shady") + rbTree.remove(5) + expectedResult = + listOf( + Pair(7, "hi"), + Pair(10, "name"), + Pair(12, "chka"), + Pair(9, "chka"), + Pair(2, "is"), + Pair(4, "my"), + Pair(3, "Shady"), + Pair(1, "Slim"), + ) + } + + @Test + fun `balance after remove - brother is left and black, brother's rightSon - red (leftSon - black)`() { + rbTree.put(7, "hi") + rbTree.put(4, "my") + rbTree.put(10, "name") + rbTree.put(2, "is") + rbTree.put(5, "chka") + rbTree.put(9, "chka") + rbTree.put(12, "Slim") + rbTree.put(3, "Shady") + rbTree.remove(5) + expectedResult = + listOf( + Pair(7, "hi"), + Pair(10, "name"), + Pair(12, "Slim"), + Pair(9, "chka"), + Pair(3, "Shady"), + Pair(4, "my"), + Pair(2, "is"), + ) + } + + @Test + fun `balance after remove - brother is left and black, both sons - black`() { + rbTree.put(7, "hi") + rbTree.put(4, "my") + rbTree.put(10, "name") + rbTree.put(2, "is") + rbTree.put(5, "Slim") + rbTree.put(3, "Shady") + rbTree.remove(3) + + // now vertexes with keys 2 and 5 are black + rbTree.remove(5) + + expectedResult = listOf(Pair(7, "hi"), Pair(10, "name"), Pair(4, "my"), Pair(2, "is")) + } + + @Test + fun `balance after remove - left brother is red`() { + rbTree.put(60, "sixty") + rbTree.put(33, "thirty-three") + rbTree.put(84, "eighty-four") + rbTree.put(15, "fifteen") + rbTree.put(51, "fifty-one") + rbTree.put(65, "sixty-five") + rbTree.put(96, "ninety-six") + rbTree.put(5, "five") + rbTree.put(27, "twenty-seven") + rbTree.put(61, "sixty-one") + rbTree.put(69, "sixty-nine") + rbTree.put(17, "seventeen") + + // now vertex with key 15 is red, with key 51 - black + rbTree.remove(51) + + expectedResult = + listOf( + Pair(60, "sixty"), + Pair(84, "eighty-four"), + Pair(96, "ninety-six"), + Pair(65, "sixty-five"), + Pair(69, "sixty-nine"), + Pair(61, "sixty-one"), + Pair(15, "fifteen"), + Pair(27, "twenty-seven"), + Pair(33, "thirty-three"), + Pair(17, "seventeen"), + Pair(5, "five"), + ) + } @Test fun `test secondary constructor`() { From ccc41af52be37b7c47699b0486627de4e87bba8c Mon Sep 17 00:00:00 2001 From: Kostya Date: Sun, 7 Apr 2024 02:42:53 +0300 Subject: [PATCH 13/15] feat: finally add tests reports --- .github/workflows/coverage.yml | 1 - lib/src/main/kotlin/trees/RBSearchTree.kt | 154 +++++++++++----------- 2 files changed, 77 insertions(+), 78 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 4a4fa5b..08e66a4 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -50,7 +50,6 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} title: '# 5⃣2⃣ Coverage Report' update-comment: true - skip-if-no-changes: true min-coverage-overall: 40 min-coverage-changed-files: 60 pass-emoji: '🥳' diff --git a/lib/src/main/kotlin/trees/RBSearchTree.kt b/lib/src/main/kotlin/trees/RBSearchTree.kt index 45bc2a1..dfaaa7e 100644 --- a/lib/src/main/kotlin/trees/RBSearchTree.kt +++ b/lib/src/main/kotlin/trees/RBSearchTree.kt @@ -61,7 +61,7 @@ class RBSearchTree : AbstractBinarySearchTree> { if (vertex == root && size == 0L) { root = null } else if (needToBalance(vertex)) { -// balanceAfterRemove(vertex) + balanceAfterRemove(vertex) } return value @@ -125,82 +125,82 @@ class RBSearchTree : AbstractBinarySearchTree> { * rotate left. We move conflict on level below, then we look at the previous cases * @param vertex The child vertex of the removed vertex or null if the removed vertex had no children. */ -// private fun balanceAfterRemove(vertex: RBVertex?) { -// var currentVertex = vertex -// while (currentVertex != root && (currentVertex?.isRed == false || currentVertex == null)) { -// var brother: RBVertex? -// if (currentVertex == currentVertex?.parent?.leftSon) { -// brother = currentVertex?.parent?.rightSon -// -// if (brother?.isRed == true) { -// brother.isRed = false -// currentVertex?.parent?.isRed = true -// val vertexForRotate = currentVertex?.parent -// vertexForRotate?.let { rotateLeft(vertexForRotate) } -// brother = currentVertex?.parent?.rightSon -// } -// -// if ((brother?.leftSon?.isRed == false || brother?.leftSon == null) && -// (brother?.rightSon?.isRed == false || brother?.rightSon == null) -// ) { -// brother?.isRed = true -// currentVertex = currentVertex?.parent -// if (vertex == currentVertex?.leftSon) currentVertex?.leftSon = null -// } else { -// if (brother.rightSon?.isRed == false || brother.rightSon == null) { -// brother.leftSon?.isRed = false -// brother.isRed = true -// rotateRight(brother) -// brother = currentVertex?.parent?.rightSon -// } -// -// val parentColor = currentVertex?.parent?.isRed -// parentColor?.let { brother?.isRed = parentColor } -// currentVertex?.parent?.isRed = false -// brother?.rightSon?.isRed = false -// val vertexForRotate = currentVertex?.parent -// vertexForRotate?.let { rotateLeft(vertexForRotate) } -// if (currentVertex == vertex) currentVertex?.parent?.leftSon = null -// currentVertex = root -// } -// } else { -// brother = currentVertex?.parent?.leftSon -// -// if (brother?.isRed == true) { -// brother.isRed = false -// currentVertex?.parent?.isRed = true -// val vertexForRotate = currentVertex?.parent -// vertexForRotate?.let { rotateRight(vertexForRotate) } -// brother = currentVertex?.parent?.leftSon -// } -// -// if ((brother?.leftSon?.isRed == false || brother?.leftSon == null) && -// (brother?.rightSon?.isRed == false || brother?.rightSon == null) -// ) { -// brother?.isRed = true -// currentVertex = currentVertex?.parent -// if (vertex == currentVertex?.rightSon) currentVertex?.rightSon = null -// } else { -// if (brother.leftSon?.isRed == false || brother.leftSon == null) { -// brother.rightSon?.isRed = false -// brother.isRed = true -// rotateLeft(brother) -// brother = currentVertex?.parent?.leftSon -// } -// -// val parentColor = currentVertex?.parent?.isRed -// parentColor?.let { brother?.isRed = parentColor } -// currentVertex?.parent?.isRed = false -// brother?.leftSon?.isRed = false -// val vertexForRotate = currentVertex?.parent -// vertexForRotate?.let { rotateRight(vertexForRotate) } -// if (currentVertex == vertex) currentVertex?.parent?.rightSon = null -// currentVertex = root -// } -// } -// } -// currentVertex?.isRed = false -// } + private fun balanceAfterRemove(vertex: RBVertex?) { + var currentVertex = vertex + while (currentVertex != root && (currentVertex?.isRed == false || currentVertex == null)) { + var brother: RBVertex? + if (currentVertex == currentVertex?.parent?.leftSon) { + brother = currentVertex?.parent?.rightSon + + if (brother?.isRed == true) { + brother.isRed = false + currentVertex?.parent?.isRed = true + val vertexForRotate = currentVertex?.parent + vertexForRotate?.let { rotateLeft(vertexForRotate) } + brother = currentVertex?.parent?.rightSon + } + + if ((brother?.leftSon?.isRed == false || brother?.leftSon == null) && + (brother?.rightSon?.isRed == false || brother?.rightSon == null) + ) { + brother?.isRed = true + currentVertex = currentVertex?.parent + if (vertex == currentVertex?.leftSon) currentVertex?.leftSon = null + } else { + if (brother.rightSon?.isRed == false || brother.rightSon == null) { + brother.leftSon?.isRed = false + brother.isRed = true + rotateRight(brother) + brother = currentVertex?.parent?.rightSon + } + + val parentColor = currentVertex?.parent?.isRed + parentColor?.let { brother?.isRed = parentColor } + currentVertex?.parent?.isRed = false + brother?.rightSon?.isRed = false + val vertexForRotate = currentVertex?.parent + vertexForRotate?.let { rotateLeft(vertexForRotate) } + if (currentVertex == vertex) currentVertex?.parent?.leftSon = null + currentVertex = root + } + } else { + brother = currentVertex?.parent?.leftSon + + if (brother?.isRed == true) { + brother.isRed = false + currentVertex?.parent?.isRed = true + val vertexForRotate = currentVertex?.parent + vertexForRotate?.let { rotateRight(vertexForRotate) } + brother = currentVertex?.parent?.leftSon + } + + if ((brother?.leftSon?.isRed == false || brother?.leftSon == null) && + (brother?.rightSon?.isRed == false || brother?.rightSon == null) + ) { + brother?.isRed = true + currentVertex = currentVertex?.parent + if (vertex == currentVertex?.rightSon) currentVertex?.rightSon = null + } else { + if (brother.leftSon?.isRed == false || brother.leftSon == null) { + brother.rightSon?.isRed = false + brother.isRed = true + rotateLeft(brother) + brother = currentVertex?.parent?.leftSon + } + + val parentColor = currentVertex?.parent?.isRed + parentColor?.let { brother?.isRed = parentColor } + currentVertex?.parent?.isRed = false + brother?.leftSon?.isRed = false + val vertexForRotate = currentVertex?.parent + vertexForRotate?.let { rotateRight(vertexForRotate) } + if (currentVertex == vertex) currentVertex?.parent?.rightSon = null + currentVertex = root + } + } + } + currentVertex?.isRed = false + } /** * Finds a vertex by corresponding key. If such vertex doesn't exist returns null. From 9a346bd66f96001a3f469281fc8f9394633980ab Mon Sep 17 00:00:00 2001 From: Kostya Date: Sun, 7 Apr 2024 02:49:09 +0300 Subject: [PATCH 14/15] chore: change emoji --- .github/workflows/coverage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 08e66a4..bcd858c 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -48,7 +48,7 @@ jobs: ${{ github.workspace }}/**/build/reports/jacoco/prodNormalDebugCoverage/prodNormalDebugCoverage.xml, ${{ github.workspace }}/**/build/reports/jacoco/**/debugCoverage.xml token: ${{ secrets.GITHUB_TOKEN }} - title: '# 5⃣2⃣ Coverage Report' + title: '# 🇷🇺 Coverage Report' update-comment: true min-coverage-overall: 40 min-coverage-changed-files: 60 From 4f0bcb275fb2720e48590814a3e10b0dc2248da7 Mon Sep 17 00:00:00 2001 From: Kostya Date: Mon, 8 Apr 2024 01:16:57 +0300 Subject: [PATCH 15/15] ci: add right path to xml --- .github/workflows/coverage.yml | 2 +- lib/build.gradle.kts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index bcd858c..8e40a86 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -45,7 +45,7 @@ jobs: uses: madrapps/jacoco-report@v1.6.1 with: paths: | - ${{ github.workspace }}/**/build/reports/jacoco/prodNormalDebugCoverage/prodNormalDebugCoverage.xml, + ${{ github.workspace }}/lib/build/reports/jacoco/test/jacocoTestReport.xml, ${{ github.workspace }}/**/build/reports/jacoco/**/debugCoverage.xml token: ${{ secrets.GITHUB_TOKEN }} title: '# 🇷🇺 Coverage Report' diff --git a/lib/build.gradle.kts b/lib/build.gradle.kts index aa9fc85..0d9f8ce 100644 --- a/lib/build.gradle.kts +++ b/lib/build.gradle.kts @@ -49,7 +49,7 @@ tasks.named("jacocoTestReport") { dependsOn(tasks.test) reports { csv.required = true - xml.required = false + xml.required = true html.outputLocation = layout.buildDirectory.dir("jacocoHtml") } }