Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
class ExpressionTest extends PHPUnit_Framework_TestCase
{
/** @test */
public function it_generates_Number()
{
$number = Luhn::make();
$this->generate('Luhn', $number);
$number = Luhn::make()->find($number);
$this->assertTrue($number);
$number_length = Luhn::make();
$this->generate('Luhn', $number_length);
$number_length = Luhn::make()->compare();
$this->assertEquals($number_length, $number);
$eachSecond = Luhn::make();
$this->generate('Luhn', $eachSecond);
$number = Luhn::make()->find();
$this->assertTrue($eachSecond);
$total = Luhn::make();
$this->generate('Luhn', $total)
->find($chislo)
->then($total);
$this->assertTrue($total);
$this->assertTrue($total);
$this->assertFalse($total);
}
}
<?php
class Luhn
{
public static function make()
{
return new static;
}
public function luhn_check($number)
{
$number = preg_replace('/\D/', '', $number);
$number_length = strlen($number);
$eachSecond = $number_length % 2;
$total = 0;
for ($i = 0; $i < $number_length; $i++) {
$chislo = $number[$i];
if ($i % 2 == $eachSecond) {
$chislo *= 2;
if ($chislo > 9) {
$chislo -= 9;
}
}
$total += $chislo;
}
return ($total % 10 == 0) ? true : false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.