Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class NotAllArgumentsException extends Exception { }
- class NaNException extends Exception { }
- class NegativeNumberException extends Exception { }
- class NaTException extends Exception { }
- class Triangle {
- public function name_is($l1 = null, $l2 = null, $l3 = null){
- try{
- if(!$l1 || !$l2 || !$l3)
- throw new NotAllArgumentsException('Not All Arguments Exception');
- $arr = array($l1,$l2, $l3);
- foreach($arr as $n)
- if(!is_int($n))
- throw new NaNException('NaN Exception');
- else if($n < 0)
- throw new NegativeNumberException('Negative Number Exception');
- sort($arr);
- if($arr[0]+$arr[1] <= $arr[2])
- throw new NaTException('NaT Exception');
- if($arr[0]==$arr[1] && $arr[1]==$arr[2])
- return "Equilatero";
- else if(($arr[0]==$arr[1] && $arr[1]!=$arr[2])||($arr[0]!=$arr[1] && $arr[1]==$arr[2]))
- return "Isosceles";
- else return "Escaleno";
- }catch(Exception $e){
- return $e->getMessage();
- }
- }
- }
- class TriangleTest extends PHPUnit_Framework_TestCase{
- public function SetUp(){
- $this->t = new Triangle();
- }
- public function test_it(){
- $myfile = fopen("stdin.txt", "r") or die("Unable to open test file");
- while(!feof($myfile)) {
- $test = trim(fgets($myfile));
- $res = fgets($myfile);
- str_replace(" ", ",", $test);
- eval("\$this->assertEquals(\"$res\", $this->t->name_is($test));");
- }
- fclose($myfile);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement