pr3-elm/aufgaben/tests/Pflichtuebung_01/DateTests.elm

243 lines
7.9 KiB
Elm

module Pflichtuebung_01.DateTests exposing (..)
import Expect exposing (Expectation)
import Fuzz exposing (Fuzzer, int, list, string)
import Test exposing (..)
import Pflichtuebung_01.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))
]
testNext : Test
testNext =
describe "next method test"
[test "next of 01.01.1970" <|
\() ->
Expect.equal (2, 1, 1970) (next (1, 1, 1970))
, test "next of 02.06.2024 " <|
\() ->
Expect.equal (3, 6, 2024) (next (2, 6, 2024))
, test "next of 31.12.2020" <|
\() ->
Expect.equal (1, 1, 2021) (next (31, 12, 2020))
-- leap year test
, test "next of 28.02.2020" <|
\() ->
Expect.equal (29, 2, 2020) (next (28, 2, 2020))
, test "next of 29.02.2020" <|
\() ->
Expect.equal (1, 3, 2020) (next (29, 2, 2020))
-- non-leap year test
, test "next of 28.02.2021" <|
\() ->
Expect.equal (1, 3, 2021) (next (28, 2, 2021))
]
testPrev : Test
testPrev =
describe "prev method test"
[test "prev of 01.01.2000" <|
\() ->
Expect.equal (31, 12, 1999) (prev (1, 1, 2000))
, test "prev of 02.06.2024 " <|
\() ->
Expect.equal (1, 6, 2024) (prev (2, 6, 2024))
, test "prev of 1.12.2020" <|
\() ->
Expect.equal (30, 11, 2020) (prev (1, 12, 2020))
-- leap year test
, test "prev of 28.02.2020" <|
\() ->
Expect.equal (27, 2, 2020) (prev (28, 2, 2020))
, test "prev of 1.03.2020" <|
\() ->
Expect.equal (29, 2, 2020) (prev (1, 3, 2020))
-- non-leap year test
, test "prev of 1.03.2021" <|
\() ->
Expect.equal (28, 2, 2021) (prev (1, 3, 2021))
]
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)
]
subTest : Test
subTest =
describe "sub test"
[test "sub 01.01.1970 01.01.1970" <|
\() ->
Expect.equal 0 (sub (1, 1, 1970) (1, 1, 1970))
, test "sub 01.01.1970 02.01.1970" <|
\() ->
Expect.equal -1 (sub (1, 1, 1970) (2, 1, 1970))
, test "sub 01.01.1970 01.02.1970" <|
\() ->
Expect.equal -31 (sub (1, 1, 1970) (1, 2, 1970))
, test "sub 01.01.1970 01.01.1971" <|
\() ->
Expect.equal -365 (sub (1, 1, 1970) (1, 1, 1971))
, test "sub 01.01.1970 01.01.1972" <|
\() ->
Expect.equal -730 (sub (1, 1, 1970) (1, 1, 1972))
, test "sub 01.01.1970 01.01.1974" <|
\() ->
Expect.equal -1461 (sub (1, 1, 1970) (1, 1, 1974))
-- explicit leap year 2020 test
, test "sub 27.02.2020 01.03.2020" <|
\() ->
Expect.equal -3 (sub (27, 2, 2020) (1, 3, 2020))
-- positive test
, test "sub 01.01.1970 01.01.1969" <|
\() ->
Expect.equal 365 (sub (1, 1, 1970) (1, 1, 1969))
]
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))
]