tamerlib/tests/ExampleClass.php

46 lines
1.1 KiB
PHP
Raw Permalink Normal View History

2023-06-16 03:38:51 -04:00
<?php
class ExampleClass
{
/**
* Sleeps for the given number of seconds, plus a random number of seconds between 0 and 100.
2023-06-16 03:38:51 -04:00
*
* @param int $seconds
* @return int
* @throws Exception
2023-06-16 03:38:51 -04:00
*/
public function sleep(int $seconds=1): int
2023-06-16 03:38:51 -04:00
{
sleep($seconds);
return random_int(0, 100) + $seconds;
2023-06-16 03:38:51 -04:00
}
/**
* Calculates pi using the Leibniz formula.
2023-06-16 03:38:51 -04:00
*
* @param int $iterations
* @return float
2023-06-16 03:38:51 -04:00
*/
public function pi(int $iterations): float
2023-06-16 03:38:51 -04:00
{
$pi = 0;
$sign = 1;
for ($i = 0; $i < $iterations; $i++)
{
$pi += $sign / (2 * $i + 1);
$sign *= -1;
}
return $pi * 4;
2023-06-16 03:38:51 -04:00
}
/**
* Throws an exception.
2023-06-16 03:38:51 -04:00
*
* @return void
* @throws Exception
2023-06-16 03:38:51 -04:00
*/
public function throwException(): void
2023-06-16 03:38:51 -04:00
{
throw new Exception('This is an exception.');
2023-06-16 03:38:51 -04:00
}
}