pr3-elm/aufgaben/tests/DateTests.elm

164 lines
5.0 KiB
Elm
Raw Permalink Normal View History

2022-12-12 19:08:10 +01:00
module DateTests exposing (..)
import Expect exposing (Expectation)
import Fuzz exposing (Fuzzer, int, list, string)
import Test exposing (..)
2022-12-12 19:08:10 +01:00
import Date exposing (..)
testYear : Test
testYear =
describe "year method test"
[ test "year of 1.1.2018" <|
\() ->
Expect.equal 2018 (year (1, 1, 2018))
, test "year of 1.1.2019" <|
\() ->
Expect.equal 2019 (year (7, 4, 2019))
, test "year of 1.1.2020" <|
\() ->
Expect.equal 2020 (year (1, 1, 2020))
, test "year of 01.01.1970" <|
\() ->
Expect.equal 1970 (year (1, 1, 1970))
, test "year of 02.06.2024 " <|
\() ->
Expect.equal 2024 (year (2, 6, 2024))
]
testMonth : Test
testMonth =
describe "month method test"
[ test "month of 1.8.2018" <|
\() ->
Expect.equal 8 (month (1, 8, 2018))
, test "month of 1.1.2019" <|
\() ->
Expect.equal 4 (month (7, 4, 2019))
, test "month of 1.12.2020" <|
\() ->
Expect.equal 12 (month (1, 12, 2020))
, test "month of 01.01.1970" <|
\() ->
Expect.equal 1 (month (1, 1, 1970))
, test "month of 02.06.2024 " <|
\() ->
Expect.equal 6 (month (2, 6, 2024))
]
testDay : Test
testDay =
describe "day method test"
[ test "day of 5.8.2018" <|
\() ->
Expect.equal 5 (day (5, 8, 2018))
, test "day of 8.1.2019" <|
\() ->
Expect.equal 8 (day (8, 4, 2019))
, test "day of 1.12.2020" <|
\() ->
Expect.equal 20 (day (20, 12, 2020))
, test "day of 01.01.1970" <|
\() ->
Expect.equal 1 (day (1, 1, 1970))
, test "day of 02.06.2024 " <|
\() ->
Expect.equal 2 (day (2, 6, 2024))
]
-- DD.MM.YYYY, months/days < 10 have a leading 0
testToString : Test
testToString =
describe "toString method test"
[ test "toString of 05.8.2018" <|
\() ->
Expect.equal "05.08.2018" (toString (5, 8, 2018))
, test "toString of 08.1.2019" <|
\() ->
Expect.equal "08.04.2019" (toString (8, 4, 2019))
, test "toString of 20.12.2020" <|
\() ->
Expect.equal "20.12.2020" (toString (20, 12, 2020))
, test "toString of 01.01.1970" <|
\() ->
Expect.equal "01.01.1970" (toString (1, 1, 1970))
, test "toString of 02.06.2024 " <|
\() ->
Expect.equal "02.06.2024" (toString (2, 6, 2024))
]
leapYearTest : Test
leapYearTest =
describe "leap year test"
[test "leap year 2020" <|
\() ->
Expect.equal True (leapyear 2020)
, test "leap year 2024" <|
\() ->
Expect.equal True (leapyear 2024)
, test "leap year 2021" <|
\() ->
Expect.equal False (leapyear 2021)
, test "leap year 2022" <|
\() ->
Expect.equal False (leapyear 2022)
]
ltTest : Test
ltTest =
describe "less than test"
[test "lt 01.01.1970 01.01.1970" <|
\() ->
Expect.equal False (lt (1, 1, 1970) (1, 1, 1970))
, test "lt 01.01.1970 02.01.1970" <|
\() ->
Expect.equal True (lt (1, 1, 1970) (2, 1, 1970))
, test "lt 01.01.1970 01.02.2000" <|
\() ->
Expect.equal True (lt (1, 1, 1970) (1, 2, 2000))
, test "lt 01.01.2000 01.01.1999" <|
\() ->
Expect.equal False (lt (1, 1, 2000) (1, 1, 1999))
]
eqTest : Test
eqTest =
describe "eq test"
[test "eq 01.01.1970 01.01.1970" <|
\() ->
Expect.equal True (eq (1, 1, 1970) (1, 1, 1970))
, test "eq 01.01.1970 02.01.1970" <|
\() ->
Expect.equal False (eq (1, 1, 1970) (2, 1, 1970))
, test "eq 01.01.1970 01.02.2000" <|
\() ->
Expect.equal False (eq (1, 1, 1970) (1, 2, 2000))
, test "eq 01.01.2000 01.01.1999" <|
\() ->
Expect.equal False (eq (1, 1, 1970) (1, 1, 1999))
]
gtTest : Test
gtTest =
describe "gt test"
[test "gt 01.01.1970 01.01.1970" <|
\() ->
Expect.equal False (gt (1, 1, 1970) (1, 1, 1970))
, test "gt 01.01.1970 02.01.1970" <|
\() ->
Expect.equal False (gt (1, 1, 1970) (2, 1, 1970))
, test "gt 01.01.1970 01.02.2000" <|
\() ->
Expect.equal False (gt (1, 1, 1970) (1, 2, 2000))
, test "gt 01.01.2000 01.01.1999" <|
\() ->
Expect.equal True (gt (1, 1, 2000) (1, 1, 1999))
, test "gt 05.01.2000 01.01.2000" <|
\() ->
Expect.equal True (gt (5, 1, 2000) (1, 1, 2000))
]