20250520
[Dictionary] добавлен метод AddRange (array $dictionary), который добавляет элементы в виде ассоциативного массива ключ => значение в словарь. [Dictionary] Добавлен метод ToArray (), который возвращает все элементы словаря в виде массива..
This commit is contained in:
		| @@ -31,18 +31,6 @@ class DictionaryTest extends TestCase | ||||
|         require_once __DIR__ . '/../../sources/classes/Dictionary.php'; | ||||
|     } | ||||
|  | ||||
|     public function testSerialize () | ||||
|     { | ||||
|         $this->PrepareForTest(); | ||||
|  | ||||
|         $dict = new Dictionary(); | ||||
|         $dict->Add('1', 1); | ||||
|         $dict->Add('2', '2'); | ||||
|         $dict->Add('3', true); | ||||
|  | ||||
|         $this->assertEquals("{\"1\":1,\"2\":\"2\",\"3\":true}", $dict->Serialize()); | ||||
|     } | ||||
|  | ||||
|     public function testGet () | ||||
|     { | ||||
|         $this->PrepareForTest(); | ||||
| @@ -129,4 +117,38 @@ class DictionaryTest extends TestCase | ||||
|  | ||||
|         $this->assertArrayIsEqualToArrayIgnoringListOfKeys($array, $dict->Keys(), []); | ||||
|     } | ||||
|  | ||||
|     public function testAddRange () | ||||
|     { | ||||
|         $this->PrepareForTest(); | ||||
|  | ||||
|         $dict = new Dictionary(); | ||||
|         $dict->Add('1', 1); | ||||
|  | ||||
|         $array = ['2' => '2', '3' => true, '4' => false]; | ||||
|  | ||||
|         $dict->AddRange($array); | ||||
|  | ||||
|         $this->assertEquals(1, $dict->Get('1')); | ||||
|         $this->assertTrue($dict->Get('3')); | ||||
|         $this->assertEquals(4, $dict->count()); | ||||
|         $this->assertFalse($dict->Get("4")); | ||||
|     } | ||||
|  | ||||
|     public function testToArray () | ||||
|     { | ||||
|         $this->PrepareForTest(); | ||||
|  | ||||
|         $dict = new Dictionary(); | ||||
|         $dict->Add('1', 1); | ||||
|         $dict->Add('3', true); | ||||
|         $dict->Add('2', '2'); | ||||
|  | ||||
|         $array = $dict->ToArray(); | ||||
|  | ||||
|         $this->assertIsArray($array); | ||||
|         $this->assertEquals(1, $array['1']); | ||||
|         $this->assertTrue($array['3']); | ||||
|         $this->assertCount(3, $array); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user