@@ -14,19 +14,109 @@ protected function setUp(): void
14
14
$ this ->deduplicator = new ArrayDeduplicator ();
15
15
}
16
16
17
- public function testDedupeArrayOfArraysRemovesExactDuplicates (): void
17
+ public static function dedupeArrayOfArraysProvider (): array
18
18
{
19
- $ data = [
20
- ['a ' => 1 , 'b ' => 2 ],
21
- ['a ' => 1 , 'b ' => 2 ], // duplicate
22
- ['a ' => 2 , 'b ' => 3 ],
19
+ return [
20
+ 'empty array ' => [
21
+ 'input ' => [],
22
+ 'expectedCount ' => 0 ,
23
+ 'expectedItems ' => []
24
+ ],
25
+ 'no duplicates ' => [
26
+ 'input ' => [
27
+ ['a ' => 1 , 'b ' => 2 ],
28
+ ['a ' => 2 , 'b ' => 3 ],
29
+ ['a ' => 3 , 'b ' => 4 ]
30
+ ],
31
+ 'expectedCount ' => 3 ,
32
+ 'expectedItems ' => [
33
+ ['a ' => 1 , 'b ' => 2 ],
34
+ ['a ' => 2 , 'b ' => 3 ],
35
+ ['a ' => 3 , 'b ' => 4 ]
36
+ ]
37
+ ],
38
+ 'exact duplicates ' => [
39
+ 'input ' => [
40
+ ['a ' => 1 , 'b ' => 2 ],
41
+ ['a ' => 1 , 'b ' => 2 ], // duplicate
42
+ ['a ' => 2 , 'b ' => 3 ]
43
+ ],
44
+ 'expectedCount ' => 2 ,
45
+ 'expectedItems ' => [
46
+ ['a ' => 1 , 'b ' => 2 ],
47
+ ['a ' => 2 , 'b ' => 3 ]
48
+ ]
49
+ ],
50
+ 'multiple duplicates ' => [
51
+ 'input ' => [
52
+ ['id ' => 1 , 'name ' => 'test ' ],
53
+ ['id ' => 2 , 'name ' => 'test2 ' ],
54
+ ['id ' => 1 , 'name ' => 'test ' ], // duplicate
55
+ ['id ' => 3 , 'name ' => 'test3 ' ],
56
+ ['id ' => 2 , 'name ' => 'test2 ' ] // duplicate
57
+ ],
58
+ 'expectedCount ' => 3 ,
59
+ 'expectedItems ' => [
60
+ ['id ' => 1 , 'name ' => 'test ' ],
61
+ ['id ' => 2 , 'name ' => 'test2 ' ],
62
+ ['id ' => 3 , 'name ' => 'test3 ' ]
63
+ ]
64
+ ],
65
+ 'duplicate synonyms ' => [
66
+ 'input ' => [
67
+ ['gray ' , 'grey ' ],
68
+ ['trousers ' , 'pants ' ],
69
+ ['ipad ' , 'tablet ' ],
70
+ ['caulk ' , 'caulking ' ],
71
+ ['trousers ' , 'pants ' ], // duplicate
72
+ ['molding ' , 'moldings ' , 'moulding ' , 'mouldings ' ],
73
+ ['trash ' , 'garbage ' ],
74
+ ['molding ' , 'moldings ' , 'moulding ' , 'mouldings ' ], // duplicate
75
+ ],
76
+ 'expectedCount ' => 6 ,
77
+ 'expectedItems ' => [
78
+ ['gray ' , 'grey ' ],
79
+ ['trousers ' , 'pants ' ],
80
+ ['ipad ' , 'tablet ' ],
81
+ ['caulk ' , 'caulking ' ],
82
+ ['molding ' , 'moldings ' , 'moulding ' , 'mouldings ' ],
83
+ ['trash ' , 'garbage ' ],
84
+ ]
85
+ ],
86
+ 'duplicate alt corrections ' => [
87
+ 'input ' => [
88
+ [ 'word ' => 'trousers ' , 'nbTypos ' => 1 , 'correction ' => 'pants ' ],
89
+ [ 'word ' => 'rod ' , 'nbTypos ' => 1 , 'correction ' => 'bar ' ],
90
+ [ 'word ' => 'bell ' , 'nbTypos ' => 1 , 'correction ' => 'buzzer ' ],
91
+ [ 'word ' => 'rod ' , 'nbTypos ' => 1 , 'correction ' => 'bar ' ], // duplicate
92
+ [ 'word ' => 'blind ' , 'nbTypos ' => 1 , 'correction ' => 'shade ' ],
93
+ [ 'word ' => 'blind ' , 'nbTypos ' => 2 , 'correction ' => 'shade ' ], // not a duplicate
94
+ [ 'word ' => 'trousers ' , 'nbTypos ' => 1 , 'correction ' => 'pants ' ], // duplicate
95
+ ],
96
+ 'expectedCount ' => 5 ,
97
+ 'expectedItems ' => [
98
+ [ 'word ' => 'trousers ' , 'nbTypos ' => 1 , 'correction ' => 'pants ' ],
99
+ [ 'word ' => 'rod ' , 'nbTypos ' => 1 , 'correction ' => 'bar ' ],
100
+ [ 'word ' => 'bell ' , 'nbTypos ' => 1 , 'correction ' => 'buzzer ' ],
101
+ [ 'word ' => 'blind ' , 'nbTypos ' => 1 , 'correction ' => 'shade ' ],
102
+ [ 'word ' => 'blind ' , 'nbTypos ' => 2 , 'correction ' => 'shade ' ],
103
+ ]
104
+ ]
23
105
];
106
+ }
24
107
25
- $ result = $ this ->deduplicator ->dedupeArrayOfArrays ($ data );
108
+ /**
109
+ * @dataProvider dedupeArrayOfArraysProvider
110
+ */
111
+ public function testDedupeArrayOfArrays (array $ input , int $ expectedCount , array $ expectedItems ): void
112
+ {
113
+ $ result = $ this ->deduplicator ->dedupeArrayOfArrays ($ input );
114
+
115
+ $ this ->assertCount ($ expectedCount , $ result );
26
116
27
- $ this -> assertCount ( 2 , $ result );
28
- $ this ->assertContains ([ ' a ' => 1 , ' b ' => 2 ] , $ result );
29
- $ this -> assertContains ([ ' a ' => 2 , ' b ' => 3 ], $ result );
117
+ foreach ( $ expectedItems as $ expectedItem ) {
118
+ $ this ->assertContains ($ expectedItem , $ result );
119
+ }
30
120
}
31
121
32
122
public function testDedupeArrayOfArraysKeepsOrderOfFirstOccurrences (): void
@@ -46,14 +136,14 @@ public function testDedupeSpecificSettingsOnlyProcessesRequestedSettings(): void
46
136
{
47
137
$ settings = [
48
138
'synonyms ' => [
49
- ['word ' => 'foo ' ],
50
- ['word ' => 'foo ' ],
139
+ ['red ' => 'rouge ' ],
140
+ ['red ' => 'rouge ' ],
51
141
],
52
142
'altCorrections ' => [
53
- ['word ' => 'bar ' ],
143
+ [ 'word ' => 'bell ' , ' nbTypos ' => 1 , ' correction ' => ' buzzer ' ],
54
144
],
55
- 'placeholders ' => [
56
- ['word ' => 'baz ' ],
145
+ 'placeholder ' => [
146
+ ['foo ' => 'bar ' ],
57
147
],
58
148
];
59
149
@@ -72,7 +162,7 @@ public function testDedupeSpecificSettingsOnlyProcessesRequestedSettings(): void
72
162
public function testDedupeSpecificSettingsHandlesMissingKeys (): void
73
163
{
74
164
$ settings = [
75
- 'synonyms ' => [['w ' => ' x ' ]],
165
+ 'synonyms ' => [['red ' , ' rouge ' ]],
76
166
];
77
167
78
168
$ result = $ this ->deduplicator ->dedupeSpecificSettings (
0 commit comments