Skip to content

Commit

Permalink
Small refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ashtanko committed Nov 1, 2024
1 parent d9ae550 commit 25b27c6
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 20 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ optimizations.

## Metrics

* 275 number of properties
* 272 number of properties

* 229 number of functions
* 231 number of functions

* 140 number of classes

Expand All @@ -57,15 +57,15 @@ optimizations.

## Complexity Report

* 7,634 lines of code (loc)
* 7,633 lines of code (loc)

* 3,710 source lines of code (sloc)

* 2,870 logical lines of code (lloc)

* 3,361 comment lines of code (cloc)

* 425 cyclomatic complexity (mcc)
* 427 cyclomatic complexity (mcc)

* 214 cognitive complexity

Expand All @@ -79,4 +79,4 @@ optimizations.

## Findings (0)

generated with [detekt version 1.23.7](https://detekt.dev/) on 2024-11-01 19:17:21 UTC
generated with [detekt version 1.23.7](https://detekt.dev/) on 2024-11-01 19:30:41 UTC
10 changes: 5 additions & 5 deletions diktat-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -393,18 +393,18 @@
# robustness and readability of code, because `var` variables can be reassigned several times in the business logic.
# This rule prohibits usage of `var`s as local variables - the only exception is accumulators and counters
- name: SAY_NO_TO_VAR
enabled: false # todo temporary disabled
enabled: true
# Inspection that checks if string template has redundant quotes
- name: STRING_TEMPLATE_QUOTES
enabled: false # todo temporary disabled
enabled: true
# Check if there are redundant nested if-statements, which could be collapsed into a single one by concatenating their conditions
- name: COLLAPSE_IF_STATEMENTS
enabled: true
configuration:
startCollapseFromNestedLevel: 2
# Checks that floating-point values are not used in arithmetic expressions
- name: FLOAT_IN_ACCURATE_CALCULATIONS
enabled: false # todo temporary disabled
enabled: true
# Checks that function length isn't too long
- name: TOO_LONG_FUNCTION
enabled: true
Expand Down Expand Up @@ -484,7 +484,7 @@
# Developer expects to get the value of the property, but receives some unknown value and some extra side effect hidden by the custom getter/setter.
# Use extra functions for it instead.
- name: CUSTOM_GETTERS_SETTERS
enabled: false # todo temporary disabled
enabled: true
# Checks if null-check was used explicitly (for example: if (a == null))
# Try to avoid explicit null checks (explicit comparison with `null`)
# Kotlin is declared as [Null-safe](https://kotlinlang.org/docs/reference/null-safety.html) language.
Expand Down Expand Up @@ -537,7 +537,7 @@
isRangeToIgnore: false
# Check if there is a call of print()\println() or console.log(). Assumption that it's a debug print
- name: DEBUG_PRINT
enabled: false # todo temporary disabled
enabled: true
# Check that typealias name is in PascalCase
- name: TYPEALIAS_NAME_INCORRECT_CASE
enabled: true
Expand Down
5 changes: 1 addition & 4 deletions src/main/kotlin/dev/shtanko/algorithms/extensions/DoubleX.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@

package dev.shtanko.algorithms.extensions

private const val EVEN_DIVISOR = 2.0

/**
* Checks if a Double value is even.
*
* @return `true` if the Double value is even, `false` otherwise.
*/
val Double.isEven: Boolean
get() = this % EVEN_DIVISOR == 0.0
fun Double.isEven(): Boolean = (this % 2).toInt() == 0
3 changes: 1 addition & 2 deletions src/main/kotlin/dev/shtanko/algorithms/extensions/IntX.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ val isEven = IntPredicate { it % EVEN_DIVISOR == 0 }
*
* @return `true` if the Int value is even, `false` otherwise.
*/
val Int.isEven: Boolean
get() = this % EVEN_DIVISOR == 0
fun Int.isEven(): Boolean = this % EVEN_DIVISOR == 0

/**
* Generates an IntArray of the specified size with random values.
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/dev/shtanko/algorithms/math/Sqrt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fun sqrt(
}
var approximation = number
while (abs(approximation - number / approximation) > tolerance * approximation) {
approximation = (number / approximation + approximation) / 2.0
approximation = (number / approximation + approximation) / 2
}
return approximation
}
1 change: 1 addition & 0 deletions src/main/kotlin/dev/shtanko/algorithms/sorts/HeapSort.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ data object HeapSort : Sortable {
* @param index The index of the current element in the heap.
* @param T The type of elements in the array, must be comparable.
*/
@Suppress("SAY_NO_TO_VAR")
private fun <T : Comparable<T>> heapify(
array: Array<T>,
size: Int,
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/dev/shtanko/algorithms/utils/MeasureTime.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ fun measureTime(
* @param array The array associated with the task.
* @param task The task to measure the execution time of.
*/
@Suppress("DEBUG_PRINT")
fun measureTime(
strategy: Sortable,
array: IntArray,
Expand All @@ -74,6 +75,7 @@ fun measureTime(
* @param taskName The name of the task.
* @param task The task to measure the execution time of.
*/
@Suppress("DEBUG_PRINT")
fun measureTime(
taskName: String,
task: () -> Unit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ class DoubleXTest {
@ParameterizedTest(name = "For example, value {0} is even.")
@ValueSource(doubles = [2.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0, 16.0, 18.0, 20.0, 100.0])
fun `is even test`(value: Double) {
assertThat(value.isEven).isTrue
assertThat(value.isEven()).isTrue
}

@DisplayName("Test only odd numbers")
@ParameterizedTest(name = "For example, value {0} is not even.")
@ValueSource(doubles = [1.0, 11.0, 21.0, 31.0, 41.0, 51.0, 61.0, 71.0, 81.0, 91.0, 3.0, 13.0])
fun `is odd test`(value: Double) {
assertThat(value.isEven).isFalse
assertThat(value.isEven()).isFalse
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class IntXTest {
@ParameterizedTest
@ArgumentsSource(InputIsEvenArgumentsProvider::class)
fun `is even test`(n: Int, expected: Boolean) {
val actual = n.isEven
val actual = n.isEven()
assertThat(actual).isEqualTo(expected)
}

Expand Down

0 comments on commit 25b27c6

Please sign in to comment.