-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: se agrega la interfaz del servicio(IFibonacciServicios), el ser…
…vicio(FibonacciServicios), el controller(FibonacciController). Esto permite calcular la serie de Fibonacci, de un numero perteneciente al conjunto de los Naturales entre 0 y 90. Issues: #4, #5 y #12
- Loading branch information
Romina Fernandez
committed
Dec 2, 2019
1 parent
3ed69c4
commit c54d87f
Showing
3 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using FibonacciWebApi.Servicios; | ||
|
||
namespace FibonacciWebApi.Controllers | ||
{ | ||
[Route("api/[controller]")] | ||
[ApiController] | ||
public class FibonacciController : ControllerBase | ||
{ | ||
[HttpGet] | ||
public ActionResult<string> Get() | ||
{ | ||
return "Debe ingresar un numero para realizar Fibonacci"; | ||
} | ||
|
||
[HttpGet("{numero}")] | ||
public ActionResult<string> Get(int numero) | ||
{ | ||
IFibonacciServicios f = new FibonacciServicios(); | ||
if (numero < 0 || numero > 90) | ||
{ | ||
return "Debe ingresar un numero perteneciente al conjunto de los Naturales entre 0 y 90"; | ||
} | ||
else | ||
{ | ||
return f.CalcularFibonacci(numero).ToString(); | ||
} | ||
//return RealizarFibonacci(fibo); | ||
} | ||
|
||
//private int RealizarFibonacci(int fibo) | ||
//{ | ||
// if (fibo == 0) | ||
// { | ||
// return 0; | ||
// } | ||
// else if (fibo == 1) | ||
// { | ||
// return 1; | ||
// } | ||
// else | ||
// { | ||
// return RealizarFibonacci(fibo - 1) + RealizarFibonacci(fibo - 2); | ||
// } | ||
//} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
|
||
namespace FibonacciWebApi.Servicios | ||
{ | ||
public class FibonacciServicios : IFibonacciServicios | ||
{ | ||
public int CalcularFibonacci(int i) | ||
{ | ||
return RealizarFibonacci(i); | ||
} | ||
|
||
public int RealizarFibonacci(int fibo) | ||
{ if (fibo == 0) | ||
{ | ||
return 0; | ||
} | ||
else if (fibo == 1) | ||
{ | ||
return 1; | ||
} | ||
else | ||
{ | ||
return RealizarFibonacci(fibo - 1) + RealizarFibonacci(fibo - 2); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace FibonacciWebApi.Servicios | ||
{ | ||
public interface IFibonacciServicios | ||
{ | ||
int CalcularFibonacci(int i); | ||
} | ||
} |