Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commit 0af31d0

Browse files
committed
additional testcases for intersect and except using objects.
1 parent 687e157 commit 0af31d0

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

tests/Fusonic/Linq/Test/SetOperatorsTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,23 @@ public function testIntersect_ReturnsIntersectedElements()
1818
$array = $linq->toArray();
1919
$this->assertEquals("b", $array[0]);
2020
$this->assertEquals("c", $array[1]);
21+
22+
$a1 = new stdClass();
23+
$a1->id = 1;
24+
$a1->value = "a";
25+
$a2 = new stdClass();
26+
$a2->id = 2;
27+
$a2->value = "a";
28+
$b1 = new stdClass();
29+
$b1->id = 3;
30+
$b1->value = "b";
31+
32+
$items = array($a1, $a2, $b1);
33+
$distinct = Linq::from($items)->intersect(array($a2, $b1));
34+
35+
$this->assertFalse($distinct->contains($a1));
36+
$this->assertTrue($distinct->contains($a2));
37+
$this->assertTrue($distinct->contains($b1));
2138
}
2239

2340
public function testIntersect_ThrowsArgumentExceptionIfSecondSequenceIsNotTraversable()
@@ -57,6 +74,23 @@ public function testExcept_ReturnsAllElementsExceptTheGivenOnes()
5774
$array = $linq->toArray();
5875
$this->assertEquals("a", $array[0]);
5976
$this->assertEquals("d", $array[1]);
77+
78+
$a1 = new stdClass();
79+
$a1->id = 1;
80+
$a1->value = "a";
81+
$a2 = new stdClass();
82+
$a2->id = 2;
83+
$a2->value = "a";
84+
$b1 = new stdClass();
85+
$b1->id = 3;
86+
$b1->value = "b";
87+
88+
$items = array($a1, $a2, $b1);
89+
$distinct = Linq::from($items)->except(array($a2, $b1));
90+
91+
$this->assertTrue($distinct->contains($a1));
92+
$this->assertFalse($distinct->contains($a2));
93+
$this->assertFalse($distinct->contains($b1));
6094
}
6195

6296
public function testExcept_ThrowsArgumentExceptionIfSecondSequenceIsNotTraversable()

0 commit comments

Comments
 (0)