added test cases for date

Signed-off-by: Skyball2000 <thomas3654william@gmail.com>
main
Yan Wittmann 2022-11-08 11:22:48 +01:00 committed by Skyball2000
parent 902d5725d9
commit 6ff56e98cb
4 changed files with 310 additions and 19 deletions

View File

@ -1,45 +1,50 @@
module Pflichtuebung_01.Pu01 exposing (..)
module Pflichtuebung_01.Date exposing (..)
type alias Day =
Int
type alias Month =
Int
type alias Year =
Int
type alias Date =
( Day, Month, Year )
-- 1 Punkt:
year : Date -> Year
--year (a, b, c) = c
year (_, _, c) = c
month : Date -> Month
--month (a,b,c) = b
month (_, b, _) = b
day : Date -> Day
--day (a,b , c) = a
day (a, _, _) = a
-- 1 Punkt:
lt : Date -> Date -> Bool
lt date1 date2 = False
eq : Date -> Date -> Bool
eq date1 date2 = False
gt : Date -> Date -> Bool
gt date1 date2 = False
-- 1 Punkt:
toString : Date -> String
toString date = ""
-- 2 Punkte:
next : Date -> Date
next date = (1, 1, 1)
-- 2 Punkte:
prev : Date -> Date
prev date = (1, 1, 1)
-- 1 Punkt:
leapyear : Year -> Bool
leapyear y = False
-- 2 Punkte
-- 2 Punkte:
sub : Date -> Date -> Int
sub date1 date2 = 0

View File

@ -0,0 +1,283 @@
module Pflichtuebung_01.DateTests exposing (..)
import Expect exposing (Expectation)
import Fuzz exposing (Fuzzer, int, list, string)
import Test exposing (..)
import Pflichtuebung_01.Date exposing (..)
--type alias Day =
-- Int
--
--
--type alias Month =
-- Int
--
--
--type alias Year =
-- Int
--
--
--type alias Date =
-- ( Day, Month, Year )
--
---- 1 Punkt:
--year : Date -> Year
----year (a, b, c) = c
--month : Date -> Month
----month (a,b,c) = b
--day : Date -> Day
----day (a,b , c) = a
--
--lt : Date -> Date -> Bool
--eq : Date -> Date -> Bool
--gt : Date -> Date -> Bool
--
--toString : Date -> String
--
--next : Date -> Date
--
--prev : Date -> Date
--
--leapyear : Year -> Bool
--
--sub : Date -> Date -> Int
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)
]
-- sub a b soll die Anzahl der Tage liefern, die zwischen den Daten a und b liegt. Wenn a
-- vor b liegt, soll das Ergebnis negativ sein, sonst positiv (außer a und b sind gleich, dann soll
-- das Ergebnis 0 sein).
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, 1970) (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, 1970) (1, 1, 1999))
, test "gt 05.01.2000 01.01.2000" <|
\() ->
Expect.equal True (gt (5, 1, 2000) (1, 1, 2000))
]

View File

@ -1,10 +0,0 @@
module Pflichtuebung_01.Pu01Tests exposing (..)
import Expect exposing (Expectation)
import Fuzz exposing (Fuzzer, int, list, string)
import Test exposing (..)
suite : Test
suite =
todo "Implement our first test. See https://package.elm-lang.org/packages/elm-explorations/test/latest for how to do this!"

View File

@ -0,0 +1,13 @@
module Test03.ListStuffTests exposing (..)
import Expect exposing (Expectation)
import Fuzz exposing (Fuzzer, int, list, string)
import Test exposing (..)
import Test03.ListStuff
test1 : Test
test1 =
test "Length1 method is not equal 1"
(\_ -> Expect.equal 1 (Test03.ListStuff.length1 [2] 0))