Tower of Hanoi test.
All checks were successful
The build was successful.

This commit is contained in:
Rafal Kupiec 2019-12-22 22:58:36 +01:00
parent 3eb82e632b
commit c940224d21
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4
2 changed files with 37 additions and 0 deletions

22
tests/tower_of_hanoi.aer Normal file
View File

@ -0,0 +1,22 @@
class Hanoi {
public void towerOfHanoi(int $diskCount, int $fromPole, int $toPole, int $viaPole) {
if($diskCount == 1) {
printf('Move disk from pole ' + $fromPole + ' to pole ' + $toPole + "\n");
} else {
$this->towerOfHanoi($diskCount - 1, $fromPole, $viaPole, $toPole);
$this->towerOfHanoi(1, $fromPole, $toPole, $viaPole);
$this->towerOfHanoi($diskCount - 1, $viaPole, $toPole, $fromPole);
}
}
}
class Program {
public void main() {
object $hanoi = new Hanoi();
$hanoi->towerOfHanoi(4, 1, 2, 3);
}
}

15
tests/tower_of_hanoi.exp Normal file
View File

@ -0,0 +1,15 @@
Move disk from pole 1 to pole 3
Move disk from pole 1 to pole 2
Move disk from pole 3 to pole 2
Move disk from pole 1 to pole 3
Move disk from pole 2 to pole 1
Move disk from pole 2 to pole 3
Move disk from pole 1 to pole 3
Move disk from pole 1 to pole 2
Move disk from pole 3 to pole 2
Move disk from pole 3 to pole 1
Move disk from pole 2 to pole 1
Move disk from pole 3 to pole 2
Move disk from pole 1 to pole 3
Move disk from pole 1 to pole 2
Move disk from pole 3 to pole 2