Test.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. declare(strict_types=1);
  3. use PHPUnit\Framework\TestCase;
  4. require_once __DIR__ . "/aretheythesame.php";
  5. class Check {
  6. /**
  7. * @var string
  8. */
  9. public $name;
  10. /**
  11. * @var array
  12. */
  13. public $one;
  14. /**
  15. * @var array
  16. */
  17. public $two;
  18. /**
  19. * @var bool
  20. */
  21. public $expected;
  22. public function __construct(string $name, array $a, $b, bool $expected) {
  23. $this->one = $a;
  24. $this->two = $b;
  25. $this->expected = $expected;
  26. $this->name = $name;
  27. }
  28. }
  29. class TestCompCase extends TestCase {
  30. function testComp() {
  31. $checks = [
  32. new Check(
  33. "Good",
  34. [121, 144, 19, 161, 19, 144, 19, 11],
  35. [121, 14641, 20736, 361, 25921, 361, 20736, 361],
  36. true
  37. ),
  38. new Check(
  39. "132 is not 11^2",
  40. [121, 144, 19, 161, 19, 144, 19, 11],
  41. [132, 14641, 20736, 361, 25921, 361, 20736, 361],
  42. false
  43. ),
  44. new Check(
  45. "36100 is not the square of any member of a",
  46. [121, 144, 19, 161, 19, 144, 19, 11],
  47. [121, 14641, 20736, 36100, 25921, 361, 20736, 361],
  48. false
  49. ),
  50. new Check(
  51. "Bad pair",
  52. [4, 4],
  53. [1, 31],
  54. false
  55. ),
  56. new Check(
  57. "Empty and null",
  58. [],
  59. NULL,
  60. false
  61. )
  62. ];
  63. /** @var \Check $check */
  64. foreach ($checks as $check) {
  65. $actual = comp($check->one, $check->two);
  66. }
  67. $this->assertEquals($check->expected, $actual, $check->name);
  68. }
  69. }