Skip to content

Commit

Permalink
closes #51
Browse files Browse the repository at this point in the history
  • Loading branch information
yamin8000 committed May 27, 2023
1 parent 09e3f01 commit cfd0394
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,11 @@ import java.math.BigInteger

internal object Constants {

private const val ZERO_ONLY_REGEX = "0+"
private const val DECIMAL_REGEX = "\\d*\\.\\d+"

internal const val NaN = "NaN"
internal const val zeroChar = '0'
internal const val dashChar = '-'
internal const val dotChar = '.'

internal val zeroOnlyRegex: Regex by lazy(LazyThreadSafetyMode.NONE) { Regex(ZERO_ONLY_REGEX) }
internal val decimalRegex: Regex by lazy(LazyThreadSafetyMode.NONE) { Regex(DECIMAL_REGEX) }

internal val zeroBigInteger: BigInteger by lazy(LazyThreadSafetyMode.NONE) { BigInteger.ZERO }
internal val oneBigInteger: BigInteger by lazy(LazyThreadSafetyMode.NONE) { BigInteger.ONE }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,38 @@ import org.junit.jupiter.api.Test

class MainTests {


@Test
fun singleDigitTest() {
fun normalTests() {
assertEquals("دوازده", PersianDigits.spellToPersian(12))
assertEquals("صفر", PersianDigits.spellToPersian(0))
assertEquals("دو", "02".spellToPersian())
assertEquals("یک", 1.spellToPersian())
assertEquals("نه", 9.spellToPersian())
}

@Test
fun negativeTest() {
assertEquals("منفی یکصد و بیست و چهار", PersianDigits.spellToPersian(-124))
assertEquals("صفر", "-00".spellToPersian())
assertEquals("NaN", "-".spellToPersian())
assertEquals("منفی یک دهم", "-.1".spellToPersian())
}

@Test
fun decimalTest() {
assertEquals("یکصد و بیست و چهار ممیز یک، صدم", PersianDigits.spellToPersian(124.01))
assertEquals("سه ممیز چهارده، صدم", 3.14.spellToPersian())
}

@Test
fun edgeCases() {
assertEquals(
"دوازده میلیارد و یکصد و بیست و سه میلیون و سیصد و دوازده هزار و یکصد و بیست و سه",
12_123_312_123.spellToPersian()
)
assertEquals(
"پنج میلیون و یکصد و بیست و یک هزار و سیصد و بیست و یک",
PersianDigits.spellToPersian("5121321")
)
assertEquals("NaN", "-".spellToPersian())
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
android.enableJetifier=false
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official
org.gradle.parallel=true
Expand Down

0 comments on commit cfd0394

Please sign in to comment.