Skip to content

Commit

Permalink
updating tests
Browse files Browse the repository at this point in the history
  • Loading branch information
travgm committed Nov 14, 2024
1 parent fd55805 commit d61b94e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
4 changes: 2 additions & 2 deletions test/DecimalTimeSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ instance Arbitrary ZonedTime where

makeTestState :: TimeOfDay -> ClockState
makeTestState tod =
ClockState False Nothing (Just $ LocalTime (fromGregorian 2024 1 1) tod)
ClockState False Nothing (Just $ LocalTime (fromGregorian 2024 1 1) tod) Nothing

spec :: Spec
spec = do
Expand All @@ -55,7 +55,7 @@ spec = do
Left err -> expectationFailure $ "Expected Right but got Left: " ++ err

it "fails when currentDate is Nothing" $ do
let state = ClockState False Nothing Nothing
let state = ClockState False Nothing Nothing Nothing
case localTimeToDecimal state of
Left _ -> return ()
Right _ -> expectationFailure "Expected Left but got Right"
Expand Down
33 changes: 21 additions & 12 deletions test/PrettyPrinterSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ instance Arbitrary ClockState where
ext <- arbitrary
dtime <- arbitrary
date <- arbitrary
return $ ClockState ext dtime date
return $ ClockState ext dtime date Nothing

instance Arbitrary ValidDecimalTime where
arbitrary = ValidDecimalTime . DecimalTime <$> choose (0, 1000)
Expand All @@ -36,7 +36,7 @@ instance Arbitrary LocalTime where

makeClockState :: Bool -> Maybe LocalTime -> Maybe ValidDecimalTime -> ClockState
makeClockState ext date dtime =
ClockState ext dtime date
ClockState ext dtime date Nothing

makeValidTime :: Integer -> ValidDecimalTime
makeValidTime = ValidDecimalTime . DecimalTime
Expand All @@ -58,21 +58,30 @@ spec = do

describe "formatTime" $ do
it "formats error message" $ do
Pretty.formatTime (Left "test error") `shouldBe` "Decimal time: test error"
Pretty.formatTime (Error "test error") (Left "test error")
`shouldBe` "Decimal time: test error"

it "formats normal time without extended info" $ do
let state = makeClockState False Nothing (Just $ makeValidTime 500)
Pretty.formatTime (Right state) `shouldBe` "Decimal time: 500"
let state = makeClockState False Nothing (Just $ makeValidTime 500)
Pretty.formatTime Normal (Right state)
`shouldBe` "Decimal time: 500"

it "formats time with date when extended" $ do
let date = LocalTime (fromGregorian 2024 1 1) midnight
state = makeClockState True (Just date) (Just $ makeValidTime 500)
Pretty.formatTime (Right state) `shouldBe` "Decimal time: 500 (2024-01-01)"
let date = LocalTime (fromGregorian 2024 1 1) midnight
state = makeClockState True (Just date) (Just $ makeValidTime 500)
Pretty.formatTime Normal (Right state)
`shouldBe` "Decimal time: 500 (2024-01-01)"

it "formats NEW with date when extended" $ do
let date = LocalTime (fromGregorian 2024 1 1) midnight
state = makeClockState True (Just date) (Just $ makeValidTime 0)
Pretty.formatTime (Right state) `shouldBe` "Decimal time: NEW (2024-01-01)"
let date = LocalTime (fromGregorian 2024 1 1) midnight
state = makeClockState True (Just date) (Just $ makeValidTime 0)
Pretty.formatTime Normal (Right state)
`shouldBe` "Decimal time: NEW (2024-01-01)"

it "shows alarm when reached" $ do
let state = makeClockState False Nothing (Just $ makeValidTime 500)
Pretty.formatTime (AlarmReached (DecimalTime 500)) (Right state)
`shouldBe` "Decimal time: 500 ALARM!"

it "always starts with 'Decimal time: '" $ property $ \state ->
T.isPrefixOf "Decimal time: " (Pretty.formatTime $ Right state)
T.isPrefixOf "Decimal time: " (Pretty.formatTime Normal $ Right state)

0 comments on commit d61b94e

Please sign in to comment.