Browse Source

More tests to go.

pull/50/head
Rafal Kupiec 1 year ago
parent
commit
580d1af308
Signed by: belliash GPG Key ID: 4E829243E0CFE6B4
2 changed files with 30 additions and 0 deletions
  1. +26
    -0
      tests/int2alpha_test.aer
  2. +4
    -0
      tests/int2alpha_test.exp

+ 26
- 0
tests/int2alpha_test.aer View File

@ -0,0 +1,26 @@
class Program {
string num2alpha(int $n) {
string $r = '';
for(int $i = 1; $n >= 0 && $i < 10; $i++) {
$r = chr(0x41 + ($n % pow(26, $i) / pow(26, $i - 1))) + $r;
$n -= pow(26, $i);
}
return $r;
}
int alpha2num(string $a) {
int $r = 0;
int $l = strlen($a);
for(int $i = 0; $i < $l; $i++) {
$r += pow(26, $i) * (ord($a[$l - $i - 1]) - 0x40);
}
return (int) $r - 1;
}
void main() {
import('math');
var_dump($this->alpha2num("Salut"), $this->num2alpha(1723), $this->num2alpha(9854), $this->alpha2num("Base64"));
}
}

+ 4
- 0
tests/int2alpha_test.exp View File

@ -0,0 +1,4 @@
int(9293725)
string(3 'BNH')
string(3 'NOA')
int(39764075)

Loading…
Cancel
Save