PageRenderTime 19ms CodeModel.GetById 13ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/tutorial/fibonacci.e

http://github.com/tybor/Liberty
Specman e | 39 lines | 34 code | 5 blank | 0 comment | 3 complexity | 353392e800322ad6f334123e64355568 MD5 | raw file
 1class FIBONACCI
 2
 3insert
 4   ARGUMENTS
 5
 6create {ANY}
 7   make
 8
 9feature {ANY}
10   make
11      local
12         arg: STRING
13      do
14         if argument_count = 0 then
15            std_input.read_line
16            arg := std_input.last_string
17         elseif argument_count = 1 then
18            arg := argument(1)
19         end
20         if not arg.is_integer then
21            std_error.put_line("Expecting an integer")
22            die_with_code(exit_failure_code)
23         end
24         io.put_integer(fibonacci(arg.to_integer))
25         io.put_new_line
26      end
27
28   fibonacci (i: INTEGER): INTEGER
29      require
30         i >= 0
31      do
32         if i < 2 then
33            Result := i
34         else
35            Result := fibonacci(i - 2) + fibonacci(i - 1)
36         end
37      end
38
39end -- class FIBONACCI