You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LuhnTest.php 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace Faker\Test\Calculator;
  3. use Faker\Calculator\Luhn;
  4. class LuhnTest extends \PHPUnit_Framework_TestCase
  5. {
  6. public function checkDigitProvider()
  7. {
  8. return array(
  9. array('7992739871', '3'),
  10. array('3852000002323', '7'),
  11. array('37144963539843', '1'),
  12. array('561059108101825', '0'),
  13. array('601100099013942', '4'),
  14. array('510510510510510', '0'),
  15. array(7992739871, '3'),
  16. array(3852000002323, '7'),
  17. array(37144963539843, '1'),
  18. array(561059108101825, '0'),
  19. array(601100099013942, '4'),
  20. array(510510510510510, '0')
  21. );
  22. }
  23. /**
  24. * @dataProvider checkDigitProvider
  25. */
  26. public function testComputeCheckDigit($partialNumber, $checkDigit)
  27. {
  28. $this->assertInternalType('string', $checkDigit);
  29. $this->assertEquals($checkDigit, Luhn::computeCheckDigit($partialNumber));
  30. }
  31. public function validatorProvider()
  32. {
  33. return array(
  34. array('79927398710', false),
  35. array('79927398711', false),
  36. array('79927398712', false),
  37. array('79927398713', true),
  38. array('79927398714', false),
  39. array('79927398715', false),
  40. array('79927398716', false),
  41. array('79927398717', false),
  42. array('79927398718', false),
  43. array('79927398719', false),
  44. array(79927398713, true),
  45. array(79927398714, false),
  46. );
  47. }
  48. /**
  49. * @dataProvider validatorProvider
  50. */
  51. public function testIsValid($number, $isValid)
  52. {
  53. $this->assertEquals($isValid, Luhn::isValid($number));
  54. }
  55. }