Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117753263
D4539.1775193542.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
5 KB
Referenced Files
None
Subscribers
None
D4539.1775193542.diff
View Options
diff --git a/src/app/Utils.php b/src/app/Utils.php
--- a/src/app/Utils.php
+++ b/src/app/Utils.php
@@ -339,24 +339,6 @@
return $asArray ? [$local, $domain] : "{$local}@{$domain}";
}
- /**
- * Provide all unique combinations of elements in $input, with order and duplicates irrelevant.
- *
- * @param array $input The input array of elements.
- *
- * @return array[]
- */
- public static function powerSet(array $input): array
- {
- $output = [];
-
- for ($x = 0; $x < count($input); $x++) {
- self::combine($input, $x + 1, 0, [], 0, $output);
- }
-
- return $output;
- }
-
/**
* Returns the current user's email address or null.
*
@@ -435,30 +417,6 @@
return (string) Str::uuid();
}
- private static function combine($input, $r, $index, $data, $i, &$output): void
- {
- $n = count($input);
-
- // Current cobination is ready
- if ($index == $r) {
- $output[] = array_slice($data, 0, $r);
- return;
- }
-
- // When no more elements are there to put in data[]
- if ($i >= $n) {
- return;
- }
-
- // current is included, put next at next location
- $data[$index] = $input[$i];
- self::combine($input, $r, $index + 1, $data, $i + 1, $output);
-
- // current is excluded, replace it with next (Note that i+1
- // is passed, but index is not changed)
- self::combine($input, $r, $index, $data, $i + 1, $output);
- }
-
/**
* Create self URL
*
diff --git a/src/tests/Unit/DomainTest.php b/src/tests/Unit/DomainTest.php
--- a/src/tests/Unit/DomainTest.php
+++ b/src/tests/Unit/DomainTest.php
@@ -22,7 +22,7 @@
Domain::STATUS_VERIFIED,
];
- $domains = \App\Utils::powerSet($statuses);
+ $domains = \Tests\Utils::powerSet($statuses);
foreach ($domains as $domainStatuses) {
$domain = new Domain(
@@ -90,7 +90,7 @@
Domain::TYPE_EXTERNAL,
];
- $domains = \App\Utils::powerSet($types);
+ $domains = \Tests\Utils::powerSet($types);
foreach ($domains as $domain_types) {
$domain = new Domain(
diff --git a/src/tests/Unit/SharedFolderTest.php b/src/tests/Unit/SharedFolderTest.php
--- a/src/tests/Unit/SharedFolderTest.php
+++ b/src/tests/Unit/SharedFolderTest.php
@@ -20,7 +20,7 @@
SharedFolder::STATUS_IMAP_READY,
];
- $folders = \App\Utils::powerSet($statuses);
+ $folders = \Tests\Utils::powerSet($statuses);
$folder = new SharedFolder(['name' => 'test']);
diff --git a/src/tests/Unit/UserTest.php b/src/tests/Unit/UserTest.php
--- a/src/tests/Unit/UserTest.php
+++ b/src/tests/Unit/UserTest.php
@@ -81,7 +81,7 @@
User::STATUS_RESTRICTED,
];
- $users = \App\Utils::powerSet($statuses);
+ $users = \Tests\Utils::powerSet($statuses);
foreach ($users as $user_statuses) {
$user = new User(
diff --git a/src/tests/Unit/UtilsTest.php b/src/tests/Unit/UtilsTest.php
--- a/src/tests/Unit/UtilsTest.php
+++ b/src/tests/Unit/UtilsTest.php
@@ -99,20 +99,20 @@
}
/**
- * Test for Utils::powerSet()
+ * Test for Tests\Utils::powerSet()
*/
public function testPowerSet(): void
{
$set = [];
- $result = Utils::powerSet($set);
+ $result = \Tests\Utils::powerSet($set);
$this->assertIsArray($result);
$this->assertCount(0, $result);
$set = ["a1"];
- $result = Utils::powerSet($set);
+ $result = \Tests\Utils::powerSet($set);
$this->assertIsArray($result);
$this->assertCount(1, $result);
@@ -120,7 +120,7 @@
$set = ["a1", "a2"];
- $result = Utils::powerSet($set);
+ $result = \Tests\Utils::powerSet($set);
$this->assertIsArray($result);
$this->assertCount(3, $result);
@@ -130,7 +130,7 @@
$set = ["a1", "a2", "a3"];
- $result = Utils::powerSet($set);
+ $result = \Tests\Utils::powerSet($set);
$this->assertIsArray($result);
$this->assertCount(7, $result);
diff --git a/src/tests/Utils.php b/src/tests/Utils.php
new file mode 100644
--- /dev/null
+++ b/src/tests/Utils.php
@@ -0,0 +1,53 @@
+<?php
+
+namespace Tests;
+
+use Illuminate\Support\Str;
+
+/**
+ * Small utility functions for tests
+ */
+class Utils
+{
+ /**
+ * Provide all unique combinations of elements in $input, with order and duplicates irrelevant.
+ *
+ * @param array $input The input array of elements.
+ *
+ * @return array[]
+ */
+ public static function powerSet(array $input): array
+ {
+ $output = [];
+
+ for ($x = 0; $x < count($input); $x++) {
+ self::combine($input, $x + 1, 0, [], 0, $output);
+ }
+
+ return $output;
+ }
+
+ private static function combine($input, $r, $index, $data, $i, &$output): void
+ {
+ $n = count($input);
+
+ // Current cobination is ready
+ if ($index == $r) {
+ $output[] = array_slice($data, 0, $r);
+ return;
+ }
+
+ // When no more elements are there to put in data[]
+ if ($i >= $n) {
+ return;
+ }
+
+ // current is included, put next at next location
+ $data[$index] = $input[$i];
+ self::combine($input, $r, $index + 1, $data, $i + 1, $output);
+
+ // current is excluded, replace it with next (Note that i+1
+ // is passed, but index is not changed)
+ self::combine($input, $r, $index, $data, $i + 1, $output);
+ }
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Apr 3, 5:19 AM (1 d, 14 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18822678
Default Alt Text
D4539.1775193542.diff (5 KB)
Attached To
Mode
D4539: Move powerSet() to Tests/Utils
Attached
Detach File
Event Timeline