Add new test - luhn verification.
Все проверки выполнены успешно
The build was successful.

Этот коммит содержится в:
Rafal Kupiec 2019-04-04 11:53:50 +02:00
родитель 7ec7ade171
Коммит dc44ee31b8
Подписано: belliash
Идентификатор ключа GPG: 4E829243E0CFE6B4
2 изменённых файлов: 50 добавлений и 0 удалений

44
tests/luhn_verify.aer Обычный файл
Просмотреть файл

@ -0,0 +1,44 @@
class Luhn {
private string $number;
string getNumber() {
return $this->number;
}
void setNumber(string $number) {
$this->number = $number;
}
bool validate() {
string $sum;
string $revNumber;
int $len;
$revNumber = strrev($this->number);
$len = strlen($this->number);
for(int $i = 0; $i < $len; $i++) {
$sum += $i & 1 ? $revNumber[$i] * 2 : $revNumber[$i];
}
return array_sum(str_split($sum)) % 10 === 0;
}
}
class Program {
private const NUMBERS = {'3788803280', '6487308345', '5443489710530865', '5539266155200609', '4024007151066296', '4345234978'};
void main() {
int $i, $nums = sizeof($this->NUMBERS);
object $luhn = new Luhn();
while($i < $nums) {
$luhn->setNumber($this->NUMBERS[$i]);
if($luhn->validate()) {
print('The number ' + $luhn->getNumber() + ' has passed the Luhn validation.' + "\n");
} else {
print('The number ' + $luhn->getNumber() + ' has NOT passed the Luhn validation.' + "\n");
}
$i++;
}
}
}

6
tests/luhn_verify.exp Обычный файл
Просмотреть файл

@ -0,0 +1,6 @@
The number 3788803280 has passed the Luhn validation.
The number 6487308345 has passed the Luhn validation.
The number 5443489710530865 has passed the Luhn validation.
The number 5539266155200609 has passed the Luhn validation.
The number 4024007151066296 has passed the Luhn validation.
The number 4345234978 has NOT passed the Luhn validation.