Skip to content

Commit

Permalink
initial ci and view test cases commit
Browse files Browse the repository at this point in the history
  • Loading branch information
flober committed Jul 1, 2024
1 parent 31cdcf4 commit a8191f8
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 12 deletions.
40 changes: 40 additions & 0 deletions .github/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Haskell CI

on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Stack
uses: actions/setup-haskell@v1
with:
stack-version: '2.15.5'
ghc-version: '9.6.5'

- name: Cache Stack dependencies
uses: actions/cache@v2
with:
path: |
~/.stack
.stack-work
# Cache invalidated if package.yaml changes.
key: ${{ runner.os }}-stack-${{ hashFiles('package.yaml') }}

- name: Install dependencies
run: stack setup

- name: Build
run: stack build --fast

- name: Run tests
run: stack test
17 changes: 11 additions & 6 deletions battlegrounds.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ cabal-version: 2.2
name: battlegrounds
version: 0.1.0.0
description: Please see the README on GitHub at <https://github.com/githubuser/battlegrounds#readme>
homepage: https://github.com/githubuser/battlegrounds#readme
bug-reports: https://github.com/githubuser/battlegrounds/issues
author: Author name here
maintainer: example@example.com
copyright: 2024 Author name here
homepage: https://github.com/blastwind/battlegrounds#readme
bug-reports: https://github.com/blastwind/battlegrounds/issues
author: Andrew Chen
maintainer: andrewchen14250@gmail.com
copyright: 2024 Andrew Chen
license: BSD-3-Clause
license-file: LICENSE
build-type: Simple
Expand All @@ -21,7 +21,7 @@ extra-source-files:

source-repository head
type: git
location: https://github.com/githubuser/battlegrounds
location: https://github.com/blastwind/battlegrounds

library
exposed-modules:
Expand Down Expand Up @@ -80,6 +80,7 @@ test-suite battlegrounds-test
type: exitcode-stdio-1.0
main-is: Spec.hs
other-modules:
Terminal.View
Paths_battlegrounds
autogen-modules:
Paths_battlegrounds
Expand All @@ -89,4 +90,8 @@ test-suite battlegrounds-test
build-depends:
base >=4.7 && <5
, battlegrounds
, containers ==0.6.7
, tasty
, tasty-hunit
, uuid ==1.3.15
default-language: Haskell2010
12 changes: 8 additions & 4 deletions package.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: battlegrounds
version: 0.1.0.0
github: "githubuser/battlegrounds"
github: "blastwind/battlegrounds"
license: BSD-3-Clause
author: "Author name here"
maintainer: "example@example.com"
copyright: "2024 Author name here"
author: "Andrew Chen"
maintainer: "andrewchen14250@gmail.com"
copyright: "2024 Andrew Chen"

extra-source-files:
- README.md
Expand Down Expand Up @@ -73,4 +73,8 @@ tests:
- -rtsopts
- -with-rtsopts=-N
dependencies:
- containers == 0.6.7
- uuid == 1.3.15
- battlegrounds
- tasty
- tasty-hunit
2 changes: 1 addition & 1 deletion src/Model.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type TavernTier = Int

type CardCost = Int

data CardName = Dummy | Dumber | TriDummy | Dumbo | BigDumbo | KingDumbo deriving Show
data CardName = Dummy | Dumber | TriDummy | Dumbo | BigDumbo | KingDumbo | DummyWithALongNameItKeepsGoing deriving Show

