/
equalTest.php
99 lines (95 loc) · 2.25 KB
/
equalTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
/**
* @covers Dash\equal
* @covers Dash\Curry\equal
*/
class equalTest extends PHPUnit\Framework\TestCase
{
/**
* @dataProvider cases
*/
public function test($a, $b, $expected)
{
$this->assertSame($expected, Dash\equal($a, $b));
}
/**
* @dataProvider cases
*/
public function testCurried($a, $b, $expected)
{
$equal = Dash\Curry\equal($b);
$this->assertSame($expected, $equal($a));
}
public function cases()
{
return [
'With identical numbers' => [
'a' => 3,
'b' => 3,
'expected' => true,
],
'With two equal but non-identical numbers' => [
'a' => 123,
'b' => 123.0,
'expected' => true,
],
'With equal but not identical string/integer values' => [
'a' => '3',
'b' => 3,
'expected' => true,
],
'With equal but not identical boolean/integer values' => [
'a' => true,
'b' => 1,
'expected' => true,
],
'With equal but not identical null/integer values' => [
'a' => null,
'b' => 0,
'expected' => true,
],
'With inequal values of the same type' => [
'a' => 4,
'b' => 3,
'expected' => false,
],
'With inequal values of different types' => [
'a' => '4',
'b' => 3,
'expected' => false,
],
'With two identical arrays' => [
'a' => [1, 2, 3],
'b' => [1, 2, 3],
'expected' => true,
],
'With two arrays containing loosely equal values' => [
'a' => [null, 1, 2, 3],
'b' => [0, 1, '2', 3],
'expected' => true,
],
'With two arrays containing identical values in different orders' => [
'a' => [1, 2, 3],
'b' => [3, 2, 1],
'expected' => false,
],
'With two arrays containing identical values but different keys' => [
'a' => ['a' => 1, 'b' => 2, 'c' => 3],
'b' => ['a' => 1, 'd' => 2, 'c' => 3],
'expected' => false,
],
'With two arrays containing equal but not identical nested arrays' => [
'a' => ['a' => [1, 2], 'b' => [3, 4, 5]],
'b' => ['a' => [1, '2'], 'b' => [3.0, 4, 5]],
'expected' => true,
],
];
}
public function testExamples()
{
$this->assertSame(true, Dash\equal(3, '3'));
$this->assertSame(true, Dash\equal(3, 3));
$this->assertSame(true, Dash\equal([1, 2, 3], [1, '2', 3]));
$this->assertSame(false, Dash\equal([1, 2, 3], [3, 2, 1]));
}
}