Skip to content

Commit

Permalink
[11.x] Add tests for Arr::divide (#51673)
Browse files Browse the repository at this point in the history
* Add tests for Arr::divide

* fixes code style

* add tests

* update comments
  • Loading branch information
saMahmoudzadeh authored Jun 2, 2024
1 parent 4ebbabe commit ee81af8
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion tests/Support/SupportArrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,42 @@ public function testCrossJoin()
$this->assertSame([[]], Arr::crossJoin());
}

public function testDivide()
public function testDivide(): void
{
// Test dividing an empty array
[$keys, $values] = Arr::divide([]);
$this->assertEquals([], $keys);
$this->assertEquals([], $values);

// Test dividing an array with a single key-value pair
[$keys, $values] = Arr::divide(['name' => 'Desk']);
$this->assertEquals(['name'], $keys);
$this->assertEquals(['Desk'], $values);

// Test dividing an array with multiple key-value pairs
[$keys, $values] = Arr::divide(['name' => 'Desk', 'price' => 100, 'available' => true]);
$this->assertEquals(['name', 'price', 'available'], $keys);
$this->assertEquals(['Desk', 100, true], $values);

// Test dividing an array with numeric keys
[$keys, $values] = Arr::divide([0 => 'first', 1 => 'second']);
$this->assertEquals([0, 1], $keys);
$this->assertEquals(['first', 'second'], $values);

// Test dividing an array with null key
[$keys, $values] = Arr::divide([null => 'Null', 1 => 'one']);
$this->assertEquals([null, 1], $keys);
$this->assertEquals(['Null', 'one'], $values);

// Test dividing an array where the keys are arrays
[$keys, $values] = Arr::divide([['one' => 1, 2 => 'second'], 1 => 'one']);
$this->assertEquals([0, 1], $keys);
$this->assertEquals([['one' => 1, 2 => 'second'], 'one'], $values);

// Test dividing an array where the values are arrays
[$keys, $values] = Arr::divide([null => ['one' => 1, 2 => 'second'], 1 => 'one']);
$this->assertEquals([null, 1], $keys);
$this->assertEquals([['one' => 1, 2 => 'second'], 'one'], $values);
}

public function testDot()
Expand Down

0 comments on commit ee81af8

Please sign in to comment.