1: <?php
2: namespace tests\unit\barebones\utilities;
3: use barebones\utilities\Arrays;
4: use tests\integration\barebones\BarebonesTestCase;
5:
6: class ArraysTest extends BarebonesTestCase
7: {
8: public function testIsAsociative()
9: {
10: $this->assertTrue(Arrays::isAssociativeArray(array('a' => 'b')));
11: $this->assertTrue(Arrays::isAssociativeArray(array('1' => 'a')));
12: $this->assertTrue(Arrays::isAssociativeArray(array('1' => '1')));
13: $this->assertTrue(Arrays::isAssociativeArray(
14: array(
15: '0' => '0',
16: '2' => '2',
17: )));
18:
19: $this->assertNotTrue(Arrays::isAssociativeArray(array('a')));
20: $this->assertNotTrue(Arrays::isAssociativeArray(array('0' => '0')));
21: $this->assertNotTrue(Arrays::isAssociativeArray(
22: array(
23: '0' => 'a',
24: '1' => 'b',
25: )));
26: }
27:
28: public function testUnique() {
29: $a = array_map(function ($i){
30: return rand() % 10;
31: }, array_fill(0, 20, 0));
32:
33: Arrays::unique($a, function ($l, $r) {
34: return $l - $r;
35: });
36:
37: $this->assertTrue(Arrays::allValuesUnique($a));
38: }
39: }
40: