* [Dictionary] Добавлен метод Keys (): array, который возвращает все ключи словаря.
* [Dictionary] Добавлен метод Sort (bool $descending = false): void, который сортирует внутренние данные по ключам (в обратном порядке, если выбран $descending = true).
This commit is contained in:
2025-05-16 23:34:24 +03:00
parent ee76392d71
commit 5b83b096e5
3 changed files with 67 additions and 9 deletions

View File

@@ -99,4 +99,34 @@ class DictionaryTest extends TestCase
$this->assertTrue($dict->Has('3'));
$this->assertFalse($dict->Has('4'));
}
public function testKeys ()
{
$this->PrepareForTest();
$dict = new Dictionary();
$dict->Add('1', 1);
$dict->Add('3', true);
$dict->Add('2', '2');
$array = ['1', '3', '2'];
$this->assertArrayIsEqualToArrayIgnoringListOfKeys($array, $dict->Keys(), []);
}
public function testSort ()
{
$this->PrepareForTest();
$dict = new Dictionary();
$dict->Add('1', 1);
$dict->Add('3', true);
$dict->Add('2', '2');
$array = ['1', '2', '3'];
$dict->Sort();
$this->assertArrayIsEqualToArrayIgnoringListOfKeys($array, $dict->Keys(), []);
}
}