SetOperationsTest.php 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214
  1. <?php
  2. namespace MathPHP\Tests\SetTheory;
  3. use MathPHP\SetTheory\Set;
  4. use MathPHP\LinearAlgebra\Vector;
  5. use MathPHP\LinearAlgebra\NumericMatrix;
  6. class SetOperationsTest extends \PHPUnit\Framework\TestCase
  7. {
  8. /**
  9. * @test
  10. * @dataProvider dataProviderForAdd
  11. */
  12. public function testAdd(array $A, $x, array $R)
  13. {
  14. // Given
  15. $setA = new Set($A);
  16. $setR = new Set($R);
  17. // When
  18. $setA->add($x);
  19. // Then
  20. $this->assertEquals($setR, $setA);
  21. $this->assertEquals($setR->asArray(), $setA->asArray());
  22. }
  23. /**
  24. * @test
  25. * @dataProvider dataProviderForAdd
  26. */
  27. public function testAddTwiceDoesNothing(array $A, $x, array $R)
  28. {
  29. // Given
  30. $setA = new Set($A);
  31. $setR = new Set($R);
  32. // When
  33. $setA->add($x);
  34. $setA->add($x);
  35. // Then
  36. $this->assertEquals($setR, $setA);
  37. }
  38. public function dataProviderForAdd(): array
  39. {
  40. $vector = new Vector([1, 2, 3]);
  41. return [
  42. [
  43. [],
  44. null,
  45. [null],
  46. ],
  47. [
  48. [],
  49. new Set(),
  50. ['Ø' => new Set()],
  51. ],
  52. [
  53. [],
  54. 1,
  55. [1 => 1],
  56. ],
  57. [
  58. [1, 2, 3],
  59. 4,
  60. [1, 2, 3, 4],
  61. ],
  62. [
  63. [1, 2, 3],
  64. 1,
  65. [1, 2, 3],
  66. ],
  67. [
  68. [1, 2, 3],
  69. 'new',
  70. [1, 2, 3, 'new'],
  71. ],
  72. [
  73. [1, 2, 3],
  74. 3.1,
  75. [1, 2, 3, 3.1],
  76. ],
  77. [
  78. [1, 2, 3],
  79. new Set(),
  80. [1, 2, 3, 'Ø'],
  81. ],
  82. [
  83. [1, 2, 3],
  84. new Set([4, 5]),
  85. [1, 2, 3, 'Set{4, 5}'],
  86. ],
  87. [
  88. [1, 2, 3],
  89. new Set([1, 2]),
  90. [1, 2, 3, 'Set{1, 2}'],
  91. ],
  92. [
  93. [1, 2, 3],
  94. -3,
  95. [1, 2, 3, -3],
  96. ],
  97. [
  98. [1, 2, 3],
  99. $vector,
  100. [1, 2, 3, $vector],
  101. ],
  102. ];
  103. }
  104. /**
  105. * When adding objects to a set, the key becomes to the objects hash.
  106. * The object is stored as is as the value.
  107. */
  108. public function testAddWithObjects()
  109. {
  110. // Given
  111. $set = new Set([1, 2, 3]);
  112. $vector = new Vector([1, 2, 3]);
  113. $matrix = new NumericMatrix([[1,2,3],[2,3,4]]);
  114. // When
  115. $set->add($vector);
  116. $set->add($matrix);
  117. // Then
  118. $this->assertEquals(5, count($set));
  119. $this->assertEquals(5, count($set->asArray()));
  120. $objects = 0;
  121. foreach ($set as $key => $value) {
  122. if ($value instanceof \MathPHP\LinearAlgebra\Vector) {
  123. $objects++;
  124. $vector_key = \get_class($value) . '(' . spl_object_hash($vector) . ')';
  125. $this->assertEquals($vector_key, $key);
  126. $this->assertEquals($vector, $value);
  127. }
  128. if ($value instanceof \MathPHP\LinearAlgebra\NumericMatrix) {
  129. $objects++;
  130. $matrix_key = \get_class($value) . '(' . spl_object_hash($matrix) . ')';
  131. $this->assertEquals($matrix_key, $key);
  132. $this->assertEquals($matrix, $value);
  133. }
  134. }
  135. // There should have been two objects (vector and matrix)
  136. $this->assertEquals(2, $objects);
  137. }
  138. public function testAddWithMultipleObjects()
  139. {
  140. // Given
  141. $set = new Set([1, 2, 3]);
  142. $vector1 = new Vector([1, 2, 3]);
  143. $vector2 = new Vector([1, 2, 3]);
  144. $vector3 = new Vector([4, 5, 6]);
  145. $matrix = new NumericMatrix([[1,2,3],[2,3,4]]);
  146. $std1 = new \StdClass();
  147. $std2 = new \StdClass();
  148. $std3 = $std2; // Same object so this wont get added
  149. // When
  150. $set->add($vector1);
  151. $set->add($vector2);
  152. $set->add($vector3);
  153. $set->add($matrix);
  154. $set->add($std1);
  155. $set->add($std2);
  156. $set->add($std3);
  157. // Then
  158. $this->assertEquals(9, count($set));
  159. $this->assertEquals(9, count($set->asArray()));
  160. $objects = 0;
  161. foreach ($set as $key => $value) {
  162. if ($value instanceof \MathPHP\LinearAlgebra\Vector) {
  163. $objects++;
  164. $this->assertInstanceOf(\MathPHP\LinearAlgebra\Vector::class, $value);
  165. }
  166. if ($value instanceof \MathPHP\LinearAlgebra\NumericMatrix) {
  167. $objects++;
  168. $this->assertInstanceOf(\MathPHP\LinearAlgebra\NumericMatrix::class, $value);
  169. }
  170. if ($value instanceof \StdClass) {
  171. $objects++;
  172. $this->assertInstanceOf(\StdClass::class, $value);
  173. }
  174. }
  175. // There should have been four objects (3 vectors and 1 matrix)
  176. $this->assertEquals(6, $objects);
  177. }
  178. public function testAddWithDuplicateObjects()
  179. {
  180. // Given
  181. $set = new Set([1, 2, 3]);
  182. $vector = new Vector([1, 2, 3]);
  183. // When adding the same object twice.
  184. $set->add($vector);
  185. $set->add($vector);
  186. // Then
  187. $this->assertEquals(4, count($set));
  188. $this->assertEquals(4, count($set->asArray()));
  189. $objects = 0;
  190. foreach ($set as $key => $value) {
  191. if ($value instanceof \MathPHP\LinearAlgebra\Vector) {
  192. $objects++;
  193. $vector_key = \get_class($value) . '(' . spl_object_hash($vector) . ')';
  194. $this->assertEquals($vector_key, $key);
  195. $this->assertEquals($vector, $value);
  196. }
  197. }
  198. // There should have only been one vector object.
  199. $this->assertEquals(1, $objects);
  200. }
  201. /**
  202. * In this case, we add an array that contains arrays.
  203. * So each array element will be added, but with the implementation
  204. * detail that they will be converted into ArrayObjects.
  205. */
  206. public function testAddMultiWithArrayOfArrays()
  207. {
  208. // Given
  209. $set = new Set([1, 2, 3]);
  210. $array = [4, 5, [1, 2, 3]];
  211. // When
  212. $set->addMulti($array);
  213. // Then
  214. $this->assertEquals(6, count($set));
  215. $this->assertEquals(6, count($set->asArray()));
  216. $arrays = 0;
  217. foreach ($set as $key => $value) {
  218. if (\is_array($value)) {
  219. $arrays++;
  220. $this->assertEquals([1, 2, 3], $value);
  221. $this->assertEquals(3, count($value));
  222. $this->assertEquals(1, $value[0]);
  223. $this->assertEquals(1, $value[0]);
  224. $this->assertEquals(1, $value[0]);
  225. }
  226. }
  227. // There should have only been one array.
  228. $this->assertEquals(1, $arrays);
  229. }
  230. /**
  231. * In this case, we add an array that contains arrays.
  232. * So each array element will be added, but with the implementation
  233. * detail that they will be converted into ArrayObjects.
  234. */
  235. public function testAddMultiWithArrayOfArraysMultipleArraysAndDuplicates()
  236. {
  237. // Given
  238. $set = new Set([1, 2, 3]);
  239. $array = [4, 5, [1, 2, 3], [1, 2, 3], [5, 5, 5]];
  240. // When
  241. $set->addMulti($array);
  242. // Then, only 7, because [1, 2, 3] was in there twice.
  243. $this->assertEquals(7, count($set));
  244. $this->assertEquals(7, count($set->asArray()));
  245. $arrays = 0;
  246. foreach ($set as $key => $value) {
  247. if (\is_array($value)) {
  248. $arrays++;
  249. $this->assertEquals(3, count($value));
  250. }
  251. }
  252. // There should have been 2 arrays.
  253. $this->assertEquals(2, $arrays);
  254. }
  255. /**
  256. * When adding resources to a set, the key becomes to the resource ID.
  257. * The resource is stored as is as the value.
  258. */
  259. public function testAddWithResources()
  260. {
  261. // Given
  262. $set = new Set();
  263. $fh = fopen(__FILE__, 'r');
  264. // When
  265. $set->add($fh);
  266. $set->add($fh); // Should only get added once
  267. // Then
  268. $this->assertEquals(1, count($set));
  269. $this->assertEquals(1, count($set->asArray()));
  270. $resources = 0;
  271. foreach ($set as $key => $value) {
  272. if (\is_resource($value)) {
  273. $resources++;
  274. $vector_key = 'Resource(' . \strval($value) . ')';
  275. $this->assertEquals($vector_key, $key);
  276. $this->assertEquals($fh, $value);
  277. }
  278. }
  279. // There should have been one resource
  280. $this->assertEquals(1, $resources);
  281. }
  282. /**
  283. * @test
  284. * @dataProvider dataProviderForAddMulti
  285. */
  286. public function testAddMulti(array $A, array $x, array $R)
  287. {
  288. // Given
  289. $setA = new Set($A);
  290. $setR = new Set($R);
  291. // When
  292. $setA->addMulti($x);
  293. // Then
  294. $this->assertEquals($setR, $setA);
  295. $this->assertEquals($setR->asArray(), $setA->asArray());
  296. }
  297. public function dataProviderForAddMulti(): array
  298. {
  299. $vector = new Vector([1, 2, 3]);
  300. return [
  301. [
  302. [],
  303. [1],
  304. [1],
  305. ],
  306. [
  307. [],
  308. [1, 2],
  309. [1, 2],
  310. ],
  311. [
  312. [1, 2, 3],
  313. [],
  314. [1, 2, 3],
  315. ],
  316. [
  317. [1, 2, 3],
  318. [4],
  319. [1, 2, 3, 4],
  320. ],
  321. [
  322. [1, 2, 3],
  323. [4, 5],
  324. [1, 2, 3, 4, 5],
  325. ],
  326. [
  327. [1, 2, 3],
  328. [4, 5, 6],
  329. [1, 2, 3, 4, 5, 6],
  330. ],
  331. [
  332. [1, 2, 3],
  333. [1, 2, 3],
  334. [1, 2, 3],
  335. ],
  336. [
  337. [1, 2, 3],
  338. [1, 2, 3, 4],
  339. [1, 2, 3, 4],
  340. ],
  341. [
  342. [1, 2, 3],
  343. ['new', 4],
  344. [1, 2, 3, 'new', 4],
  345. ],
  346. [
  347. [1, 2, 3],
  348. [3.1, 4],
  349. [1, 2, 3, 3.1, 4],
  350. ],
  351. [
  352. [1, 2, 3],
  353. [new Set()],
  354. [1, 2, 3, 'Ø'],
  355. ],
  356. [
  357. [1, 2, 3],
  358. [new Set([4, 5])],
  359. [1, 2, 3, 'Set{4, 5}'],
  360. ],
  361. [
  362. [1, 2, 3],
  363. [new Set([1, 2]), 4],
  364. [1, 2, 3, 'Set{1, 2}', 4],
  365. ],
  366. [
  367. [1, 2, 3],
  368. [new Set([1, 2]), 6, 7, new Set([1, 2]), new Set([3, 4])],
  369. [1, 2, 3, 'Set{1, 2}', 6, 7, 'Set{3, 4}'],
  370. ],
  371. [
  372. [1, 2, 3],
  373. [-3],
  374. [1, 2, 3, -3],
  375. ],
  376. [
  377. [1, 2, 3],
  378. [4, $vector],
  379. [1, 2, 3, 4, $vector],
  380. ],
  381. ];
  382. }
  383. /**
  384. * @test
  385. * @dataProvider dataProviderForRemove
  386. */
  387. public function testRemove(array $A, $x, array $R)
  388. {
  389. // Given
  390. $setA = new Set($A);
  391. $setR = new Set($R);
  392. // When
  393. $setA->remove($x);
  394. // Then
  395. $this->assertEquals($setR, $setA);
  396. }
  397. public function dataProviderForRemove(): array
  398. {
  399. $vector = new Vector([1, 2, 3]);
  400. $fh = fopen(__FILE__, 'r');
  401. return [
  402. [
  403. [],
  404. null,
  405. [],
  406. ],
  407. [
  408. [null],
  409. null,
  410. [],
  411. ],
  412. [
  413. [1],
  414. 1,
  415. [],
  416. ],
  417. [
  418. [1, 2, 3],
  419. 1,
  420. [2, 3],
  421. ],
  422. [
  423. [1, 2, 3],
  424. 2,
  425. [1, 3],
  426. ],
  427. [
  428. [1, 2, 3],
  429. 3,
  430. [1, 2],
  431. ],
  432. [
  433. [1, 2, 3],
  434. 5,
  435. [1, 2, 3],
  436. ],
  437. [
  438. [1, 2, 3],
  439. -1,
  440. [1, 2, 3],
  441. ],
  442. [
  443. [1, 2, 3, -3],
  444. -3,
  445. [1, 2, 3],
  446. ],
  447. [
  448. [1, 2, 3, 4.5, 6.7],
  449. 4.5,
  450. [1, 2, 3, 6.7],
  451. ],
  452. [
  453. [1, 2, 3, 'a', 'b', 'see'],
  454. 'b',
  455. [1, 2, 3, 'a', 'see'],
  456. ],
  457. [
  458. [1, 2, 3, new Set([1, 2])],
  459. 1,
  460. [2, 3, 'Set{1, 2}'],
  461. ],
  462. [
  463. [1, 2, 3, new Set([1, 2])],
  464. new Set([1, 2]),
  465. [1, 2, 3],
  466. ],
  467. [
  468. [1, 2, 3, new Set([1, 2])],
  469. 'Set{1, 2}',
  470. [1, 2, 3],
  471. ],
  472. [
  473. [1, 2, 3, [1, 2, 3]],
  474. [1, 2, 3],
  475. [1, 2, 3],
  476. ],
  477. [
  478. [1, 2, 3, [1, 2, 3], [2, 3], [4, 5, 6]],
  479. [2, 3],
  480. [1, 2, 3, [1, 2, 3], [4, 5, 6]],
  481. ],
  482. [
  483. [1, 2, 3, [1, 2, 3], [2, 3], [4, 5, 6]],
  484. [4, 5, 6],
  485. [1, 2, 3, [1, 2, 3], [2, 3]],
  486. ],
  487. [
  488. [1, 2, 3, [1, 2, 3]],
  489. [6, 7, 3],
  490. [1, 2, 3, [1, 2, 3]],
  491. ],
  492. [
  493. [1, 2, 3, $vector],
  494. $vector,
  495. [1, 2, 3],
  496. ],
  497. [
  498. [1, 2, 3, $vector],
  499. [$vector], // Array containing vector
  500. [1, 2, 3, $vector],
  501. ],
  502. [
  503. [1, 2, 3, $vector],
  504. [1, $vector], // array containing 1 and vector
  505. [1, 2, 3, $vector],
  506. ],
  507. [
  508. [1, 2, 3, $fh],
  509. $fh,
  510. [1, 2, 3],
  511. ],
  512. [
  513. [1, 2, 3, $fh],
  514. [1, $fh], // array containing 1 and f1
  515. [1, 2, 3, $fh],
  516. ],
  517. ];
  518. }
  519. /**
  520. * @test
  521. * @dataProvider dataProviderForRemoveMulti
  522. */
  523. public function testRemoveMulti(array $A, array $x, array $R)
  524. {
  525. // Given
  526. $setA = new Set($A);
  527. $setR = new Set($R);
  528. // When
  529. $setA->removeMulti($x);
  530. // Then
  531. $this->assertEquals($setR, $setA);
  532. }
  533. public function dataProviderForRemoveMulti(): array
  534. {
  535. $vector = new Vector([1, 2, 3]);
  536. $fh = fopen(__FILE__, 'r');
  537. return [
  538. [
  539. [],
  540. [],
  541. [],
  542. ],
  543. [
  544. [],
  545. [null],
  546. [],
  547. ],
  548. [
  549. [null],
  550. [null],
  551. [],
  552. ],
  553. [
  554. [1],
  555. [1],
  556. [],
  557. ],
  558. [
  559. [1],
  560. [1],
  561. [],
  562. ],
  563. [
  564. [1, 2, 3],
  565. [1],
  566. [2, 3],
  567. ],
  568. [
  569. [1, 2, 3],
  570. [2],
  571. [1, 3],
  572. ],
  573. [
  574. [1, 2, 3],
  575. [3],
  576. [1, 2],
  577. ],
  578. [
  579. [1, 2, 3],
  580. [4],
  581. [1, 2, 3],
  582. ],
  583. [
  584. [1, 2, 3],
  585. [5, 6],
  586. [1, 2, 3],
  587. ],
  588. [
  589. [1, 2, 3],
  590. [3, 4, 5],
  591. [1, 2],
  592. ],
  593. [
  594. [1, 2, 3],
  595. [1, 2],
  596. [3],
  597. ],
  598. [
  599. [1, 2, 3],
  600. [2, 3],
  601. [1],
  602. ],
  603. [
  604. [1, 2, 3],
  605. [1, 3],
  606. [2],
  607. ],
  608. [
  609. [1, 2, 3],
  610. [5, 'a'],
  611. [1, 2, 3],
  612. ],
  613. [
  614. [1, 2, 3],
  615. [-1],
  616. [1, 2, 3],
  617. ],
  618. [
  619. [1, 2, 3, -3],
  620. [-3],
  621. [1, 2, 3],
  622. ],
  623. [
  624. [1, 2, 3, 4.5, 6.7],
  625. [4.5, 10],
  626. [1, 2, 3, 6.7],
  627. ],
  628. [
  629. [1, 2, 3, 'a', 'b', 'see'],
  630. ['b', 'z'],
  631. [1, 2, 3, 'a', 'see'],
  632. ],
  633. [
  634. [1, 2, 3, 'a', 'b', 'see'],
  635. ['b', 1, 'see', 5555],
  636. [ 2, 3, 'a'],
  637. ],
  638. [
  639. [1, 2, 3, new Set([1, 2])],
  640. [1],
  641. [2, 3, 'Set{1, 2}'],
  642. ],
  643. [
  644. [1, 2, 3, new Set([1, 2])],
  645. [new Set([1, 2])],
  646. [1, 2, 3],
  647. ],
  648. [
  649. [1, 2, 3, new Set([1, 2])],
  650. ['Set{1, 2}'],
  651. [1, 2, 3],
  652. ],
  653. [
  654. [1, 2, 3, [1, 2, 3]],
  655. [1, 2, 3],
  656. [[1, 2, 3]],
  657. ],
  658. [
  659. [1, 2, 3, [1, 2, 3], [2, 3], [4, 5, 6]],
  660. [2, 3],
  661. [1, [1, 2, 3], [2, 3], [4, 5, 6]],
  662. ],
  663. [
  664. [1, 2, 3, [1, 2, 3], [2, 3], [4, 5, 6]],
  665. [4, 5, 6],
  666. [1, 2, 3, [1, 2, 3], [2, 3], [4, 5, 6]],
  667. ],
  668. [
  669. [1, 2, 3, [1, 2, 3]],
  670. [[1, 2, 3]],
  671. [1, 2, 3],
  672. ],
  673. [
  674. [1, 2, 3, [1, 2, 3], [2, 3], [4, 5, 6]],
  675. [[2, 3]],
  676. [1, 2, 3, [1, 2, 3], [4, 5, 6]],
  677. ],
  678. [
  679. [1, 2, 3, [1, 2, 3], [2, 3], [4, 5, 6]],
  680. [[4, 5, 6]],
  681. [1, 2, 3, [1, 2, 3], [2, 3]],
  682. ],
  683. [
  684. [1, 2, 3, [1, 2, 3], [2, 3], [4, 5, 6]],
  685. [[1, 2, 3], [4, 5, 6]],
  686. [1, 2, 3, [2, 3]],
  687. ],
  688. [
  689. [1, 2, 3, [1, 2, 3], [2, 3], [4, 5, 6]],
  690. [1, [4, 5, 6], 3],
  691. [2, [1, 2, 3], [2, 3]],
  692. ],
  693. [
  694. [1, 2, 3, $vector],
  695. [$vector, 9],
  696. [1, 2, 3],
  697. ],
  698. [
  699. [1, 2, 3, $vector],
  700. [$vector],
  701. [1, 2, 3],
  702. ],
  703. [
  704. [1, 2, 3, $vector],
  705. [1, $vector],
  706. [2, 3],
  707. ],
  708. [
  709. [1, 2, 3, $fh],
  710. [1, $fh],
  711. [2, 3],
  712. ],
  713. ];
  714. }
  715. /**
  716. * @test
  717. * @dataProvider dataProviderForIsDisjoint
  718. */
  719. public function testIsDisjoint(array $A, array $B)
  720. {
  721. // Given
  722. $setA = new Set($A);
  723. $setB = new Set($B);
  724. // Then
  725. $this->assertTrue($setA->isDisjoint($setB));
  726. }
  727. public function dataProviderForIsDisjoint(): array
  728. {
  729. return [
  730. [
  731. [],
  732. [2],
  733. ],
  734. [
  735. [1],
  736. [],
  737. ],
  738. [
  739. [1],
  740. [2],
  741. ],
  742. [
  743. [1, 2, 3],
  744. [4, 5, 6],
  745. ],
  746. [
  747. [1, 2, 3,],
  748. [1.1, 2.2, -3],
  749. ],
  750. [
  751. [1, 2, 3, 'a', 'b'],
  752. [4, 5, 6, 'c', 'd'],
  753. ],
  754. [
  755. [1, 2, 3, new Set([1, 2])],
  756. [4, 5, 6],
  757. ],
  758. [
  759. [1, 2, 3, new Set([1, 2])],
  760. [4, 5, 6, new Set([2, 3])],
  761. ],
  762. [
  763. [new Set([1, 2])],
  764. [new Set([2, 3])],
  765. ],
  766. ];
  767. }
  768. /**
  769. * @test
  770. * @dataProvider dataProviderForNotDisjoint
  771. */
  772. public function testNotDisjoint(array $A, array $B)
  773. {
  774. // Given
  775. $setA = new Set($A);
  776. $setB = new Set($B);
  777. // Then
  778. $this->assertFalse($setA->isDisjoint($setB));
  779. }
  780. public function dataProviderForNotDisjoint(): array
  781. {
  782. return [
  783. [
  784. [1],
  785. [1],
  786. ],
  787. [
  788. [new Set()],
  789. [new Set()],
  790. ],
  791. [
  792. [new Set([1, 2])],
  793. [new Set([1, 2])],
  794. ],
  795. [
  796. [1, 2, 3],
  797. [3, 4, 5],
  798. ],
  799. ];
  800. }
  801. /**
  802. * @test
  803. * @dataProvider dataProviderForIsSubsetSuperset
  804. */
  805. public function testIsSubset(array $A, array $B)
  806. {
  807. // Given
  808. $setA = new Set($A);
  809. $setB = new Set($B);
  810. // Then
  811. $this->assertTrue($setA->isSubset($setB));
  812. }
  813. public function dataProviderForIsSubsetSuperset(): array
  814. {
  815. return [
  816. [
  817. [],
  818. [1],
  819. ],
  820. [
  821. [1],
  822. [1],
  823. ],
  824. [
  825. [1, 2],
  826. [1, 2],
  827. ],
  828. [
  829. [1, 2],
  830. [1, 2, 3],
  831. ],
  832. [
  833. [1, 2, 'a'],
  834. [1, 2, 3, 'a', 4.5, new Set([1, 2])],
  835. ],
  836. [
  837. [1, 2, 'a', new Set([1, 2])],
  838. [1, 2, 3, 'a', 4.5, new Set([1, 2])],
  839. ],
  840. [
  841. [1, 2, 'a', new Set([1, 2]), -1, 2.4],
  842. [1, 2, 3, 'a', 4.5, new Set([1, 2]), -1, -2, 2.4, 3.5],
  843. ],
  844. ];
  845. }
  846. /**
  847. * @test
  848. * @dataProvider dataProviderForIsNotSubset
  849. */
  850. public function testIsNotSubset(array $A, array $B)
  851. {
  852. // Given
  853. $setA = new Set($A);
  854. $setB = new Set($B);
  855. // Then
  856. $this->assertFalse($setA->isSubset($setB));
  857. }
  858. public function dataProviderForIsNotSubset(): array
  859. {
  860. return [
  861. [
  862. [1],
  863. [],
  864. ],
  865. [
  866. [1, 2],
  867. [1],
  868. ],
  869. [
  870. [1, 2, 3],
  871. [1, 2],
  872. ],
  873. [
  874. [1, 2, 3, 4],
  875. [1, 2, 3],
  876. ],
  877. [
  878. [1, 2, 'b'],
  879. [1, 2, 3, 'a', 4.5, new Set([1, 2])],
  880. ],
  881. [
  882. [1, 2, 3, 'a', 4.5, new Set([1, 2])],
  883. [1, 2, 'a', new Set([1, 2])],
  884. ],
  885. [
  886. [1, 2, 3, 'a', 4.5, new Set([1, 2]), -1, -2, 2.4, 3.5],
  887. [1, 2, 'a', new Set([1, 2]), -1, 2.4],
  888. ],
  889. ];
  890. }
  891. /**
  892. * @test
  893. * @dataProvider dataProviderForIsProperSet
  894. */
  895. public function testIsProperSubset(array $A, array $B)
  896. {
  897. // Given
  898. $setA = new Set($A);
  899. $setB = new Set($B);
  900. // Then
  901. $this->assertTrue($setA->isProperSubset($setB));
  902. }
  903. /**
  904. * @test
  905. * @dataProvider dataProviderForIsProperSet
  906. */
  907. public function testIsProperSuperset(array $A, array $B)
  908. {
  909. // Given
  910. $setA = new Set($B);
  911. $setB = new Set($A);
  912. // Then
  913. $this->assertFalse($setA->isProperSuperset($setB));
  914. }
  915. public function dataProviderForIsProperSet(): array
  916. {
  917. return [
  918. [
  919. [],
  920. [],
  921. ],
  922. [
  923. [1],
  924. [1],
  925. ],
  926. [
  927. [1, 2],
  928. [1, 2],
  929. ],
  930. [
  931. [1, 3, 2],
  932. [1, 2, 3],
  933. ],
  934. [
  935. [1, 2,'a', 3, 4.5, new Set([1, 2])],
  936. [1, 2, 3, 'a', 4.5, new Set([1, 2])],
  937. ],
  938. [
  939. [1, 2, 3, 'a', 4.5, new Set([1, 2])],
  940. [1, 2, 3, 'a', 4.5, new Set([1, 2])],
  941. ],
  942. [
  943. [1, 2, 3, 'a', 4.5, new Set([1, 2]), -1, -2, 2.4, 3.5],
  944. [1, 2, 3, 'a', 4.5, new Set([1, 2]), -1, -2, 2.4, 3.5],
  945. ],
  946. ];
  947. }
  948. /**
  949. * @test
  950. * @dataProvider dataProviderForIsSubsetSuperset
  951. */
  952. public function testIsSuperset(array $A, array $B)
  953. {
  954. // Given
  955. $setA = new Set($B);
  956. $setB = new Set($A);
  957. // Then
  958. $this->assertTrue($setA->isSuperset($setB));
  959. }
  960. /**
  961. * @test
  962. * @dataProvider dataProviderForUnion
  963. */
  964. public function testUnion(array $A, array $B, array $A∪B, Set $R)
  965. {
  966. // Given
  967. $setA = new Set($A);
  968. $setB = new Set($B);
  969. $expected = new Set($A∪B);
  970. // When
  971. $union = $setA->union($setB);
  972. $union_array = $union->asArray();
  973. // Then
  974. $this->assertEquals($R, $union);
  975. $this->assertEquals($expected, $union);
  976. $this->assertEquals(count($A∪B), count($union));
  977. foreach ($A∪B as $member) {
  978. $this->assertArrayHasKey("$member", $union_array);
  979. }
  980. foreach ($A∪B as $_ => $value) {
  981. if ($value instanceof Set) {
  982. $this->assertEquals($value, $union_array["$value"]);
  983. } else {
  984. $this->assertArrayHasKey((string) $value, $union_array);
  985. }
  986. }
  987. }
  988. public function dataProviderForUnion(): array
  989. {
  990. $setOneTwo = new Set([1, 2]);
  991. return [
  992. [
  993. [],
  994. [],
  995. [],
  996. new Set(),
  997. ],
  998. [
  999. [1],
  1000. [],
  1001. [1],
  1002. new Set([1]),
  1003. ],
  1004. [
  1005. [],
  1006. [1],
  1007. [1],
  1008. new Set([1]),
  1009. ],
  1010. [
  1011. [1],
  1012. [1],
  1013. [1],
  1014. new Set([1]),
  1015. ],
  1016. [
  1017. [1],
  1018. [2],
  1019. [1, 2],
  1020. new Set([1, 2]),
  1021. ],
  1022. [
  1023. [2],
  1024. [1],
  1025. [1, 2],
  1026. new Set([1, 2]),
  1027. ],
  1028. [
  1029. [1],
  1030. [2],
  1031. [2, 1],
  1032. new Set([1, 2]),
  1033. ],
  1034. [
  1035. [2],
  1036. [1],
  1037. [2, 1],
  1038. new Set([1, 2]),
  1039. ],
  1040. [
  1041. [1, 2, 3, 'a', 'b'],
  1042. [1, 'a', 'k'],
  1043. [1, 2, 3, 'a', 'b', 'k'],
  1044. new Set([1, 2, 3, 'a', 'b', 'k']),
  1045. ],
  1046. [
  1047. [1, 2, 3, 'a', 'b', $setOneTwo],
  1048. [1, 'a', 'k'],
  1049. [1, 2, 3, 'a', 'b', 'k', $setOneTwo],
  1050. new Set([1, 2, 3, 'a', 'b', 'k', $setOneTwo]),
  1051. ],
  1052. [
  1053. [1, 2, 3, 'a', 'b'],
  1054. [1, 'a', 'k', $setOneTwo],
  1055. [1, 2, 3, 'a', 'b', 'k', $setOneTwo],
  1056. new Set([1, 2, 3, 'a', 'b', 'k', $setOneTwo]),
  1057. ],
  1058. [
  1059. [1, 2, 3, 'a', 'b', new Set()],
  1060. [1, 'a', 'k', $setOneTwo],
  1061. [1, 2, 3, 'a', 'b', 'k', $setOneTwo, new Set()],
  1062. new Set([1, 2, 3, 'a', 'b', 'k', $setOneTwo, new Set()]),
  1063. ],
  1064. [
  1065. [1, 2, 3, 'a', 'b', $setOneTwo],
  1066. [1, 'a', 'k', -2, '2.4', 3.5, $setOneTwo],
  1067. [1, 2, 3, 'a', 'b', 'k', -2, '2.4', 3.5, $setOneTwo],
  1068. new Set([1, 2, 3, 'a', 'b', 'k', -2, '2.4', 3.5, $setOneTwo]),
  1069. ],
  1070. ];
  1071. }
  1072. /**
  1073. * @test
  1074. * @dataProvider dataProviderForUnionMultipleSets
  1075. */
  1076. public function testUnionMultipleSets(array $A, array $B, array $C, array $A∪B∪C, Set $R)
  1077. {
  1078. // Given
  1079. $setA = new Set($A);
  1080. $setB = new Set($B);
  1081. $setC = new Set($C);
  1082. $expected = new Set($A∪B∪C);
  1083. // When
  1084. $union = $setA->union($setB, $setC);
  1085. $union_array = $union->asArray();
  1086. // Then
  1087. $this->assertEquals($R, $union);
  1088. $this->assertEquals($expected, $union);
  1089. $this->assertEquals(count($A∪B∪C), count($union));
  1090. foreach ($A∪B∪C as $member) {
  1091. $this->assertArrayHasKey("$member", $union_array);
  1092. }
  1093. foreach ($A∪B∪C as $_ => $value) {
  1094. if ($value instanceof Set) {
  1095. $this->assertEquals($value, $union_array["$value"]);
  1096. } else {
  1097. $this->assertArrayHasKey((string) $value, $union_array);
  1098. }
  1099. }
  1100. }
  1101. public function dataProviderForUnionMultipleSets(): array
  1102. {
  1103. return [
  1104. [
  1105. [1, 2, 3],
  1106. [2, 3, 4],
  1107. [3, 4, 5],
  1108. [1, 2, 3, 4, 5],
  1109. new Set([1, 2, 3, 4, 5]),
  1110. ],
  1111. [
  1112. [1, 2, 3, -3, 3.4],
  1113. [2, 3, 4, new Set()],
  1114. [3, 4, 5, new Set([1, 2])],
  1115. [1, 2, 3, 4, 5, -3, 3.4, new Set(), new Set([1, 2])],
  1116. new Set([1, 2, 3, 4, 5, -3, 3.4, new Set(), new Set([1, 2])]),
  1117. ],
  1118. ];
  1119. }
  1120. public function testUnionWithArrays()
  1121. {
  1122. // Given
  1123. $A = new Set([1, 2, [1, 2, 3]]);
  1124. $B = new Set([2, 3, [2, 3, 4]]);
  1125. $expected = new Set([1, 2, [1, 2, 3], 3, [2, 3, 4]]);
  1126. // When
  1127. $A∪B = $A->union($B);
  1128. // Then
  1129. $this->assertEquals($expected, $A∪B);
  1130. $this->assertEquals($expected->asArray(), $A∪B->asArray());
  1131. }
  1132. public function testUnionWithArrays2()
  1133. {
  1134. // Given
  1135. $A = new Set([1, 2, [1, 2, 3]]);
  1136. $B = new Set([2, 3, [2, 3, 4], [1, 2, 3]]);
  1137. $expected = new Set([1, 2, [1, 2, 3], 3, [2, 3, 4]]);
  1138. // When
  1139. $A∪B = $A->union($B);
  1140. // Then
  1141. $this->assertEquals($expected, $A∪B);
  1142. $this->assertEquals($expected->asArray(), $A∪B->asArray());
  1143. }
  1144. public function testUnionWithObjects()
  1145. {
  1146. // Given
  1147. $vector1 = new Vector([1, 2, 3]);
  1148. $vector2 = new Vector([1, 2, 3]);
  1149. $A = new Set([1, 2, $vector1]);
  1150. $B = new Set([2, 3, $vector2]);
  1151. $expected = new Set([1, 2, $vector1, 3, $vector2]);
  1152. // When
  1153. $A∪B = $A->union($B);
  1154. // Then
  1155. $this->assertEquals($expected, $A∪B);
  1156. $this->assertEquals($expected->asArray(), $A∪B->asArray());
  1157. }
  1158. public function testUnionWithObjects2()
  1159. {
  1160. // Given
  1161. $vector1 = new Vector([1, 2, 3]);
  1162. $vector2 = new Vector([1, 2, 3]);
  1163. $A = new Set([1, 2, $vector1]);
  1164. $B = new Set([2, 3, $vector2, $vector1]);
  1165. $expected = new Set([1, 2, $vector1, 3, $vector2]);
  1166. // When
  1167. $A∪B = $A->union($B);
  1168. // Then
  1169. $this->assertEquals($expected, $A∪B);
  1170. $this->assertEquals($expected->asArray(), $A∪B->asArray());
  1171. }
  1172. /**
  1173. * @test
  1174. * @dataProvider dataProviderForIntersect
  1175. */
  1176. public function testIntersect(array $A, array $B, array $A∩B, Set $R)
  1177. {
  1178. // Given
  1179. $setA = new Set($A);
  1180. $setB = new Set($B);
  1181. $expected = new Set($A∩B);
  1182. // When
  1183. $intersection = $setA->intersect($setB);
  1184. $intersection_array = $intersection->asArray();
  1185. // Then
  1186. $this->assertEquals($R, $intersection);
  1187. $this->assertEquals($expected, $intersection);
  1188. $this->assertEquals(count($A∩B), count($intersection));
  1189. foreach ($A∩B as $member) {
  1190. $this->assertArrayHasKey("$member", $intersection_array);
  1191. $this->assertArrayHasKey("$member", $setA->asArray());
  1192. $this->assertArrayHasKey("$member", $setB->asArray());
  1193. $this->assertContains($member, $A);
  1194. $this->assertContains($member, $B);
  1195. }
  1196. foreach ($A∩B as $_ => $value) {
  1197. if ($value instanceof Set) {
  1198. $this->assertEquals($value, $intersection_array["$value"]);
  1199. } else {
  1200. $this->assertContains($value, $intersection_array);
  1201. }
  1202. }
  1203. }
  1204. public function dataProviderForIntersect(): array
  1205. {
  1206. $setOneTwo = new Set([1, 2]);
  1207. return [
  1208. [
  1209. [],
  1210. [],
  1211. [],
  1212. new Set(),
  1213. ],
  1214. [
  1215. [1],
  1216. [],
  1217. [],
  1218. new Set(),
  1219. ],
  1220. [
  1221. [],
  1222. [1],
  1223. [],
  1224. new Set(),
  1225. ],
  1226. [
  1227. [1],
  1228. [1],
  1229. [1],
  1230. new Set([1]),
  1231. ],
  1232. [
  1233. [1],
  1234. [2],
  1235. [],
  1236. new Set(),
  1237. ],
  1238. [
  1239. [2],
  1240. [1],
  1241. [],
  1242. new Set(),
  1243. ],
  1244. [
  1245. [2],
  1246. [2],
  1247. [2],
  1248. new Set([2]),
  1249. ],
  1250. [
  1251. [1, 2],
  1252. [1, 2],
  1253. [1, 2],
  1254. new Set([1, 2]),
  1255. ],
  1256. [
  1257. [1, 2],
  1258. [2, 1],
  1259. [1, 2],
  1260. new Set([1, 2]),
  1261. ],
  1262. [
  1263. [1, 2, 3, 'a', 'b'],
  1264. [1, 'a', 'k'],
  1265. [1, 'a'],
  1266. new Set([1, 'a']),
  1267. ],
  1268. [
  1269. [1, 2, 3, 'a', 'b', new Set([1, 2])],
  1270. [1, 'a', 'k'],
  1271. [1, 'a'],
  1272. new Set([1, 'a']),
  1273. ],
  1274. [
  1275. [1, 2, 3, 'a', 'b'],
  1276. [1, 'a', 'k', new Set([1, 2])],
  1277. [1, 'a'],
  1278. new Set([1, 'a']),
  1279. ],
  1280. [
  1281. [1, 2, 3, 'a', 'b', $setOneTwo],
  1282. [1, 'a', 'k', $setOneTwo],
  1283. [1, 'a', $setOneTwo],
  1284. new Set([1, 'a', $setOneTwo]),
  1285. ],
  1286. [
  1287. [1, 2, 3, 'a', 'b', new Set()],
  1288. [1, 'a', 'k', $setOneTwo],
  1289. [1, 'a'],
  1290. new Set([1, 'a']),
  1291. ],
  1292. [
  1293. [1, 2, 3, 'a', 'b', $setOneTwo],
  1294. [1, 'a', 'k', -2, '2.4', 3.5, $setOneTwo],
  1295. [1, 'a', $setOneTwo],
  1296. new Set([1, 'a', $setOneTwo]),
  1297. ],
  1298. ];
  1299. }
  1300. /**
  1301. * @test
  1302. * @dataProvider dataProviderForIntersectMultipleSets
  1303. */
  1304. public function testIntersectMultipleSets(array $A, array $B, array $C, array $A∩B∩C, Set $R)
  1305. {
  1306. // Given
  1307. $setA = new Set($A);
  1308. $setB = new Set($B);
  1309. $setC = new Set($C);
  1310. $expected = new Set($A∩B∩C);
  1311. // When
  1312. $intersection = $setA->intersect($setB, $setC);
  1313. $intersection_array = $intersection->asArray();
  1314. // Then
  1315. $this->assertEquals($R, $intersection);
  1316. $this->assertEquals($expected, $intersection);
  1317. $this->assertEquals(count($A∩B∩C), count($intersection));
  1318. foreach ($A∩B∩C as $member) {
  1319. $this->assertArrayHasKey("$member", $intersection_array);
  1320. $this->assertArrayHasKey("$member", $setA->asArray());
  1321. $this->assertArrayHasKey("$member", $setB->asArray());
  1322. $this->assertArrayHasKey("$member", $setC->asArray());
  1323. $this->assertContains($member, $A);
  1324. $this->assertContains($member, $B);
  1325. $this->assertContains($member, $C);
  1326. }
  1327. foreach ($A∩B∩C as $_ => $value) {
  1328. if ($value instanceof Set) {
  1329. $this->assertEquals($value, $intersection_array["$value"]);
  1330. } else {
  1331. $this->assertContains($value, $intersection_array);
  1332. }
  1333. }
  1334. }
  1335. public function dataProviderForIntersectMultipleSets(): array
  1336. {
  1337. $setOneTwo = new Set([1, 2]);
  1338. return [
  1339. [
  1340. [1, 2, 3, 4],
  1341. [2, 3, 4, 5],
  1342. [3, 4, 5, 6],
  1343. [3, 4],
  1344. new Set([3, 4]),
  1345. ],
  1346. [
  1347. [1, 2, 3, 4, $setOneTwo],
  1348. [2, 3, 4, 5, $setOneTwo],
  1349. [3, 4, 5, 6, $setOneTwo],
  1350. [3, 4, $setOneTwo],
  1351. new Set([3, 4, $setOneTwo]),
  1352. ],
  1353. ];
  1354. }
  1355. public function testIntersectWithArrays()
  1356. {
  1357. // Given
  1358. $A = new Set([1, 2, [1, 2, 3]]);
  1359. $B = new Set([2, 3, [2, 3, 4]]);
  1360. $expected = new Set([2]);
  1361. // When
  1362. $A∩B = $A->intersect($B);
  1363. // Then
  1364. $this->assertEquals($expected, $A∩B);
  1365. $this->assertEquals($expected->asArray(), $A∩B->asArray());
  1366. }
  1367. public function testIntersectWithArrays2()
  1368. {
  1369. // Given
  1370. $A = new Set([1, 2, [1, 2, 3]]);
  1371. $B = new Set([2, 3, [2, 3, 4], [1, 2, 3]]);
  1372. $expected = new Set([2, [1, 2, 3]]);
  1373. // When
  1374. $A∩B = $A->intersect($B);
  1375. // Then
  1376. $this->assertEquals($expected, $A∩B);
  1377. $this->assertEquals($expected->asArray(), $A∩B->asArray());
  1378. }
  1379. public function testIntersectWithObjects()
  1380. {
  1381. // Given
  1382. $vector1 = new Vector([1, 2, 3]);
  1383. $vector2 = new Vector([1, 2, 3]);
  1384. $A = new Set([1, 2, $vector1]);
  1385. $B = new Set([2, 3, $vector2]);
  1386. $expected = new Set([2]);
  1387. // When
  1388. $A∩B = $A->intersect($B);
  1389. // Then
  1390. $this->assertEquals($expected, $A∩B);
  1391. $this->assertEquals($expected->asArray(), $A∩B->asArray());
  1392. }
  1393. public function testIntersectWithObjects2()
  1394. {
  1395. // Given
  1396. $vector1 = new Vector([1, 2, 3]);
  1397. $vector2 = new Vector([1, 2, 3]);
  1398. $A = new Set([1, 2, $vector1]);
  1399. $B = new Set([2, 3, $vector2, $vector1]);
  1400. $expected = new Set([2, $vector1]);
  1401. // When
  1402. $A∩B = $A->intersect($B);
  1403. // Then
  1404. $this->assertEquals($expected, $A∩B);
  1405. $this->assertEquals($expected->asArray(), $A∩B->asArray());
  1406. }
  1407. /**
  1408. * @test
  1409. * @dataProvider dataProviderForDifference
  1410. */
  1411. public function testDifference(array $A, array $B, array $diff, Set $R)
  1412. {
  1413. // Given
  1414. $setA = new Set($A);
  1415. $setB = new Set($B);
  1416. $expected = new Set($diff);
  1417. // When
  1418. $difference = $setA->difference($setB);
  1419. $difference_array = $difference->asArray();
  1420. // Then
  1421. $this->assertEquals($R, $difference);
  1422. $this->assertEquals($expected, $difference);
  1423. $this->assertEquals(count($diff), count($difference));
  1424. foreach ($diff as $member) {
  1425. $this->assertArrayHasKey("$member", $difference_array);
  1426. $this->assertArrayHasKey("$member", $setA->asArray());
  1427. $this->assertArrayNotHasKey("$member", $setB->asArray());
  1428. $this->assertContains($member, $A);
  1429. $this->assertNotContains("$member", $B);
  1430. }
  1431. foreach ($diff as $_ => $value) {
  1432. if ($value instanceof Set) {
  1433. $this->assertEquals($value, $difference_array["$value"]);
  1434. } else {
  1435. $this->assertContains($value, $difference_array);
  1436. }
  1437. }
  1438. }
  1439. public function dataProviderForDifference(): array
  1440. {
  1441. $emptySet = new Set();
  1442. $setOneTwo = new Set([1, 2]);
  1443. return [
  1444. [
  1445. [],
  1446. [],
  1447. [],
  1448. new Set(),
  1449. ],
  1450. [
  1451. [1],
  1452. [1],
  1453. [],
  1454. new Set(),
  1455. ],
  1456. [
  1457. [1, 2],
  1458. [1],
  1459. [2],
  1460. new Set([2]),
  1461. ],
  1462. [
  1463. [1],
  1464. [1, 2],
  1465. [],
  1466. new Set(),
  1467. ],
  1468. [
  1469. [1, 2, 3, 4],
  1470. [2, 3, 4, 5],
  1471. [1],
  1472. new Set([1]),
  1473. ],
  1474. [
  1475. [1, 2, 3, 'a', 'b'],
  1476. [1, 'a', 'k'],
  1477. [2, 3, 'b'],
  1478. new Set([2, 3, 'b']),
  1479. ],
  1480. [
  1481. [1, 2, 3, 'a', 'b', $setOneTwo],
  1482. [1, 'a', 'k'],
  1483. [2, 3, 'b',$setOneTwo],
  1484. new Set([2, 3, 'b', $setOneTwo]),
  1485. ],
  1486. [
  1487. [1, 2, 3, 'a', 'b'],
  1488. [1, 'a', 'k', new Set([1, 2])],
  1489. [2, 3, 'b'],
  1490. new Set([2, 3, 'b']),
  1491. ],
  1492. [
  1493. [1, 2, 3, 'a', 'b', $emptySet],
  1494. [1, 'a', 'k', new Set([1, 2])],
  1495. [2, 3, 'b', $emptySet],
  1496. new Set([2, 3, 'b', $emptySet]),
  1497. ],
  1498. [
  1499. [1, 2, 3, 'a', 'b', new Set([1, 2])],
  1500. [1, 'a', 'k', -2, '2.4', 3.5, new Set([1, 2])],
  1501. [2, 3, 'b'],
  1502. new Set([2, 3, 'b']),
  1503. ],
  1504. [
  1505. [1, 2,'a', 3, 4.5, new Set([1, 2])],
  1506. [1, 2, 3, 'a', 4.5, new Set([1, 2])],
  1507. [],
  1508. new Set(),
  1509. ],
  1510. [
  1511. [1, 2, 3, 'a', 4.5, new Set([1, 2])],
  1512. [1, 2, 3, 'a', 4.5, new Set([1, 2])],
  1513. [],
  1514. new Set(),
  1515. ],
  1516. [
  1517. [1, 2, 3, 'a', 4.5, new Set([1, 2]), -1, -2, 2.4, 3.5],
  1518. [1, 2, 3, 'a', 4.5, new Set([1, 2]), -1, -2, 2.4, 3.5],
  1519. [],
  1520. new Set(),
  1521. ],
  1522. ];
  1523. }
  1524. /**
  1525. * @test
  1526. * @dataProvider dataProviderForDifferenceMultiSet
  1527. */
  1528. public function testDifferenceMultiSet(array $A, array $B, array $C, array $diff, Set $R)
  1529. {
  1530. // Given
  1531. $setA = new Set($A);
  1532. $setB = new Set($B);
  1533. $setC = new Set($C);
  1534. $expected = new Set($diff);
  1535. // When
  1536. $difference = $setA->difference($setB, $setC);
  1537. $difference_array = $difference->asArray();
  1538. // Then
  1539. $this->assertEquals($R, $difference);
  1540. $this->assertEquals($expected, $difference);
  1541. $this->assertEquals(count($diff), count($difference));
  1542. foreach ($diff as $member) {
  1543. $this->assertArrayHasKey("$member", $difference_array);
  1544. $this->assertArrayHasKey("$member", $setA->asArray());
  1545. $this->assertArrayNotHasKey("$member", $setB->asArray());
  1546. $this->assertArrayNotHasKey("$member", $setC->asArray());
  1547. $this->assertContains($member, $A);
  1548. $this->assertNotContains("$member", $B);
  1549. $this->assertNotContains("$member", $C);
  1550. }
  1551. foreach ($diff as $_ => $value) {
  1552. if ($value instanceof Set) {
  1553. $this->assertEquals($value, $difference_array["$value"]);
  1554. } else {
  1555. $this->assertContains($value, $difference_array);
  1556. }
  1557. }
  1558. }
  1559. public function dataProviderForDifferenceMultiSet(): array
  1560. {
  1561. $setOneTwo = new Set([1, 2]);
  1562. return [
  1563. [
  1564. ['1', '2', '3', '4'],
  1565. ['2', '3', '4', '5'],
  1566. ['3', '4', '5', '6'],
  1567. ['1'],
  1568. new Set([1]),
  1569. ],
  1570. [
  1571. ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'],
  1572. ['2', '4', '6', '8', '10'],
  1573. ['5', '10'],
  1574. ['1', '3', '7', '9'],
  1575. new Set([1, 3, 7, 9]),
  1576. ],
  1577. [
  1578. ['1', '2', '3', '4', $setOneTwo],
  1579. ['2', '3', '4', '5'],
  1580. ['3', '4', '5', '6'],
  1581. ['1', $setOneTwo],
  1582. new Set([1, $setOneTwo]),
  1583. ],
  1584. [
  1585. ['1', '2', '3', '4', new Set([1, 2])],
  1586. ['2', '3', '4', '5'],
  1587. ['3', '4', '5', '6', new Set([1, 2])],
  1588. ['1'],
  1589. new Set([1]),
  1590. ],
  1591. ];
  1592. }
  1593. public function testDifferenceWithArrays()
  1594. {
  1595. // Given
  1596. $A = new Set([1, 2, [1, 2, 3]]);
  1597. $B = new Set([2, 3, [2, 3, 4]]);
  1598. $expected = new Set([1, [1, 2, 3]]);
  1599. // When
  1600. $A∖B = $A->difference($B);
  1601. // Then
  1602. $this->assertEquals($expected, $A∖B);
  1603. $this->assertEquals($expected->asArray(), $A∖B->asArray());
  1604. }
  1605. public function testDifferenceWithArrays2()
  1606. {
  1607. // Given
  1608. $A = new Set([1, 2, [1, 2, 3]]);
  1609. $B = new Set([2, 3, [2, 3, 4], [1, 2, 3]]);
  1610. $expected = new Set([1]);
  1611. // When
  1612. $A∖B = $A->difference($B);
  1613. // Then
  1614. $this->assertEquals($expected, $A∖B);
  1615. $this->assertEquals($expected->asArray(), $A∖B->asArray());
  1616. }
  1617. public function testDifferenceWithObjects()
  1618. {
  1619. // Given
  1620. $vector1 = new Vector([1, 2, 3]);
  1621. $vector2 = new Vector([1, 2, 3]);
  1622. $A = new Set([1, 2, $vector1]);
  1623. $B = new Set([2, 3, $vector2]);
  1624. $expected = new Set([1, $vector1]);
  1625. // When
  1626. $A∖B = $A->difference($B);
  1627. // Then
  1628. $this->assertEquals($expected, $A∖B);
  1629. $this->assertEquals($expected->asArray(), $A∖B->asArray());
  1630. }
  1631. public function testDifferenceWithObjects2()
  1632. {
  1633. // Given
  1634. $vector1 = new Vector([1, 2, 3]);
  1635. $vector2 = new Vector([1, 2, 3]);
  1636. $A = new Set([1, 2, $vector1]);
  1637. $B = new Set([2, 3, $vector2, $vector1]);
  1638. $expected = new Set([1]);
  1639. // When
  1640. $A∖B = $A->difference($B);
  1641. // Then
  1642. $this->assertEquals($expected, $A∖B);
  1643. $this->assertEquals($expected->asArray(), $A∖B->asArray());
  1644. }
  1645. /**
  1646. * @test
  1647. * @dataProvider dataProviderForSymmetricDifference
  1648. */
  1649. public function testSymmetricDifference(array $A, array $B, array $diff, Set $R)
  1650. {
  1651. // Given
  1652. $setA = new Set($A);
  1653. $setB = new Set($B);
  1654. $expected = new Set($diff);
  1655. // When
  1656. $difference = $setA->symmetricDifference($setB);
  1657. $difference_array = $difference->asArray();
  1658. // Then
  1659. $this->assertEquals($R, $difference);
  1660. $this->assertEquals($expected, $difference);
  1661. $this->assertEquals(count($diff), count($difference));
  1662. foreach ($diff as $member) {
  1663. $this->assertArrayHasKey("$member", $difference_array);
  1664. }
  1665. foreach ($diff as $_ => $value) {
  1666. if ($value instanceof Set) {
  1667. $this->assertEquals($value, $difference_array["$value"]);
  1668. } else {
  1669. $this->assertArrayHasKey((string) $value, $difference_array);
  1670. }
  1671. }
  1672. }
  1673. public function dataProviderForSymmetricDifference(): array
  1674. {
  1675. return [
  1676. [
  1677. [1, 2, 3],
  1678. [2, 3, 4],
  1679. [1, 4],
  1680. new Set([1, 4]),
  1681. ],
  1682. [
  1683. [1, 2, 3, new Set()],
  1684. [2, 3, 4],
  1685. [1, 4, new Set()],
  1686. new Set([1, 4, new Set()]),
  1687. ],
  1688. [
  1689. [1, 2, 3],
  1690. [2, 3, 4, new Set()],
  1691. [1, 4, new Set()],
  1692. new Set([1, 4, new Set()]),
  1693. ],
  1694. [
  1695. [1, 2, 3, new Set()],
  1696. [2, 3, 4, new Set()],
  1697. [1, 4],
  1698. new Set([1, 4]),
  1699. ],
  1700. [
  1701. [1, 3, 5, 7, 9],
  1702. [2, 4, 6, 8, 10],
  1703. [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
  1704. new Set([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]),
  1705. ],
  1706. ];
  1707. }
  1708. public function testSymmetricDifferenceWithArrays()
  1709. {
  1710. // Given
  1711. $A = new Set([1, 2, [1, 2, 3]]);
  1712. $B = new Set([2, 3, [2, 3, 4]]);
  1713. $expected = new Set([1, 3, [1, 2, 3], [2, 3, 4]]);
  1714. // When
  1715. $AΔB = $A->symmetricDifference($B);
  1716. // Then
  1717. $this->assertEquals($expected, $AΔB);
  1718. $this->assertEquals($expected->asArray(), $AΔB->asArray());
  1719. }
  1720. public function testSymmetricDifferenceWithArrays2()
  1721. {
  1722. // Given
  1723. $A = new Set([1, 2, [1, 2, 3]]);
  1724. $B = new Set([2, 3, [2, 3, 4], [1, 2, 3]]);
  1725. $expected = new Set([1, 3, [2, 3, 4]]);
  1726. // When
  1727. $AΔB = $A->symmetricDifference($B);
  1728. // Then
  1729. $this->assertEquals($expected, $AΔB);
  1730. $this->assertEquals($expected->asArray(), $AΔB->asArray());
  1731. }
  1732. public function testSymmetricDifferenceWithObjects()
  1733. {
  1734. // Given
  1735. $vector1 = new Vector([1, 2, 3]);
  1736. $vector2 = new Vector([1, 2, 3]);
  1737. $A = new Set([1, 2, $vector1]);
  1738. $B = new Set([2, 3, $vector2]);
  1739. $expected = new Set([1, 3, $vector1, $vector2]);
  1740. // When
  1741. $AΔB = $A->symmetricDifference($B);
  1742. // Then
  1743. $this->assertEquals($expected, $AΔB);
  1744. $this->assertEquals($expected->asArray(), $AΔB->asArray());
  1745. }
  1746. public function testSymmetricDifferenceWithObjects2()
  1747. {
  1748. // Given
  1749. $vector1 = new Vector([1, 2, 3]);
  1750. $vector2 = new Vector([1, 2, 3]);
  1751. $A = new Set([1, 2, $vector1]);
  1752. $B = new Set([2, 3, $vector2, $vector1]);
  1753. $expected = new Set([1, 3, $vector2]);
  1754. // When
  1755. $AΔB = $A->symmetricDifference($B);
  1756. // Then
  1757. $this->assertEquals($expected, $AΔB);
  1758. $this->assertEquals($expected->asArray(), $AΔB->asArray());
  1759. }
  1760. /**
  1761. * @test
  1762. * @dataProvider dataProviderForSingleSet
  1763. */
  1764. public function testCopy(array $members)
  1765. {
  1766. // Given
  1767. $set = new Set($members);
  1768. $copy = $set->copy();
  1769. // When
  1770. $set_array = $set->asArray();
  1771. $copy_array = $copy->asArray();
  1772. // Then
  1773. $this->assertEquals($set, $copy);
  1774. $this->assertEquals($set_array, $copy_array);
  1775. $this->assertEquals(count($set), count($copy));
  1776. }
  1777. /**
  1778. * @test
  1779. * @dataProvider dataProviderForSingleSet
  1780. */
  1781. public function testClear(array $members)
  1782. {
  1783. // Given
  1784. $set = new Set($members);
  1785. // When
  1786. $set->clear();
  1787. // Then
  1788. $this->assertTrue($set->isEmpty());
  1789. $this->assertEmpty($set->asArray());
  1790. $this->assertEquals($set, new Set());
  1791. }
  1792. /**
  1793. * @test
  1794. * @dataProvider dataProviderForCartesianProduct
  1795. */
  1796. public function testCartesianProduct(array $A, array $B, array $A×B, Set $R)
  1797. {
  1798. // Given
  1799. $setA = new Set($A);
  1800. $setB = new Set($B);
  1801. // When
  1802. $setA×B = $setA->cartesianProduct($setB);
  1803. $A×B_array = $setA×B->asArray();
  1804. // Then
  1805. $this->assertEquals($R, $setA×B);
  1806. $this->assertEquals($A×B, $A×B_array);
  1807. $this->assertEquals(count($setA×B), count($A×B));
  1808. foreach ($setA×B as $key => $value) {
  1809. $this->assertInstanceOf(Set::class, $value);
  1810. $this->assertEquals(2, count($value));
  1811. }
  1812. foreach ($A×B_array as $key => $value) {
  1813. $this->assertInstanceOf(Set::class, $value);
  1814. $this->assertEquals(2, count($value));
  1815. }
  1816. }
  1817. public function dataProviderForCartesianProduct(): array
  1818. {
  1819. return [
  1820. [
  1821. [1, 2],
  1822. [3, 4],
  1823. ['Set{1, 3}' => new Set([1, 3]), 'Set{1, 4}' => new Set([1, 4]), 'Set{2, 3}' => new Set([2, 3]), 'Set{2, 4}' => new Set([2, 4])],
  1824. new Set([new Set([1, 3]), new Set([1, 4]), new Set([2, 3]), new Set([2, 4])]),
  1825. ],
  1826. [
  1827. [1, 2],
  1828. ['red', 'white'],
  1829. ['Set{1, red}' => new Set([1, 'red']), 'Set{1, white}' => new Set([1, 'white']), 'Set{2, red}' => new Set([2, 'red']), 'Set{2, white}' => new Set([2, 'white'])],
  1830. new Set([new Set([1, 'red']), new Set([1, 'white']), new Set([2, 'red']), new Set([2, 'white'])]),
  1831. ],
  1832. [
  1833. [1, 2],
  1834. [],
  1835. [],
  1836. new Set(),
  1837. ],
  1838. ];
  1839. }
  1840. /**
  1841. * @test
  1842. * @dataProvider dataProviderForNaryCartesianProduct
  1843. */
  1844. public function testNaryCartesianProduct(array $A, array $B, array $C, array $A×B×C, Set $R)
  1845. {
  1846. // Given
  1847. $setA = new Set($A);
  1848. $setB = new Set($B);
  1849. $setC = new Set($C);
  1850. // When
  1851. $setA×B×C = $setA->cartesianProduct($setB, $setC);
  1852. $A×B×C_array = $setA×B×C->asArray();
  1853. // Then
  1854. $this->assertEquals($R, $setA×B×C);
  1855. $this->assertEquals($A×B×C, $A×B×C_array);
  1856. $this->assertEquals(count($setA×B×C), count($A×B×C));
  1857. $this->assertEquals(count($setA×B×C), count($setA) * count($setB) * count($setC));
  1858. foreach ($setA×B×C as $key => $value) {
  1859. $this->assertInstanceOf(Set::class, $value);
  1860. $this->assertEquals(3, count($value));
  1861. }
  1862. foreach ($A×B×C_array as $key => $value) {
  1863. $this->assertInstanceOf(Set::class, $value);
  1864. $this->assertEquals(3, count($value));
  1865. }
  1866. }
  1867. public function dataProviderForNaryCartesianProduct(): array
  1868. {
  1869. return [
  1870. [
  1871. [1, 2],
  1872. [3, 4],
  1873. [5, 6],
  1874. [
  1875. 'Set{1, 3, 5}' => new Set([1, 3, 5]),
  1876. 'Set{1, 3, 6}' => new Set([1, 3, 6]),
  1877. 'Set{1, 4, 5}' => new Set([1, 4, 5]),
  1878. 'Set{1, 4, 6}' => new Set([1, 4, 6]),
  1879. 'Set{2, 3, 5}' => new Set([2, 3, 5]),
  1880. 'Set{2, 3, 6}' => new Set([2, 3, 6]),
  1881. 'Set{2, 4, 5}' => new Set([2, 4, 5]),
  1882. 'Set{2, 4, 6}' => new Set([2, 4, 6]),
  1883. ],
  1884. new Set([
  1885. new Set([1, 3, 5]),
  1886. new Set([1, 3, 6]),
  1887. new Set([1, 4, 5]),
  1888. new Set([1, 4, 6]),
  1889. new Set([2, 3, 5]),
  1890. new Set([2, 3, 6]),
  1891. new Set([2, 4, 5]),
  1892. new Set([2, 4, 6]),
  1893. ]),
  1894. ],
  1895. [
  1896. [1, 2],
  1897. ['red', 'white'],
  1898. ['A', 'B'],
  1899. [
  1900. 'Set{1, red, A}' => new Set([1, 'red', 'A']),
  1901. 'Set{1, red, B}' => new Set([1, 'red', 'B']),
  1902. 'Set{1, white, A}' => new Set([1, 'white', 'A']),
  1903. 'Set{1, white, B}' => new Set([1, 'white', 'B']),
  1904. 'Set{2, red, A}' => new Set([2, 'red', 'A']),
  1905. 'Set{2, red, B}' => new Set([2, 'red', 'B']),
  1906. 'Set{2, white, A}' => new Set([2, 'white', 'A']),
  1907. 'Set{2, white, B}' => new Set([2, 'white', 'B']),
  1908. ],
  1909. new Set([
  1910. new Set([1, 'red', 'A']),
  1911. new Set([1, 'red', 'B']),
  1912. new Set([1, 'white', 'A']),
  1913. new Set([1, 'white', 'B']),
  1914. new Set([2, 'red', 'A']),
  1915. new Set([2, 'red', 'B']),
  1916. new Set([2, 'white', 'A']),
  1917. new Set([2, 'white', 'B']),
  1918. ]),
  1919. ],
  1920. [
  1921. [1, 2],
  1922. [3],
  1923. [],
  1924. [],
  1925. new Set(),
  1926. ],
  1927. ];
  1928. }
  1929. /**
  1930. * @test
  1931. * @dataProvider dataProviderForPowerSet
  1932. */
  1933. public function testPowerSet(Set $A, Set $expected)
  1934. {
  1935. // When
  1936. $P⟮S⟯ = $A->powerSet();
  1937. // Then
  1938. $this->assertEquals($expected, $P⟮S⟯);
  1939. $this->assertEquals($expected->asArray(), $P⟮S⟯->asArray());
  1940. $this->assertEquals(count($expected), count($P⟮S⟯));
  1941. }
  1942. public function dataProviderForPowerSet(): array
  1943. {
  1944. return [
  1945. // P({}) = {Ø}
  1946. [
  1947. new Set(),
  1948. new Set([
  1949. new Set(),
  1950. ]),
  1951. ],
  1952. // P({1}) = {{Ø}, {1}}
  1953. [
  1954. new Set([1]),
  1955. new Set([
  1956. new Set(),
  1957. new Set([1]),
  1958. ]),
  1959. ],
  1960. // P({1, 2, 3}) = {Ø, {1}, {2}, {3}, {1,2}, {1,3}, {2,3}, {1,2,3}}
  1961. [
  1962. new Set([1, 2, 3]),
  1963. new Set([
  1964. new Set(),
  1965. new Set([1]),
  1966. new Set([2]),
  1967. new Set([3]),
  1968. new Set([1, 2]),
  1969. new Set([1, 3]),
  1970. new Set([2, 3]),
  1971. new Set([1, 2, 3]),
  1972. ]),
  1973. ],
  1974. // P({x, y, z}) = {Ø, {x}, {y}, {z}, {x,y}, {x,z}, {y,z}, {x,y,z}}
  1975. [
  1976. new Set(['x', 'y', 'z']),
  1977. new Set([
  1978. new Set(),
  1979. new Set(['x']),
  1980. new Set(['y']),
  1981. new Set(['z']),
  1982. new Set(['x', 'y']),
  1983. new Set(['x', 'z']),
  1984. new Set(['y', 'z']),
  1985. new Set(['x', 'y', 'z']),
  1986. ]),
  1987. ],
  1988. // P({1, [1, 2]}) = {Ø, {1}, {[1, 2]}, {1, [1, 2]}}
  1989. [
  1990. new Set([1, [1, 2]]),
  1991. new Set([
  1992. new Set(),
  1993. new Set([1]),
  1994. new Set([[1, 2]]),
  1995. new Set([1, [1, 2]]),
  1996. ]),
  1997. ],
  1998. ];
  1999. }
  2000. public function dataProviderForSingleSet(): array
  2001. {
  2002. $fh = fopen(__FILE__, 'r');
  2003. $vector = new Vector([1, 2, 3]);
  2004. $func = function ($x) {
  2005. return $x * 2;
  2006. };
  2007. return [
  2008. [[]],
  2009. [[0]],
  2010. [[1]],
  2011. [[5]],
  2012. [[-5]],
  2013. [[1, 2]],
  2014. [[1, 2, 3]],
  2015. [[1, -2, 3]],
  2016. [[1, 2, 3, 4, 5, 6]],
  2017. [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]],
  2018. [[1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2, 2.01, 2.001, 2.15]],
  2019. [['a']],
  2020. [['a', 'b']],
  2021. [['a', 'b', 'c', 'd', 'e']],
  2022. [[1, 2, 'a', 'b', 3.14, 'hello', 'goodbye']],
  2023. [[1, 2, 3, new Set([1, 2]), 'a', 'b']],
  2024. [['a', 1, 'b', new Set([1, 'b'])]],
  2025. [['a', 1, 'b', new Set([1, 'b']), '4', 5]],
  2026. [['a', 1, 'b', new Set([1, 'b']), new Set([3, 4, 5]), '4', 5]],
  2027. [[1, 2, 3, [1, 2], [2, 3, 4]]],
  2028. [[1, 2, $fh, $vector, [4, 5], 6, 'a', $func, 12, new Set([4, 6, 7]), new Set(), 'sets']],
  2029. ];
  2030. }
  2031. }