Add UE5 A.3
This commit is contained in:
parent
7033fc1258
commit
c1208da5b9
@ -1,4 +1,5 @@
|
|||||||
module Angabe5 where
|
module Angabe5 where
|
||||||
|
import Data.List
|
||||||
|
|
||||||
{- 1. Vervollstaendigen Sie gemaess Angabentext!
|
{- 1. Vervollstaendigen Sie gemaess Angabentext!
|
||||||
2. Vervollständigen Sie auch die vorgegebenen Kommentaranfänge!
|
2. Vervollständigen Sie auch die vorgegebenen Kommentaranfänge!
|
||||||
@ -26,13 +27,23 @@ class Eq a => Menge_von a where
|
|||||||
|
|
||||||
-- Protoimplementierungen
|
-- Protoimplementierungen
|
||||||
leer = []
|
leer = []
|
||||||
vereinige xs ys = xs ++ ys
|
vereinige xs ys = clear_duplicates (xs ++ ys)
|
||||||
ist_teilmenge xs ys = ist_obermenge ys xs
|
schneide xs ys = xs \\ (xs \\ ys)
|
||||||
|
ziehe_ab xs ys = xs \\ (intersectBy (==) xs ys)
|
||||||
|
ist_teilmenge xs ys = (length (ziehe_ab xs ys) == 0)
|
||||||
ist_obermenge xs ys = ist_teilmenge ys xs
|
ist_obermenge xs ys = ist_teilmenge ys xs
|
||||||
ist_element x xs = anzahl x xs >= 1
|
ist_element x xs = anzahl x xs >= 1
|
||||||
|
anzahl x xs = if (has_duplicates xs) then error "Fehler" else (length . filter (== x)) xs
|
||||||
ist_leer xs = xs == leer
|
ist_leer xs = xs == leer
|
||||||
sind_gleich xs ys = ist_teilmenge xs ys && ist_teilmenge ys xs
|
sind_gleich xs ys = ist_teilmenge xs ys && ist_teilmenge ys xs
|
||||||
|
|
||||||
|
clear_duplicates :: Eq a => [a] -> [a]
|
||||||
|
clear_duplicates [] = []
|
||||||
|
clear_duplicates (x:xs) = x : filter (/= x) (clear_duplicates xs)
|
||||||
|
|
||||||
|
has_duplicates:: Eq a => [a] -> Bool
|
||||||
|
has_duplicates [] = False
|
||||||
|
has_duplicates (x:xs) = if x `elem` xs then True else has_duplicates xs
|
||||||
|
|
||||||
-- Weitere Typen:
|
-- Weitere Typen:
|
||||||
|
|
||||||
@ -151,48 +162,33 @@ build_pairs fkt arg
|
|||||||
|
|
||||||
-- Aufgabe A.3
|
-- Aufgabe A.3
|
||||||
|
|
||||||
-- instance Menge_von Int where
|
instance Menge_von Int where
|
||||||
-- ...
|
|
||||||
|
|
||||||
-- instance Menge_von Zahlraum_0_10 where
|
instance Menge_von Zahlraum_0_10 where
|
||||||
-- ...
|
|
||||||
|
|
||||||
-- instance Menge_von Funktion where
|
|
||||||
-- ...
|
|
||||||
|
|
||||||
|
instance Menge_von Funktion where
|
||||||
|
|
||||||
-- Aufgabe A.4
|
-- Aufgabe A.4
|
||||||
|
|
||||||
-- instance (Eq a,Eq b) => Menge_von (Paar a b) where
|
instance (Eq a,Eq b) => Menge_von (Paar a b) where
|
||||||
-- ...
|
|
||||||
|
|
||||||
-- instance Eq a => Menge_von (Baum a) where
|
|
||||||
-- ...
|
|
||||||
|
|
||||||
|
instance Eq a => Menge_von (Baum a) where
|
||||||
|
|
||||||
-- Aufgabe A.5
|
-- Aufgabe A.5
|
||||||
|
|
||||||
-- instance Eq a => Eq (ElemTyp a) where
|
instance Eq a => Eq (ElemTyp a) where
|
||||||
-- ...
|
(==) (ET a) (ET b) = a == b
|
||||||
|
|
||||||
-- instance Show a => Show (ElemTyp a) where
|
|
||||||
-- ...
|
|
||||||
|
|
||||||
|
instance Show a => Show (ElemTyp a) where
|
||||||
|
|
||||||
-- Aufgabe A.6
|
-- Aufgabe A.6
|
||||||
|
|
||||||
-- instance Eq a => Menge_von (ElemTyp a) where
|
instance Eq a => Menge_von (ElemTyp a) where
|
||||||
-- ...
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- Aufgabe A.7
|
-- Aufgabe A.7
|
||||||
|
|
||||||
-- instance (Eq a,Eq b,Eq c,Eq d,Eq e) => Menge_von (PH_ElemTyp a b c d e) where
|
instance (Eq a,Eq b,Eq c,Eq d,Eq e) => Menge_von (PH_ElemTyp a b c d e) where
|
||||||
-- ...
|
|
||||||
|
|
||||||
|
|
||||||
-- Aufgabe A.8
|
-- Aufgabe A.8
|
||||||
|
|
||||||
-- instance (Eq p,Eq q,Eq r) => Menge_von (PH_ElemTyp' p q r) where ...
|
instance (Eq p,Eq q,Eq r) => Menge_von (PH_ElemTyp' p q r) where
|
||||||
|
|
||||||
|
@ -78,10 +78,10 @@ spec =
|
|||||||
funktion_tests,
|
funktion_tests,
|
||||||
menge_von_int_tests,
|
menge_von_int_tests,
|
||||||
menge_von_zahlraum_0_10_tests,
|
menge_von_zahlraum_0_10_tests,
|
||||||
menge_von_funktion_tests,
|
menge_von_funktion_tests
|
||||||
menge_von_ElemTyp_tests,
|
-- menge_von_ElemTyp_tests,
|
||||||
ph_elemtyp_tests,
|
-- ph_elemtyp_tests,
|
||||||
ph_elemtyp'_tests
|
-- ph_elemtyp'_tests
|
||||||
]
|
]
|
||||||
|
|
||||||
zahlraum_0_10_tests :: TestTree
|
zahlraum_0_10_tests :: TestTree
|
||||||
@ -112,7 +112,7 @@ zahlraum_0_10_tests =
|
|||||||
testCase "fromInteger: [0..11] -> [N,I..X,F]" $
|
testCase "fromInteger: [0..11] -> [N,I..X,F]" $
|
||||||
[fromInteger i | i <- [0..11]] @?= zahlraum010_liste
|
[fromInteger i | i <- [0..11]] @?= zahlraum010_liste
|
||||||
]
|
]
|
||||||
|
|
||||||
funktion_tests :: TestTree
|
funktion_tests :: TestTree
|
||||||
funktion_tests =
|
funktion_tests =
|
||||||
testGroup
|
testGroup
|
||||||
@ -127,7 +127,7 @@ funktion_tests =
|
|||||||
testCase "show (Fkt signum)" $
|
testCase "show (Fkt signum)" $
|
||||||
show (Fkt signum) @?= "{(N,N),(I,I),(II,I),(III,I),(IV,I),(V,I),(VI,I),(VII,I),(VIII,I),(IX,I),(X,I),(F,F)}"
|
show (Fkt signum) @?= "{(N,N),(I,I),(II,I),(III,I),(IV,I),(V,I),(VI,I),(VII,I),(VIII,I),(IX,I),(X,I),(F,F)}"
|
||||||
]
|
]
|
||||||
|
|
||||||
menge_von_int_tests :: TestTree
|
menge_von_int_tests :: TestTree
|
||||||
menge_von_int_tests =
|
menge_von_int_tests =
|
||||||
testGroup
|
testGroup
|
||||||
@ -169,7 +169,7 @@ menge_von_zahlraum_0_10_tests =
|
|||||||
testCase "anzahl: N zr010Menge_1" $
|
testCase "anzahl: N zr010Menge_1" $
|
||||||
anzahl N zr010Menge_1 @?= 1
|
anzahl N zr010Menge_1 @?= 1
|
||||||
]
|
]
|
||||||
|
|
||||||
menge_von_funktion_tests :: TestTree
|
menge_von_funktion_tests :: TestTree
|
||||||
menge_von_funktion_tests =
|
menge_von_funktion_tests =
|
||||||
testGroup
|
testGroup
|
||||||
@ -190,7 +190,7 @@ menge_von_funktion_tests =
|
|||||||
testCase "anzahl: abs fktMenge_1" $
|
testCase "anzahl: abs fktMenge_1" $
|
||||||
anzahl (Fkt abs) fktMenge_1 @?= 1
|
anzahl (Fkt abs) fktMenge_1 @?= 1
|
||||||
]
|
]
|
||||||
|
|
||||||
menge_von_ElemTyp_tests :: TestTree
|
menge_von_ElemTyp_tests :: TestTree
|
||||||
menge_von_ElemTyp_tests =
|
menge_von_ElemTyp_tests =
|
||||||
testGroup
|
testGroup
|
||||||
@ -217,7 +217,7 @@ menge_von_ElemTyp_tests =
|
|||||||
testCase "anzahl ET Fkt: abs etFktMultimenge_1" $
|
testCase "anzahl ET Fkt: abs etFktMultimenge_1" $
|
||||||
anzahl (ET (Fkt abs)) etFktMultimenge_1 @?= 2
|
anzahl (ET (Fkt abs)) etFktMultimenge_1 @?= 2
|
||||||
]
|
]
|
||||||
|
|
||||||
ph_elemtyp_tests :: TestTree
|
ph_elemtyp_tests :: TestTree
|
||||||
ph_elemtyp_tests =
|
ph_elemtyp_tests =
|
||||||
testGroup
|
testGroup
|
||||||
@ -234,7 +234,7 @@ ph_elemtyp_tests =
|
|||||||
testCase "ist_obermenge: phETMenge_1 phETMenge_4" $
|
testCase "ist_obermenge: phETMenge_1 phETMenge_4" $
|
||||||
ist_obermenge phETMenge_1 phETMenge_4 @?= False-}
|
ist_obermenge phETMenge_1 phETMenge_4 @?= False-}
|
||||||
]
|
]
|
||||||
|
|
||||||
ph_elemtyp'_tests :: TestTree
|
ph_elemtyp'_tests :: TestTree
|
||||||
ph_elemtyp'_tests =
|
ph_elemtyp'_tests =
|
||||||
testGroup
|
testGroup
|
||||||
|
Reference in New Issue
Block a user