Another script for interpreter testing.
Tous les contrôles ont réussi
The build was successful.

Cette révision appartient à :
2019-04-10 19:12:44 +02:00
Parent 08307c5ad6
révision ab4705518c
2 fichiers modifiés avec 29 ajouts et 0 suppressions

28
tests/center_text.aer Fichier normal
Voir le fichier

@@ -0,0 +1,28 @@
class Program {
private string center_text(string $word){
int $tot_width = 30;
char $symbol = '-';
int $middle = (int) round($tot_width/2);
int $length_word = strlen($word);
int $middle_word = (int) round($length_word / 2);
int $last_position = $middle + $middle_word;
int $number_of_spaces = $middle - $middle_word;
string $result = sprintf("%'{$symbol}{$last_position}s", $word);
for(int $i = 0; $i < $number_of_spaces; $i++) {
$result += "$symbol";
}
return $result;
}
void main() {
string $str = 'Example text';
print($this->center_text($str));
}
}
/* Should output
---------------This is some text------------
*/

1
tests/center_text.exp Fichier normal
Voir le fichier

@@ -0,0 +1 @@
---------Example text---------