Add UE5 A.3

This commit is contained in:
Ivaylo Ivanov 2021-11-18 18:09:23 +01:00
parent 7033fc1258
commit c1208da5b9
2 changed files with 34 additions and 38 deletions

View File

@ -1,4 +1,5 @@
module Angabe5 where
import Data.List
{- 1. Vervollstaendigen Sie gemaess Angabentext!
2. Vervollständigen Sie auch die vorgegebenen Kommentaranfänge!
@ -26,13 +27,23 @@ class Eq a => Menge_von a where
-- Protoimplementierungen
leer = []
vereinige xs ys = xs ++ ys
ist_teilmenge xs ys = ist_obermenge ys xs
vereinige xs ys = clear_duplicates (xs ++ ys)
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_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
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:
@ -151,48 +162,33 @@ build_pairs fkt arg
-- Aufgabe A.3
-- instance Menge_von Int where
-- ...
instance Menge_von Int where
-- instance Menge_von Zahlraum_0_10 where
-- ...
-- instance Menge_von Funktion where
-- ...
instance Menge_von Zahlraum_0_10 where
instance Menge_von Funktion where
-- Aufgabe A.4
-- instance (Eq a,Eq b) => Menge_von (Paar a b) where
-- ...
-- instance Eq a => Menge_von (Baum a) where
-- ...
instance (Eq a,Eq b) => Menge_von (Paar a b) where
instance Eq a => Menge_von (Baum a) where
-- Aufgabe A.5
-- instance Eq a => Eq (ElemTyp a) where
-- ...
-- instance Show a => Show (ElemTyp a) where
-- ...
instance Eq a => Eq (ElemTyp a) where
(==) (ET a) (ET b) = a == b
instance Show a => Show (ElemTyp a) where
-- Aufgabe A.6
-- instance Eq a => Menge_von (ElemTyp a) where
-- ...
instance Eq a => Menge_von (ElemTyp a) where
-- 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
-- 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

View File

@ -78,10 +78,10 @@ spec =
funktion_tests,
menge_von_int_tests,
menge_von_zahlraum_0_10_tests,
menge_von_funktion_tests,
menge_von_ElemTyp_tests,
ph_elemtyp_tests,
ph_elemtyp'_tests
menge_von_funktion_tests
-- menge_von_ElemTyp_tests,
-- ph_elemtyp_tests,
-- ph_elemtyp'_tests
]
zahlraum_0_10_tests :: TestTree
@ -112,7 +112,7 @@ zahlraum_0_10_tests =
testCase "fromInteger: [0..11] -> [N,I..X,F]" $
[fromInteger i | i <- [0..11]] @?= zahlraum010_liste
]
funktion_tests :: TestTree
funktion_tests =
testGroup
@ -127,7 +127,7 @@ funktion_tests =
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)}"
]
menge_von_int_tests :: TestTree
menge_von_int_tests =
testGroup
@ -169,7 +169,7 @@ menge_von_zahlraum_0_10_tests =
testCase "anzahl: N zr010Menge_1" $
anzahl N zr010Menge_1 @?= 1
]
menge_von_funktion_tests :: TestTree
menge_von_funktion_tests =
testGroup
@ -190,7 +190,7 @@ menge_von_funktion_tests =
testCase "anzahl: abs fktMenge_1" $
anzahl (Fkt abs) fktMenge_1 @?= 1
]
menge_von_ElemTyp_tests :: TestTree
menge_von_ElemTyp_tests =
testGroup
@ -217,7 +217,7 @@ menge_von_ElemTyp_tests =
testCase "anzahl ET Fkt: abs etFktMultimenge_1" $
anzahl (ET (Fkt abs)) etFktMultimenge_1 @?= 2
]
ph_elemtyp_tests :: TestTree
ph_elemtyp_tests =
testGroup
@ -234,7 +234,7 @@ ph_elemtyp_tests =
testCase "ist_obermenge: phETMenge_1 phETMenge_4" $
ist_obermenge phETMenge_1 phETMenge_4 @?= False-}
]
ph_elemtyp'_tests :: TestTree
ph_elemtyp'_tests =
testGroup