Skip to content

Commit

Permalink
fixed a bug that thrown exception with certain numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
yamin8000 committed Jul 24, 2023
1 parent 6fbc098 commit 839573a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Persian_Numbers/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ android {
defaultConfig {
minSdkVersion 16
targetSdkVersion 33
versionCode 4
versionName "2.0.0"
versionCode 5
versionName "2.0.1"
consumerProguardFiles "consumer-rules.pro"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,17 @@ object PersianDigits {
}

private fun processTwoDigitsNumber(number: String): String {
if (number.length != 2) spellUnknownNumber(number)
val oneNotation = "${number[1]}".toLong()
val tenNotation = ("${number[0]}".toLong()) * 10
return "${twoDigits[tenNotation]} $AND ${singleDigits[oneNotation]}"
}

private fun processThreeDigitsNumber(number: String): String {
val oneNotation = "${number[2]}".toLong()
val tenNotation = (("${number[1]}".toLong()) * 10) + oneNotation
if (number.length != 3) spellUnknownNumber(number)
val smallNotations = number.drop(1)
val hundredNotation = ("${number[0]}".toLong()) * 100
return "${threeDigits[hundredNotation]} $AND ${spellTwoDigitsNumber("$tenNotation")}"
return "${threeDigits[hundredNotation]} $AND ${spellUnknownNumber(smallNotations)}"
}

private fun spellFourDigitsAndMoreNumber(number: String): String {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.github.yamin8000.ppn

import com.github.yamin8000.ppn.PersianHelpers.spellToPersian
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

class MehdiTests {

@Test
fun firstMehdiTests() {
assertEquals("یکصد و یک", 101.spellToPersian())
}

@Test
fun otherMehdiTests() {
assertEquals("دویست و دو", 202.spellToPersian())
assertEquals("یک هزار و یکصد و یک", 1101.spellToPersian())
assertEquals("نود و نه هزار و نهصد و نه", 99_909.spellToPersian())
assertEquals("پانصد و پنجاه و پنج هزار و پانصد و پنج", 555_505.spellToPersian())
assertEquals("یک هزار و پنج", 1005.spellToPersian())
assertEquals("یک هزار و پانصد و پنج", 1505.spellToPersian())
}
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.0.1'
classpath 'com.android.tools.build:gradle:8.0.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down

0 comments on commit 839573a

Please sign in to comment.