This commit is contained in:
2025-02-04 12:40:43 +03:00
parent 4bcb4c60dd
commit 50343d5a87
372 changed files with 9019 additions and 6684 deletions

View File

@@ -122,46 +122,194 @@ class ObjectArrayTest extends TestCase
public function testDelete ()
{
$this->PrepareForTest();
$array = [
new A("a", 3, true),
new A("c", 2, false),
new A("b", 1, true),
];
$a_Array = new ObjectArray($array);
$a_Array->Delete(fn (A $a): bool => $a->b == 3);
$cnt = $a_Array->Count();
$this->assertEquals(2, $cnt);
}
public function testClear ()
{
$this->PrepareForTest();
$array = [
new A("a", 3, true),
new A("c", 2, false),
new A("b", 1, true),
];
$a_Array = new ObjectArray($array);
$a_Array->Clear();
$cnt = $a_Array->Count();
$this->assertEquals(0, $cnt);
}
public function testMerge ()
{
$this->PrepareForTest();
$array = [
new A("a", 3, true),
new A("c", 2, false),
new A("b", 1, true),
];
$array2 = [
new A("d", 4, true),
new A("e", 5, false),
new A("f", 6, true),
];
$a_Array = new ObjectArray($array);
$a_Array->Merge($array2);
$cnt = $a_Array->Count();
$this->assertEquals(6, $cnt);
$sr = $a_Array->Search('a', 'f');
$this->assertEquals(6, $sr->b);
}
public function testMaxBy ()
{
$this->PrepareForTest();
$array = [
new A("a", 3, true),
new A("c", 2, false),
new A("b", 1, true),
];
$a_Array = new ObjectArray($array);
$sr = $a_Array->MaxBy(fn (A $a) => $a->b);
$this->assertEquals("a", $sr->a);
}
public function testGetColumn ()
{
$this->PrepareForTest();
$array = [
new A("a", 3, true),
new A("c", 2, false),
new A("b", 1, true),
];
$a_Array = new ObjectArray($array);
$sr = $a_Array->GetColumn('a', fn (A $a): bool => $a->b < 3);
$this->assertIsArray($sr);
$this->assertSame(['c', 'b'], $sr);
}
public function testToArray ()
{
$this->PrepareForTest();
$array = [
new A("a", 3, true),
new A("c", 2, false),
new A("b", 1, true),
];
$a_Array = new ObjectArray($array);
$sr = $a_Array->ToArray();
$this->assertIsArray($sr);
$this->assertSame($array, $sr);
}
public function testMinBy ()
{
$this->PrepareForTest();
$array = [
new A("a", 3, true),
new A("c", 2, false),
new A("b", 1, true),
];
$a_Array = new ObjectArray($array);
$sr = $a_Array->MinBy(fn (A $a) => $a->b);
$this->assertEquals("b", $sr->a);
}
public function testIsExist ()
{
$this->PrepareForTest();
}
$array = [
new A("a", 3, true),
new A("c", 2, false),
new A("b", 1, true),
];
public function testSortCallback ()
{
$a_Array = new ObjectArray($array);
$srTrue = $a_Array->IsExist(fn (A $a) => $a->b == 1);
$srFalse = $a_Array->IsExist(fn (A $a) => $a->b == 5);
$this->assertTrue($srTrue);
$this->assertFalse($srFalse);
}
public function testUpdate ()
{
$this->PrepareForTest();
$array = [
new A("a", 3, true),
new A("c", 2, false),
new A("b", 1, true),
];
$a_Array = new ObjectArray($array);
$a_Array->Update([new A("d", 3, true)], fn (A $a) => $a->a == "a");
$sr = $a_Array->Search("a", "d");
$this->assertEquals("3", $sr->b);
$this->assertTrue($sr->c);
}
public function testGetRow ()
{
$this->PrepareForTest();
$array = [
new A("a", 3, true),
new A("c", 2, false),
new A("b", 1, true),
];
$a_Array = new ObjectArray($array);
$sr = $a_Array->GetRow(fn (A $a): bool => $a->b == 3);
$this->assertInstanceOf(A::class, $sr);
$this->assertEquals('a', $sr->a);
$this->assertTrue($sr->c);
}
}