Skip to content

Commit

Permalink
write removeOrdinalSuffix. closes #15
Browse files Browse the repository at this point in the history
  • Loading branch information
moeindev committed Apr 24, 2021
1 parent 4799339 commit b73261a
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,40 @@ object OrdinalSuffix {
}
}

/**
* removes ordinal suffix from the given alphabetical number
*
* @param string [String] number
*
* @return Suffix [String]
*
* @author Moein
*/
fun removeOrdinalSuffix(string: String): String {
var word = string.replace("مین","")
.replace(" ام", "").replace(" اُم","")

if (word.endsWith("سوم")) {
word = word.substring(0,word.length - 3) + "سه"
} else if (word.endsWith("م")) {
word = word.substring(0, word.length - 1)
}

return word
}
}

/**
* Add ordinal suffix extension
* This extension uses [OrdinalSuffix.addOrdinalSuffix] function
*
*/
fun String.addOrdinalSuffix(): String = OrdinalSuffix.addOrdinalSuffix(this)
fun String.addOrdinalSuffix(): String = OrdinalSuffix.addOrdinalSuffix(this)


/**
* Remove ordinal suffix extension
*
* This extension uses [OrdinalSuffix.removeOrdinalSuffix] function
*/
fun String.removeOrdinalSuffix(): String = OrdinalSuffix.removeOrdinalSuffix(this)
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,23 @@ class OrdinalSuffixTest {
"سی دو,سی دوم",
"ده,دهم",
])
fun `ordinal suffix result is true`(input: String, excepted: String) {
fun `add ordinal suffix result is true`(input: String, excepted: String) {
assertThat(OrdinalSuffix.addOrdinalSuffix(input)).isEqualTo(excepted)
}


@ParameterizedTest
@CsvSource(value = [
"پنجاه سه,پنجاه سوم",
"سی دو,سی دوم",
"شصت,شصتم",
"سی,سی اُم",
"سی دو,سی دوم",
"ده,دهم",
])
fun `remove ordinal suffix result is true`(excepted: String, input: String) {
assertThat(OrdinalSuffix.removeOrdinalSuffix(input)).isEqualTo(excepted)
}
}

@Nested
Expand All @@ -35,8 +49,22 @@ class OrdinalSuffixTest {
"سی دو,سی دوم",
"ده,دهم",
])
fun `ordinal suffix result is true`(input: String, excepted: String) {
fun `add ordinal suffix result is true`(input: String, excepted: String) {
assertThat(input.addOrdinalSuffix()).isEqualTo(excepted)
}


@ParameterizedTest
@CsvSource(value = [
"پنجاه سه,پنجاه سوم",
"سی دو,سی دوم",
"شصت,شصتم",
"سی,سی اُم",
"سی دو,سی دوم",
"ده,دهم",
])
fun `remove ordinal suffix result is true`(excepted: String, input: String) {
assertThat(input.removeOrdinalSuffix()).isEqualTo(excepted)
}
}
}

0 comments on commit b73261a

Please sign in to comment.