Skip to content

Commit

Permalink
Refactor constants
Browse files Browse the repository at this point in the history
  • Loading branch information
ashtanko committed Apr 2, 2024
1 parent 6c6b4d0 commit ef83feb
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 28 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,26 @@ optimizations.

## Complexity Report

* 6,718 lines of code (loc)
* 6,782 lines of code (loc)

* 3,497 source lines of code (sloc)
* 3,511 source lines of code (sloc)

* 2,668 logical lines of code (lloc)
* 2,669 logical lines of code (lloc)

* 2,689 comment lines of code (cloc)
* 2,728 comment lines of code (cloc)

* 405 cyclomatic complexity (mcc)

* 205 cognitive complexity

* 0 number of total code smells

* 76% comment source ratio
* 77% comment source ratio

* 151 mcc per 1,000 lloc

* 0 code smells per 1,000 lloc

## Findings (0)

generated with [detekt version 1.23.5](https://detekt.dev/) on 2024-04-02 23:23:38 UTC
generated with [detekt version 1.23.5](https://detekt.dev/) on 2024-04-02 23:34:50 UTC
76 changes: 64 additions & 12 deletions src/main/kotlin/dev/shtanko/algorithms/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,67 @@

package dev.shtanko.algorithms

internal const val DECIMAL = 10
internal const val OCTAL = 8
internal const val HEXADECIMAL = 16
internal const val SHUFFLE = 0xFFFF
internal const val MOD = 1_000_000_007
internal const val BILLION = 1e9
internal const val BYTE = 1024
internal const val MILLISECOND = 1000L
internal const val EPSILON = 1e-5
internal const val BIN_FORMAT = "%.1f %cB"
internal const val SI_FORMAT = "%.1f %ciB"
internal const val ALPHABET_LETTERS_COUNT = 26
/**
* Constants used across the application.
*/
internal data object Constants {
/**
* Base for decimal numbers.
*/
const val DECIMAL = 10

/**
* Base for octal numbers.
*/
const val OCTAL = 8

/**
* Base for hexadecimal numbers.
*/
const val HEXADECIMAL = 16

/**
* Constant used for shuffling.
*/
const val SHUFFLE = 0xFFFF

/**
* Modulus constant.
*/
const val MOD = 1_000_000_007

/**
* Constant representing one billion.
*/
const val BILLION = 1e9

/**
* Constant representing a byte (1024 bits).
*/
const val BYTE = 1024

/**
* Constant representing a millisecond.
*/
const val MILLISECOND = 1000L

/**
* Small constant used for floating point comparisons.
*/
const val EPSILON = 1e-5

/**
* Format for binary size representation.
*/
const val BIN_FORMAT = "%.1f %cB"

/**
* Format for SI size representation.
*/
const val SI_FORMAT = "%.1f %ciB"

/**
* Number of letters in the English alphabet.
*/
const val ALPHABET_LETTERS_COUNT = 26
}
2 changes: 1 addition & 1 deletion src/main/kotlin/dev/shtanko/algorithms/extensions/LongX.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

package dev.shtanko.algorithms.extensions

import dev.shtanko.algorithms.DECIMAL
import dev.shtanko.algorithms.Constants.DECIMAL

/**
* Checks if a Long number is a super palindrome.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

package dev.shtanko.algorithms.leetcode

import dev.shtanko.algorithms.ALPHABET_LETTERS_COUNT
import dev.shtanko.algorithms.Constants.ALPHABET_LETTERS_COUNT

/**
* 2262. Total Appeal of A String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

package dev.shtanko.algorithms.math

import dev.shtanko.algorithms.DECIMAL
import dev.shtanko.algorithms.Constants.DECIMAL
import kotlin.math.pow

/**
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 @@ -24,7 +24,7 @@

package dev.shtanko.algorithms.math

import dev.shtanko.algorithms.EPSILON
import dev.shtanko.algorithms.Constants.EPSILON
import kotlin.math.abs

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/dev/shtanko/algorithms/utils/ByteFormatter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

package dev.shtanko.algorithms.utils

import dev.shtanko.algorithms.BIN_FORMAT
import dev.shtanko.algorithms.SI_FORMAT
import dev.shtanko.algorithms.Constants.BIN_FORMAT
import dev.shtanko.algorithms.Constants.SI_FORMAT
import java.util.Locale

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

package dev.shtanko.algorithms.utils

import dev.shtanko.algorithms.BYTE
import dev.shtanko.algorithms.DECIMAL
import dev.shtanko.algorithms.Constants.BYTE
import dev.shtanko.algorithms.Constants.DECIMAL
import java.text.CharacterIterator
import java.text.StringCharacterIterator
import java.util.Locale
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

package dev.shtanko.algorithms.utils

import dev.shtanko.algorithms.MILLISECOND
import dev.shtanko.algorithms.Constants.MILLISECOND
import java.util.concurrent.TimeUnit

/**
Expand Down
12 changes: 12 additions & 0 deletions src/test/kotlin/dev/shtanko/algorithms/ConstantsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@

package dev.shtanko.algorithms

import dev.shtanko.algorithms.Constants.ALPHABET_LETTERS_COUNT
import dev.shtanko.algorithms.Constants.BILLION
import dev.shtanko.algorithms.Constants.BIN_FORMAT
import dev.shtanko.algorithms.Constants.BYTE
import dev.shtanko.algorithms.Constants.DECIMAL
import dev.shtanko.algorithms.Constants.EPSILON
import dev.shtanko.algorithms.Constants.HEXADECIMAL
import dev.shtanko.algorithms.Constants.MILLISECOND
import dev.shtanko.algorithms.Constants.MOD
import dev.shtanko.algorithms.Constants.OCTAL
import dev.shtanko.algorithms.Constants.SHUFFLE
import dev.shtanko.algorithms.Constants.SI_FORMAT
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

package dev.shtanko.algorithms.math

import dev.shtanko.algorithms.EPSILON
import dev.shtanko.algorithms.Constants.EPSILON
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test
Expand Down

0 comments on commit ef83feb

Please sign in to comment.