-
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.
- Loading branch information
Showing
15 changed files
with
440 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,30 @@ | ||
version: 2 | ||
jobs: | ||
build: | ||
docker: | ||
- image: debian:stretch | ||
|
||
steps: | ||
- run: | ||
name: APT dependencies | ||
command: apt-get update && apt-get install -y libgmp-dev curl build-essential netbase git | ||
|
||
- run: | ||
name: Install Stack | ||
command: | | ||
mkdir -p ~/.local/bin | ||
curl -L https://www.stackage.org/stack/linux-x86_64 | tar xz --wildcards --strip-components=1 -C ~/.local/bin '*/stack' | ||
- checkout | ||
|
||
- run: | ||
name: Setup project dependencies | ||
command: | | ||
export PATH=$HOME/.local/bin:$PATH | ||
stack --no-terminal --install-ghc test --only-dependencies | ||
- run: | ||
name: Project tests | ||
command: | | ||
export PATH=$HOME/.local/bin:$PATH | ||
stack --no-terminal test --haddock --no-haddock-deps |
Empty file.
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,39 @@ | ||
on: [push] | ||
name: build | ||
jobs: | ||
runhaskell: | ||
name: Run Haskell | ||
runs-on: ubuntu-latest # or macOS-latest, or windows-latest | ||
steps: | ||
# things to be cached/restored: | ||
- name: Cache stack global package db | ||
id: stack-global | ||
uses: actions/cache@v2 | ||
with: | ||
path: ~/.stack | ||
key: $-stack-global-$-$ | ||
restore-keys: | | ||
$-stack-global-$ | ||
- name: Cache stack-installed programs in ~/.local/bin | ||
id: stack-programs | ||
uses: actions/cache@v2 | ||
with: | ||
path: ~/.local/bin | ||
key: $-stack-programs-$-$ | ||
restore-keys: | | ||
$-stack-programs-$ | ||
- name: Cache .stack-work | ||
uses: actions/cache@v2 | ||
with: | ||
path: .stack-work | ||
key: $-stack-work-$-$ | ||
restore-keys: | | ||
$-stack-work-$ | ||
# end cache configuration | ||
- uses: actions/checkout@v2 | ||
- uses: haskell/actions/setup@v1 | ||
with: | ||
# cabal-version: 'latest'. Omitted, but defalts to 'latest' | ||
enable-stack: true | ||
stack-version: 'latest' | ||
- run: stack test |
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,4 @@ | ||
.stack-work/ | ||
*.cabal | ||
*~ | ||
.history |
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,3 @@ | ||
# Changelog for proyecto-base | ||
|
||
## Unreleased changes |
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,30 @@ | ||
Copyright Author name here (c) 2019 | ||
|
||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
|
||
* Redistributions in binary form must reproduce the above | ||
copyright notice, this list of conditions and the following | ||
disclaimer in the documentation and/or other materials provided | ||
with the distribution. | ||
|
||
* Neither the name of Author name here nor the names of other | ||
contributors may be used to endorse or promote products derived | ||
from this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
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,3 @@ | ||
# Jueves Mañana - Parcial Funcional | ||
|
||
Nombre y apellido: Iñaki, ARISTIA |
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,2 @@ | ||
import Distribution.Simple | ||
main = defaultMain |
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,7 @@ | ||
cradle: | ||
stack: | ||
- path: "./src" | ||
component: "proyecto-base:lib" | ||
|
||
- path: "./test" | ||
component: "proyecto-base:test:proyecto-base-test" |
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,46 @@ | ||
name: proyecto-base | ||
version: 0.1.0.0 | ||
github: "githubuser/proyecto-base" | ||
license: BSD3 | ||
author: "Author name here" | ||
maintainer: "[email protected]" | ||
copyright: "2019 Author name here" | ||
|
||
extra-source-files: | ||
- README.md | ||
- ChangeLog.md | ||
|
||
# Metadata used when publishing your package | ||
# synopsis: Short description of your package | ||
# category: Web | ||
|
||
# To avoid duplicated efforts in documentation and dealing with the | ||
# complications of embedding Haddock markup inside cabal files, it is | ||
# common to point users to the README.md file. | ||
description: Please see the README on GitHub at <https://github.com/githubuser/proyecto-base#readme> | ||
|
||
dependencies: | ||
- base >= 4.7 && < 5 | ||
- pdeprelude | ||
- hspec | ||
|
||
default-extensions: | ||
- NoImplicitPrelude | ||
- FlexibleContexts | ||
- RebindableSyntax | ||
|
||
library: | ||
source-dirs: src | ||
other-modules: [] | ||
|
||
tests: | ||
proyecto-base-test: | ||
main: CorrerTests.hs | ||
source-dirs: test | ||
ghc-options: | ||
- -threaded | ||
- -rtsopts | ||
- -with-rtsopts=-N | ||
dependencies: | ||
- proyecto-base | ||
|
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,161 @@ | ||
module Library where | ||
import PdePreludat | ||
|
||
doble :: Number -> Number | ||
doble numero = numero + numero | ||
|
||
-- 1 | ||
|
||
data Nave = UnaNave { | ||
|
||
nombre :: String, | ||
|
||
durabilidad :: Number, | ||
|
||
escudo :: Number, | ||
|
||
ataque :: Number, | ||
|
||
nombrepoder :: String, -- decidí agregar el nombre del poder al data de Nave como un String para poder leer qué poder tiene cada Nave por consola, | ||
-- ya que poder, por si solo, se muestra como <una función> en consola (y tiene sentido porque lo definí como Nave -> Nave). | ||
|
||
poder :: Poder | ||
|
||
|
||
} deriving Show | ||
|
||
type Poder = Nave -> Nave | ||
|
||
type Flota = [Nave] | ||
|
||
tiefighter :: Nave | ||
tiefighter = UnaNave {nombre = "Tie Fighter", durabilidad = 200, escudo = 100, ataque = 50, nombrepoder = "Turbo", poder = turbo} | ||
|
||
xwing :: Nave | ||
xwing = UnaNave {nombre = "X Wing", durabilidad = 300, escudo = 150, ataque = 100, nombrepoder = "Reparacion de emergencia", poder = reparacionEmergencia} | ||
|
||
naveDarthVader :: Nave | ||
naveDarthVader = UnaNave {nombre = "Nave de Darth Vader", durabilidad = 500, escudo = 300, ataque = 200, nombrepoder = "Super turbo", poder = superTurbo} | ||
|
||
milleniumFalcon :: Nave | ||
milleniumFalcon = UnaNave {nombre = "Millennium Falcon", durabilidad = 1000, escudo = 500, ataque = 50, nombrepoder = "Poder Milenario", poder = poderMilenario} | ||
|
||
naveInia :: Nave | ||
naveInia = UnaNave {nombre = "Nave Inia", durabilidad = 1000, escudo = 500, ataque = 500, nombrepoder = "Super turboreparacion", poder = superTurboreparacion} -- dos turbos e incrementar escudos en 100 | ||
|
||
turbo :: Poder | ||
turbo nave = incrementarAtaque 25 nave | ||
|
||
reparacionEmergencia :: Poder | ||
reparacionEmergencia nave = (incrementarDurabilidad 50 . reducirAtaque 30) nave | ||
|
||
superTurbo :: Poder | ||
superTurbo nave = ((repetir 3 [turbo]) . (reducirDurabilidadEn 45)) nave | ||
|
||
poderMilenario :: Poder | ||
poderMilenario nave = (reparacionEmergencia . incrementarEscudos 100) nave | ||
|
||
superTurboreparacion :: Poder | ||
superTurboreparacion nave = ((repetir 2 [turbo]) . (incrementarEscudos 100)) nave | ||
|
||
incrementarAtaque :: Number -> Nave -> Nave | ||
incrementarAtaque cantidad nave = UnaNave {nombre = nombre nave, durabilidad = durabilidad nave, escudo = escudo nave, ataque = ataque nave + cantidad, nombrepoder = nombrepoder nave, poder = poder nave} | ||
|
||
incrementarDurabilidad :: Number -> Nave -> Nave | ||
incrementarDurabilidad cantidad nave = UnaNave {nombre = nombre nave, durabilidad = durabilidad nave + cantidad, escudo = escudo nave, ataque = ataque nave, nombrepoder = nombrepoder nave, poder = poder nave} | ||
|
||
reducirAtaque :: Number -> Nave -> Nave | ||
reducirAtaque cantidad nave = UnaNave {nombre = nombre nave, durabilidad = durabilidad nave, escudo = escudo nave, ataque = ataque nave - cantidad, nombrepoder = nombrepoder nave, poder = poder nave} | ||
|
||
incrementarEscudos :: Number -> Nave -> Nave | ||
incrementarEscudos cantidad nave = UnaNave {nombre = nombre nave, durabilidad = durabilidad nave, escudo = escudo nave + cantidad, ataque = ataque nave, nombrepoder = nombrepoder nave, poder = poder nave} | ||
|
||
reducirDurabilidadEn :: Number -> Nave -> Nave | ||
reducirDurabilidadEn cantidad nave = UnaNave {nombre = nombre nave, durabilidad = (durabilidad nave - cantidad) `min` 0, escudo = escudo nave, ataque = ataque nave, nombrepoder = nombrepoder nave, poder = poder nave} | ||
|
||
repetir :: Number -> [Poder] -> Poder | ||
repetir 0 [_] = id | ||
repetir cantidad poderes = repetir (cantidad - 1) poderes | ||
|
||
-- 2 | ||
|
||
durabilidadTotal :: Flota -> Number | ||
durabilidadTotal [] = 0 | ||
durabilidadTotal flota = sum (map sacarDurabilidad flota) | ||
|
||
sacarDurabilidad :: Nave -> Number | ||
sacarDurabilidad = durabilidad | ||
|
||
-- 3 | ||
|
||
naveLuegoDeAtaque :: Nave -> Nave -> Nave | ||
naveLuegoDeAtaque naveatacada navequeataca | ||
| laAfectaElAtaque naveatacada navequeataca = reducirDurabilidadEn (ataque (activarPoderEspecial navequeataca)) (activarPoderEspecial naveatacada) | ||
| otherwise = naveatacada | ||
|
||
laAfectaElAtaque :: Nave -> Nave -> Bool | ||
laAfectaElAtaque naveatacada navequeataca = escudo (activarPoderEspecial naveatacada) < ataque (activarPoderEspecial navequeataca) | ||
|
||
activarPoderEspecial :: Nave -> Nave | ||
activarPoderEspecial nave = (poder nave) nave | ||
|
||
-- 4 | ||
|
||
estaFueraDeCombate :: Nave -> Bool | ||
estaFueraDeCombate nave = durabilidad nave == 0 | ||
|
||
-- 5 | ||
|
||
type Estrategia = Nave -> Bool | ||
|
||
flotaLuegodeAtaque :: Nave -> Flota -> Flota | ||
flotaLuegodeAtaque nave flota = map (naveLuegoDeAtaque nave) flota | ||
|
||
flotaLuegodeMision :: Nave -> Flota -> Estrategia -> Flota | ||
flotaLuegodeMision nave flota estrategia = map (atacarSiCumple estrategia nave) flota | ||
|
||
atacarSiCumple :: Estrategia -> Nave -> Nave -> Nave | ||
atacarSiCumple estrategia navequeataca naveatacada | ||
| estrategia naveatacada = naveLuegoDeAtaque navequeataca naveatacada | ||
| otherwise = naveatacada | ||
|
||
esDebil :: Estrategia | ||
esDebil nave = escudo nave < 200 | ||
|
||
tieneCiertaPeligrosidad :: Nave -> Number -> Bool | ||
tieneCiertaPeligrosidad nave peligrosidad = ataque nave > peligrosidad | ||
|
||
fueraDeCombate :: Estrategia | ||
fueraDeCombate nave = estaFueraDeCombate nave | ||
|
||
dura :: Estrategia -- nueva estrategia, la ataco si la durabilidad es mayor a 200 y si el escudo es mayor a 200. | ||
dura nave = (durabilidad nave > 200) && (escudo nave > 200) | ||
|
||
|
||
-- 6 | ||
|
||
flotaLuegodeMisionConEstrategiaMasApta :: Nave -> Flota -> Estrategia -> Estrategia -> Flota | ||
flotaLuegodeMisionConEstrategiaMasApta nave flota estrategia1 estrategia2 = flotaLuegodeMision nave flota (estrategiaMasApta nave flota estrategia1 estrategia2) | ||
|
||
estrategiaMasApta :: Nave -> Flota -> Estrategia -> Estrategia -> Estrategia | ||
estrategiaMasApta nave flota estrategia1 estrategia2 | ||
| durabilidadTotal (flotaLuegodeMision nave flota estrategia1) > durabilidadTotal (flotaLuegodeMision nave flota estrategia2) = estrategia2 | ||
| otherwise = estrategia1 | ||
|
||
|
||
-- 7. Construir una flota infinita de naves. | ||
|
||
flotaInfinita :: Flota | ||
flotaInfinita = repeat naveInia | ||
|
||
-- ¿Es posible determinar su durabilidad total? | ||
|
||
-- No, no es posible, el map de durabilidadTotal se queda "colgado" recorriendo los elementos de la lista, que es infinita, | ||
-- por lo tanto el sum de durabilidadTotal tiene que sumar una cantidad infinitas de elementos, lo cuale es imposible | ||
|
||
|
||
-- ¿Qué se obtiene como respuesta cuando se lleva adelante una misión sobre ella? | ||
|
||
-- Para llevar a cabo una misión sobre una flota, necesitamos evaluar si la nave atacante va a atacar o no a cada una de las naves de la flota; | ||
-- en el caso de la flota infinita, esta evaluación no tiene fin, ya que estamos pidiendo al programa que evalúe si va a atacar o no a una cantidad | ||
-- infinita de elementos. No devuelve nada, se queda nuevamente "colgado", evualuando infinitamente. |
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,11 @@ | ||
module Spec where | ||
import PdePreludat | ||
import Library | ||
import Test.Hspec | ||
|
||
correrTests :: IO () | ||
correrTests = hspec $ do | ||
describe "Test de ejemplo" $ do | ||
it "El pdepreludat se instaló correctamente" $ do | ||
doble 1 `shouldBe` 2 | ||
|
Oops, something went wrong.