Tests Aufgabe 7
Results 1 to 1 of 1

Thread: Tests Aufgabe 7

  1. #1

    Title
    Veteran
    Join Date
    Nov 2017
    Posts
    3
    Thanks
    0
    Thanked 3 Times in 2 Posts

    Tests Aufgabe 7

    HOWTO:
    1. Code in ein .hs-file im gleichen Verzeichnis wie Aufgabe7.hs
    2. in Aufgabe7.hs muss die 1. Zeile "> module Aufgabe7 where" lauten
    3. in hugs "load <testfilename>"
    4. "main" kommando absetzen
    Code:
    import Aufgabe7
    import Test.HUnit hiding (State)
    
    import Control.Exception
    import Control.Monad
    
    -- Damit wir auch auf Exception Testen können
    
    assertException ex action
      = handleJust isWanted (const $ return ()) $ do
        action
        assertFailure $ "Expected exception: " ++ show ex
      where isWanted = guard . (== ex)
    
    assertError ex f =
        TestCase $ assertException (ErrorCall ex) $ evaluate f
    
    main = do
        putStrLn "Aufgabe 7.1"
        res1 <- runTestTT test1
        print res1
        putStrLn ""
    
        putStrLn "Aufgabe 7.2"
        res2 <- runTestTT test2
        print res2
    
    test1 = TestLabel "Test 7.1" $
      TestList [
            {-- SIMPLE TESTS --}
            -- Test negation of constants
            TestCase $ assertEqual "7.1.00" (K True) (nnf (Nicht $ Nicht $ Nicht $ K False)),
            TestCase $ assertEqual "7.1.01" (K False) (nnf (Nicht $ Nicht $ Nicht $ K True)),
            TestCase $ assertEqual "7.1.02" (K True) (nnf (Nicht $ Nicht $ Nicht $ Nicht $ K True)),
            TestCase $ assertEqual "7.1.03" (K False) (nnf (Nicht $ Nicht $ Nicht $ Nicht $ K False)),
    
            -- Test elimination of negation
            TestCase $ assertEqual "7.1.04" (V $ Var N1) (nnf (Nicht $ Nicht $ Nicht $ Nicht $ V $ Var N1)),
            TestCase $ assertEqual "7.1.05" (Nicht $ V $ Var N1) (nnf (Nicht $ Nicht $ Nicht $ V $ Var N1)),
    
            -- Test De Morgan.
            TestCase $ assertEqual "7.1.06" (Nicht $ V $ Var N1) (nnf (Nicht $ Nicht $ Nicht $ V $ Var N1)),
            TestCase $ assertEqual "7.1.07" (Oder (Nicht $ V $ Var N1) (Nicht $ V $ Var N2)) (nnf (Nicht $ Und (V $ Var N1) (V $ Var N2))),
            TestCase $ assertEqual "7.1.08" (Oder (K True) (K False)) (nnf (Nicht $ Und (K False) (Nicht $ Nicht $ K True))),
    
            -- Test implication.
            TestCase $ assertEqual "7.1.09" (Und (V $ Var N5) (Nicht $ V $ Var N4)) (nnf (Nicht $ Impl (V $ Var N5) (V $ Var N4))),
            TestCase $ assertEqual "7.1.10" (Und (K True) (K True)) (nnf (Nicht $ Impl (K True) (K False))),
            TestCase $ assertEqual "7.1.11" (Und (K True) (K True)) (nnf (Nicht $ Impl (Nicht $ Nicht $ K True) (Nicht $ Nicht $ Nicht $ K True))),
    
            -- Test quantifiers.
            TestCase $ assertEqual "7.1.12" (Esgibt (Var N1) (K False)) (nnf (Nicht $ Fueralle (Var N1) (K True))),
            TestCase $ assertEqual "7.1.13" (Fueralle (Var N1) (K True)) (nnf (Nicht $ Esgibt (Var N1) (K False))),
            TestCase $ assertEqual "7.1.14"
                (Fueralle (Var N1) (Esgibt (Var N2) (Oder (Nicht $ V $ Var N1) (Nicht $ V $ Var N2))))
                (nnf (Nicht (Esgibt (Var N1) (Fueralle (Var N2) (Und (V $ Var N1) (V $ Var N2)))))),
            TestCase $ assertEqual "7.1.15"
                (Fueralle (Var N2) (Oder (K False) (Esgibt (Var N4) (Impl (V $ Var N2) (V $ Var N4)))))
                (nnf (Nicht $ Esgibt (Var N2) (Und (K True) (Fueralle (Var N4) (Nicht $ Impl (V $ Var N2) (V $ Var N4)))))),
            TestCase $ assertEqual "7.1.16"
                (Impl (K False) (K False))
                (nnf (Impl (K False) (K False))),
            TestCase $ assertEqual "7.1.17"
                (Impl (K True) (K True))
                (nnf (Impl (Nicht $ K False) (Nicht $ K False))),
            TestCase $ assertEqual "7.1.18"
                (Fueralle (Var N2) (Oder (K False) (Esgibt (Var N4) (Und (V $ Var N2) (Nicht $ V $ Var N4)))))
                (nnf (Nicht $ Esgibt (Var N2) (Und (K True) (Fueralle (Var N4) (Impl (V $ Var N2) (V $ Var N4)))))),
    
            {-- TESTS WITH NESTING --}
            TestCase $ assertEqual "7.1.19"
                (Und (K True) (K False))
                (nnf $ Und (Nicht $ Nicht $ Nicht $ K False) (Nicht $ Nicht $ Nicht $ K True)),
            TestCase $ assertEqual "7.1.20"
                (Oder (Oder (Nicht (V (Var N1))) (Nicht (V (Var N2)))) (Und (V (Var N5)) (Nicht (V (Var N4)))))
                (nnf $ Oder (Nicht $ Und (V $ Var N1) (V $ Var N2)) (Nicht $ Impl (V $ Var N5) (V $ Var N4))),
            TestCase $ assertEqual "7.1.21"
                (Impl (K False) (Oder (K True) (K False)))
                (nnf $ Impl (K False) (Nicht $ Und (K False) (K True))),
    
            {-- VERIFY IDENTITY AND IDEMPOTENCE --}
            TestCase $ assertEqual "7.1.22"
                (Fueralle (Var N1) (Und (V $ Var N1) (V $ Var N2)))
                (nnf $ Fueralle (Var N1) (Und (V $ Var N1) (V $ Var N2))),
    
            TestCase $ assertEqual "7.1.23"
                (nnf $ Nicht (Esgibt (Var N1) (Fueralle (Var N2) (Und (V $ Var N1) (V $ Var N2)))))
                (nnf $ nnf $ nnf (Nicht (Esgibt (Var N1) (Fueralle (Var N2) (Und (V $ Var N1) (V $ Var N2))))))
          ]
    
    test2 = TestLabel "Test 7.2" $
      TestList [
            -- f1 tests
            TestCase $ assertEqual "7.2.00" (Just [(S1,18,S2,21),(S2,3,S3,5)]) (reise_planer f1 S1 S3),
            TestCase $ assertEqual "7.2.01" (Just 0) (proviant_planer f1 S1 S3),
            TestCase $ assertEqual "7.2.02" (Nothing) (reise_planer f1 S3 S1),
            TestCase $ assertEqual "7.2.03" (Nothing) (proviant_planer f1 S3 S1),
            -- f2 tests
            TestCase $ assertEqual "7.2.04"
                (Just [(S1,20,S2,21),(S2,20,S5,22),(S5,22,S4,23),(S4,23,S3,0)])
                (reise_planer f2 S1 S3),
            TestCase $ assertEqual "7.2.05" (Just 1) (proviant_planer f2 S1 S3),
            -- f3 tests
            TestCase $ assertEqual "7.2.06" (Nothing) (reise_planer f3 S1 S3),
            TestCase $ assertEqual "7.2.07" (Nothing) (proviant_planer f3 S1 S3),
            -- f4 tests
            TestCase $ assertEqual "7.2.08"
                (Just [(S1,18,S2,19),(S2,19,S3,21),(S3,21,S5,22),(S5,22,S7,0),(S7,0,S6,1),(S6,1,S8,6)])
                (reise_planer f4 S1 S8),
            TestCase $ assertEqual "7.2.09" (Just 0) (proviant_planer f4 S1 S8),
            -- f5 tests (Might not be needed. It's one node with a loop, see drawing.)
            --          Your implementation may also handle it differently. In case of
            --          doubt, ignore/delete this test, it's dumb.
            TestCase $ assertEqual "7.2.10" (Just []) (reise_planer f5 S1 S1),
            TestCase $ assertEqual "7.2.11" (Just 0) (proviant_planer f5 S1 S1),
            -- f6 tests
            TestCase $ assertEqual "7.2.12"
                (Just [(S1,18,S3,21),(S3,20,S5,21)])
                (reise_planer f6 S1 S5),
            TestCase $ assertEqual "7.2.13" (Just 1) (proviant_planer f6 S1 S5),
            -- f7 tests
            TestCase $ assertEqual "7.2.14"
                (Just [(S1,20,S2,22),(S2,21,S5,22),(S5,3,S7,5),(S7,20,S9,21),(S9,22,S10,3)])
                (reise_planer f7 S1 S10),
            TestCase $ assertEqual "7.2.15" (Just 2) (proviant_planer f7 S1 S10)
          ]
    
    
    f1 :: Fahrplan
    f1 S1 = [(S2, 18, 3)]
    f1 S2 = [(S3, 19, 1), (S3, 3, 2), (S3, 3, 5)]
    f1 _  = []
    
    f2 :: Fahrplan
    f2 S1 = [(S2, 20, 1)]
    f2 S2 = [(S3, 17, 5), (S5, 20, 2)]
    f2 S4 = [(S1, 23, 1), (S3, 23, 1)]
    f2 S5 = [(S3, 20, 2), (S4, 22, 1)]
    f2 _  = []
    
    f3 :: Fahrplan
    f3 S1 = [(S2, 17, 3), (S2, 1, 1), (S2, 7, 1)]
    f3 S2 = [(S3, 7, 12), (S3, 3, 10), (S3, 17, 12), (S1, 3, 2)]
    f3 _  = []
    
    f4 :: Fahrplan
    f4 S1 = [(S2, 18, 1), (S3, 1, 2)]
    f4 S2 = [(S5, 5, 2), (S3, 19, 2)]
    f4 S3 = [(S5, 21, 1), (S6, 3, 1)]
    f4 S4 = [(S7, 5, 2)]
    f4 S5 = [(S7, 22, 2)]
    f4 S6 = [(S8, 1, 5)]
    f4 S7 = [(S8, 20, 1), (S6, 0, 1)]
    f4 _  = []
    
    f5 :: Fahrplan
    f5 S1 = [(S1, 20, 1)]
    f5 _  = []
    
    f6 :: Fahrplan
    f6 S1 = [(S3, 18, 3), (S2, 20, 1)]
    f6 S2 = [(S3, 20, 1), (S4, 20, 1)]
    f6 S3 = [(S5, 20, 1)]
    f6 S4 = [(S5, 20, 1)]
    f6 _  = []
    
    f7 :: Fahrplan
    f7 S1 = [(S2, 20, 2), (S3, 19, 1), (S4, 18, 1)]
    f7 S2 = [(S5, 21, 1)]
    f7 S3 = [(S5, 19, 9), (S6, 19, 9)]
    f7 S4 = [(S6, 18, 11)]
    f7 S5 = [(S7, 3, 2)]
    f7 S6 = [(S7, 3, 1)]
    f7 S7 = [(S8, 3, 1), (S9, 20, 1)]
    f7 S8 = [(S10, 3, 1)]
    f7 S9 = [(S10, 22, 5)]
    f7 _  = []
    Edit: Hier noch die Skizze für AG2: https://i.imgur.com/dcXe0jo.png
    Last edited by alem; 05-12-2017 at 11:58. Reason: Skizze vergessen :)

  2. The Following User Says Thank You to alem For This Useful Post:


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •