Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
BSN4 committed Nov 16, 2017
2 parents 61ff7d0 + e25352a commit d641d81
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 27 deletions.
11 changes: 5 additions & 6 deletions src/numberedStringOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public function sort($array)
* Words to numbers.
*
* @param string $str
* @param bool $normalized
*
* @param bool $normalized
* @return int
*/
public function wordsToNumbers($str, $normalized = false)
Expand Down Expand Up @@ -144,14 +144,14 @@ protected function englishWordsToNumbers($str)

/**
* @param string $str
* @param bool $normalized
*
* @param bool $normalized
* @return int|mixed
*/
protected function arabicWordsToNumbers($str, $normalized)
{
// Normalization phase
if(!$normalized) {
if (!$normalized) {
$str = $this->normalizeText($str);
}

Expand Down Expand Up @@ -236,8 +236,6 @@ protected function arabicWordsToNumbers($str, $normalized)
'ثمانمئة' => 800,
'تسعمئة' => 900,



'مئة' => 100,
'الف' => 1000,
'الفان' => 2000,
Expand All @@ -262,7 +260,7 @@ protected function arabicWordsToNumbers($str, $normalized)

foreach ($complications as $complication => $by) {
$subTotal = 0;
if (preg_match("/(.*)\s*{$complication}/", $str, $result) !== false && isset($result[1])) {
if (preg_match("/(.*)\s*{$complication}/", $str, $result) !== false && isset($result[1])) {
$result = " {$result[1]} ";

foreach ($spell as $word => $value) {
Expand Down Expand Up @@ -334,6 +332,7 @@ protected function compile($array)
$result[$string] = trim($needle);
} elseif (preg_match('/(\d+)\s+$/', $needle, $num)) {
$sort = trim($num[0]);

$result[$string] = $sort;
} else {
$ar_int = $this->wordsToNumbers($needle, true);
Expand Down
37 changes: 16 additions & 21 deletions tests/numberedStringOrderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected function setUp()
/** @test */
public function english_words()
{
$orderdArray = $this->numberedStringOrder->sort([
$orderdArray = $this->numberedStringOrder->sort([
'30 hundreds',
'30 millions, 24 thousands, 20 hundreds',
'30 millions, 25 thousands, 20 hundreds',
Expand All @@ -31,8 +31,6 @@ public function english_words()
'14 hundreds',
]);



$expected = [
14,
20,
Expand All @@ -43,10 +41,9 @@ public function english_words()
'30 millions, 24 thousands, 20 hundreds',
'30 millions, 25 thousands, 20 hundreds',
'30 millions, 25 thousands, 21 hundreds',
'14 billions'
'14 billions',
];


$this->assertEquals($expected, $orderdArray);
}

Expand All @@ -62,11 +59,11 @@ public function readme_examples()
'episode one',
'episode two',
'episode eleven',
'episode three'
'episode three',
]);

$this->assertEquals(["episode1","episode one","episode two","episode three","episode 5","episode eleven","episode50","episode two hundred",
499], $orderedArray);
$this->assertEquals(['episode1', 'episode one', 'episode two', 'episode three', 'episode 5', 'episode eleven', 'episode50', 'episode two hundred',
499, ], $orderedArray);

$orderedArray = $this->numberedStringOrder->sort([
'حلقة 30',
Expand All @@ -85,8 +82,7 @@ public function readme_examples()
]);

$this->assertEquals(
["حلقة واحد جديدة","حلقه الأولى جديدة","حلقتنا اليوم 1","حلقه 2 جديدة", "حلقة الثانية جديدة","حلقة ثلاثة جديدة",4,"episode 24","حلقة 30","حلقة33", "حلقة3٤", "حلقة ٥٥ ", "حلقة الاخيرة"]
, $orderedArray);
['حلقة واحد جديدة', 'حلقه الأولى جديدة', 'حلقتنا اليوم 1', 'حلقه 2 جديدة', 'حلقة الثانية جديدة', 'حلقة ثلاثة جديدة', 4, 'episode 24', 'حلقة 30', 'حلقة33', 'حلقة3٤', 'حلقة ٥٥ ', 'حلقة الاخيرة'], $orderedArray);
}

/** @test */
Expand Down Expand Up @@ -145,7 +141,6 @@ public function it_sort_arabic_words_well()
$this->assertEquals('١', $orderedArray[0]);
}


/** @test */
public function arabic_words()
{
Expand All @@ -168,16 +163,16 @@ public function arabic_words()

$expected =
[
0 => '١',
1 => '٢ ',
2 => ' 24',
3 => '١٠٠',
4 => '١٠ ألاف',
5 => '٥٥ ألف',
6 => '٣ ملايين',
7 => '١٠ ملايين و5 ألاف',
8 => '١٠ ملايين وتسع مئة ألف',
9 => '١٠ ملايين وتسع مئة ألف وخمس مئة',
0 => '١',
1 => '٢ ',
2 => ' 24',
3 => '١٠٠',
4 => '١٠ ألاف',
5 => '٥٥ ألف',
6 => '٣ ملايين',
7 => '١٠ ملايين و5 ألاف',
8 => '١٠ ملايين وتسع مئة ألف',
9 => '١٠ ملايين وتسع مئة ألف وخمس مئة',
10 => '٣٠ مليون',
11 => '4 مليارات',
12 => '30 مليار',
Expand Down

0 comments on commit d641d81

Please sign in to comment.