data Card = Card
{ _cardName :: CardName,
Expand Down
5 changes: 4 additions & 1 deletion test/Spec.hs
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
import Terminal.View (viewTestGroup)
import Test.Tasty (defaultMain, testGroup)

main :: IO ()
main = putStrLn "Test suite not yet implemented"
main = defaultMain $ testGroup "Unit Tests" [viewTestGroup]
136 changes: 136 additions & 0 deletions test/Terminal/View.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
-- View tests are regressive (ensure that new changes do not inadvertently regress the existing UI).
module Terminal.View (viewTestGroup) where

import Card
import Data.List (intercalate)
import Data.Map (empty, fromList)
import Data.Maybe (fromJust)
import Data.UUID (UUID, fromString)
import Model (CardInstance (..), OppInfo (..), Phase (..), PlayerState (..))
import Test.Tasty (TestTree, testGroup)
import Test.Tasty.HUnit (assertEqual, testCase)
import View.Terminal (render)

viewTestGroup :: TestTree
viewTestGroup =
testGroup
"View Tests"
[ testBlankRecruitView,
testRecruitViewWithMaxItems,
testRecruitViewWithAbbrevs
]

testBlankRecruitView :: TestTree
testBlankRecruitView =
testCase "Test view of blank shop, board, hand. Other hard coded stats can test stat renderings." $
assertEqual "view should be eq" (render blankPlayerState) $
intercalate
"\n"
[ "+--------------------------------------------------------------------------------------------------------------------------------------------+",
"| Recruit |",
"+--------------------------------------------------------------------------------------------------------------------------------------------+",
"| Shop: |",
"+--------------------------------------------------------------------------------------------------------------------------------------------+",
"| Board: |",
"+--------------------------------------------------------------------------------------------------------------------------------------------+",
"| Hand: |",
"+--------------------------------------------------------------------------------------------------------------------------------------------+",
"| Tavern: Upgrade Cost: 5 | Freeze: Yes | Reroll Cost: 2 |",
"+--------------------------------------------------------------------------------------------------------------------------------------------+",
"| Player: Health: 30 | Armor: 5 | Gold: 7/10 |",
"+--------------------------------------------------------------------------------------------------------------------------------------------+",
"| Opps HP: |",
"+--------------------------------------------------------------------------------------------------------------------------------------------+"
]

testRecruitViewWithMaxItems :: TestTree
testRecruitViewWithMaxItems =
testCase "Test view of filled shop, board, hand and max opps." $
assertEqual "view should be eq" (render maxItemsPlayerState) $
intercalate
"\n"
[ "+--------------------------------------------------------------------------------------------------------------------------------------------+",
"| Recruit |",
"+--------------------------------------------------------------------------------------------------------------------------------------------+",
"| Shop: Dummy | Dumber | TriDummy | Dumbo | BigDumbo | KingDumbo |",
"+--------------------------------------------------------------------------------------------------------------------------------------------+",
"| Board: Dummy | Dumber | TriDummy | Dumbo | BigDumbo | KingDumbo |",
"+--------------------------------------------------------------------------------------------------------------------------------------------+",
"| Hand: Dummy | Dumber | TriDummy | Dumbo | BigDumbo | KingDumbo | KingDumbo |",
"| KingDumbo | KingDumbo | KingDumbo |",
"+--------------------------------------------------------------------------------------------------------------------------------------------+",
"| Tavern: Upgrade Cost: 5 | Freeze: Yes | Reroll Cost: 2 |",
"+--------------------------------------------------------------------------------------------------------------------------------------------+",
"| Player: Health: 30 | Armor: 5 | Gold: 7/10 |",
"+--------------------------------------------------------------------------------------------------------------------------------------------+",
"| Opps HP: opp1: 30 + 5 | opp2: 30 + 5 | opp3: 30 + 5 | opp4: 30 + 5 |",
"| opp5: 30 + 5 | opp6: 30 + 5 | opp7: 30 + 5 |",
"+--------------------------------------------------------------------------------------------------------------------------------------------+"
]

testRecruitViewWithAbbrevs :: TestTree
testRecruitViewWithAbbrevs =
testCase "Test view of filled shop, board, hand and max opps. All names chosen to exceed limit (and hence should be abbreviated)." $
assertEqual "view should be eq" (render maxItemsWithAbbrevNamesPlayerState) $
intercalate
"\n"
[ "+--------------------------------------------------------------------------------------------------------------------------------------------+",
"| Recruit |",
"+--------------------------------------------------------------------------------------------------------------------------------------------+",
"| Shop: DummyWithALon.. | DummyWithALon.. | DummyWithALon.. | DummyWithALon.. | DummyWithALon.. | DummyWithALon.. | DummyWithALon.. |",
"+--------------------------------------------------------------------------------------------------------------------------------------------+",
"| Board: DummyWithALon.. | DummyWithALon.. | DummyWithALon.. | DummyWithALon.. | DummyWithALon.. | DummyWithALon.. | DummyWithALon.. |",
"+--------------------------------------------------------------------------------------------------------------------------------------------+",
"| Hand: DummyWithALon.. | DummyWithALon.. | DummyWithALon.. | DummyWithALon.. | DummyWithALon.. | DummyWithALon.. | DummyWithALon.. |",
"| DummyWithALon.. | DummyWithALon.. | DummyWithALon.. |",
"+--------------------------------------------------------------------------------------------------------------------------------------------+",
"| Tavern: Upgrade Cost: 5 | Freeze: Yes | Reroll Cost: 2 |",
"+--------------------------------------------------------------------------------------------------------------------------------------------+",
"| Player: Health: 30 | Armor: 5 | Gold: 7/10 |",
"+--------------------------------------------------------------------------------------------------------------------------------------------+",
"| Opps HP: aVeryLongName..: 15 + 15 | aVeryLongName..: 15 + 15 | aVeryLongName..: 15 + 15 | aVeryLongName..: 15 + 15 |",
"| aVeryLongName..: 15 + 15 | aVeryLongName..: 15 + 15 | aVeryLongName..: 15 + 15 |",
"+--------------------------------------------------------------------------------------------------------------------------------------------+"
]

dummyUUID :: UUID
dummyUUID = fromJust $ fromString "c2cc10e1-57d6-4b6f-9899-38d972112d8c"

blankPlayerState :: PlayerState
blankPlayerState =
PlayerState
{ shop = [],
board = [],
hand = [],
frozen = True,
rerollCost = 2,
tierUpCost = 5,
hp = 30,
armor = 5,
curGold = 7,
maxGold = 10,
opponentInformation = empty,
tier = 5,
phase = Recruit,
alive = True
}

maxItemsPlayerState :: PlayerState
maxItemsPlayerState =
blankPlayerState
{ shop = [CardInstance dummyUUID dummy, CardInstance dummyUUID dumber, CardInstance dummyUUID triDummy, CardInstance dummyUUID dumbo, CardInstance dummyUUID bigDumbo, CardInstance dummyUUID kingDumbo],
board = [CardInstance dummyUUID dummy, CardInstance dummyUUID dumber, CardInstance dummyUUID triDummy, CardInstance dummyUUID dumbo, CardInstance dummyUUID bigDumbo, CardInstance dummyUUID kingDumbo],
hand = [CardInstance dummyUUID dummy, CardInstance dummyUUID dumber, CardInstance dummyUUID triDummy, CardInstance dummyUUID dumbo, CardInstance dummyUUID bigDumbo, CardInstance dummyUUID kingDumbo, CardInstance dummyUUID kingDumbo, CardInstance dummyUUID kingDumbo, CardInstance dummyUUID kingDumbo, CardInstance dummyUUID kingDumbo],
opponentInformation = fromList [("opp1", OppInfo 30 5), ("opp2", OppInfo 30 5), ("opp3", OppInfo 30 5), ("opp4", OppInfo 30 5), ("opp5", OppInfo 30 5), ("opp6", OppInfo 30 5), ("opp7", OppInfo 30 5)]
}

maxItemsWithAbbrevNamesPlayerState :: PlayerState
maxItemsWithAbbrevNamesPlayerState =
blankPlayerState
{ shop = replicate 7 $ CardInstance dummyUUID dummyWithALongNameItKeepsGoing,
board = replicate 7 $ CardInstance dummyUUID dummyWithALongNameItKeepsGoing,
hand = replicate 10 $ CardInstance dummyUUID dummyWithALongNameItKeepsGoing,
opponentInformation = fromList $ [(longOppName ++ show i, OppInfo 15 15) | i <- [1 :: Integer .. 7]]
}
where
longOppName = "aVeryLongNameBlahBlah"

0 comments on commit a8191f8

Please sign in to comment.