Last active
December 8, 2015 16:29
-
-
Save sanssecours/0ff7ce3b63e3c2fe4ca5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Imports --------------------------------------------------------------------- | |
import Aufgabe7 ( | |
Nat(..), Ziffer(..), Zeichen(..), Graph(..) | |
, kIndependent, isConnected, isTree | |
, Airports(..), Airlines(..), Networks, Fare | |
, airlineConnections, allianceConnections, cheapestConnections | |
) | |
import Data.List (sort) | |
import Test.HUnit | |
-- Data ------------------------------------------------------------------------ | |
nat0 = Nat ((A, A, A), (Null, Null, Null)) | |
nat1 = Nat ((A, A, A), (Null, Null, Eins)) | |
nat2 = Nat ((A, A, A), (Null, Null, Zwei)) | |
nat3 = Nat ((A, A, A), (Null, Null, Drei)) | |
nat4 = Nat ((A, A, A), (Null, Null, Vier)) | |
nat5 = Nat ((A, A, A), (Null, Null, Fuenf)) | |
nat8 = Nat ((A, A, A), (Null, Null, Acht)) | |
nat12 = Nat ((A, A, A), (Null, Eins, Zwei)) | |
nat13 = Nat ((A, A, A), (Null, Eins, Drei)) | |
nat15 = Nat ((A, A, A), (Null, Eins, Fuenf)) | |
nat20 = Nat ((A, A, A), (Null, Zwei, Null)) | |
nat23 = Nat ((A, A, A), (Null, Zwei, Drei)) | |
nat50 = Nat ((A, A, A), (Null, Fuenf, Null)) | |
nat100 = Nat ((A, A, A), (Eins, Null, Null)) | |
graph1 = Gph [ | |
(1, [2, 3]) | |
, (2, [1, 4]) | |
, (3, [4]) | |
, (5, []) | |
] | |
graph2 = Gph [ | |
(1, [2, 3]) | |
, (2, [1, 3]) | |
, (3, []) | |
, (4, [5, 6]) | |
, (5, [7]) | |
, (6, [7]) | |
, (8, [9]) | |
, (9, [10]) | |
] | |
graph3 = Gph [ | |
(1, [2, 7]) | |
, (2, [3]) | |
, (3, [2, 8]) | |
, (4, [5, 9]) | |
, (5, [6]) | |
, (6, [5, 11]) | |
, (7, [1, 14]) | |
, (8, [9, 16]) | |
, (9, [10]) | |
, (10, [9, 11]) | |
, (11, [19, 10, 12, 6]) | |
, (12, [13, 20]) | |
, (13, [21]) | |
, (14, [7, 15]) | |
, (15, [16]) | |
, (16, [15, 17, 8]) | |
, (17, [18]) | |
, (18, [19]) | |
, (19, [22, 11]) | |
, (20, [23]) | |
, (21, [24, 13]) | |
, (22, [23]) | |
, (24, [23]) | |
] | |
tree1 = Gph [ | |
(1, [4]) | |
, (2, [4]) | |
, (3, [4]) | |
, (4, [6]) | |
, (5, [6]) | |
, (7, [6]) | |
, (8, [6]) | |
] | |
forest1 = Gph [ | |
(1, [2]) | |
, (3, []) | |
] | |
graph3independent2 = [ | |
[1, 3], [1, 4], [1, 5], [1, 6], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12] | |
, [1, 13], [1, 14], [1, 15], [1, 16], [1, 17], [1, 18], [1, 19], [1, 20] | |
, [1, 21], [1, 22], [1, 23], [1, 24], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8] | |
, [2, 9], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [2, 15], [2, 16] | |
, [2, 17], [2, 18], [2, 19], [2, 20], [2, 21], [2, 22], [2, 23], [2, 24] | |
, [3, 4], [3, 5], [3, 6], [3, 7], [3, 9], [3, 10], [3, 11], [3, 12], [3, 13] | |
, [3, 14], [3, 15], [3, 16], [3, 17], [3, 18], [3, 19], [3, 20], [3, 21] | |
, [3, 22], [3, 23], [3, 24], [4, 6], [4, 7], [4, 8], [4, 10], [4, 11] | |
, [4, 12], [4, 13], [4, 14], [4, 15], [4, 16], [4, 17], [4, 18], [4, 19] | |
, [4, 20], [4, 21], [4, 22], [4, 23], [4, 24], [5, 7], [5, 8], [5, 9] | |
, [5, 10], [5, 11], [5, 12], [5, 13], [5, 14], [5, 15], [5, 16], [5, 17] | |
, [5, 18], [5, 19], [5, 20], [5, 21], [5, 22], [5, 23], [5, 24], [6, 7] | |
, [6, 8], [6, 9], [6, 10], [6, 12], [6, 13], [6, 14], [6, 15], [6, 16] | |
, [6, 17], [6, 18], [6, 19], [6, 20], [6, 21], [6, 22], [6, 23], [6, 24] | |
, [7, 8], [7, 9], [7, 10], [7, 11], [7, 12], [7, 13], [7, 15], [7, 16] | |
, [7, 17], [7, 18], [7, 19], [7, 20], [7, 21], [7, 22], [7, 23], [7, 24] | |
, [8, 10], [8, 11], [8, 12], [8, 13], [8, 14], [8, 15], [8, 17], [8, 18] | |
, [8, 19], [8, 20], [8, 21], [8, 22], [8, 23], [8, 24], [9, 11], [9, 12] | |
, [9, 13], [9, 14], [9, 15], [9, 16], [9, 17], [9, 18], [9, 19], [9, 20] | |
, [9, 21], [9, 22], [9, 23], [9, 24], [10, 12], [10, 13], [10, 14], [10, 15] | |
, [10, 16], [10, 17], [10, 18], [10, 19], [10, 20], [10, 21], [10, 22] | |
, [10, 23], [10, 24], [11, 13], [11, 14], [11, 15], [11, 16], [11, 17] | |
, [11, 18], [11, 20], [11, 21], [11, 22], [11, 23], [11, 24], [12, 14] | |
, [12, 15], [12, 16], [12, 17], [12, 18], [12, 19], [12, 21], [12, 22] | |
, [12, 23], [12, 24], [13, 14], [13, 15], [13, 16], [13, 17], [13, 18] | |
, [13, 19], [13, 20], [13, 22], [13, 23], [13, 24], [14, 16], [14, 17] | |
, [14, 18], [14, 19], [14, 20], [14, 21], [14, 22], [14, 23], [14, 24] | |
, [15, 17], [15, 18], [15, 19], [15, 20], [15, 21], [15, 22], [15, 23] | |
, [15, 24], [16, 18], [16, 19], [16, 20], [16, 21], [16, 22], [16, 23] | |
, [16, 24], [17, 19], [17, 20], [17, 21], [17, 22], [17, 23], [17, 24] | |
, [18, 20], [18, 21], [18, 22], [18, 23], [18, 24], [19, 20], [19, 21] | |
, [19, 23], [19, 24], [20, 21], [20, 22], [20, 24], [21, 22], [21, 23] | |
, [22, 24] | |
] | |
graph3independent12 = [ | |
[1, 3, 4, 6, 10, 13, 14, 16, 18, 20, 22, 24] | |
, [1, 3, 5, 9, 11, 13, 14, 16, 18, 20, 22, 24] | |
, [2, 4, 6, 7, 8, 10, 12, 15, 17, 19, 21, 23] | |
, [2, 4, 6, 7, 8, 10, 13, 15, 17, 19, 20, 24] | |
, [2, 4, 6, 7, 8, 10, 13, 15, 17, 20, 22, 24] | |
, [2, 4, 6, 7, 8, 10, 13, 15, 18, 20, 22, 24] | |
] | |
noFlyZone :: Networks | |
noFlyZone _ _ = [] | |
network :: Networks | |
network Aeroflot = aeroflot | |
network AUA = aua | |
network _ = (\_ -> []) | |
extendedNetwork :: Networks | |
extendedNetwork KLM = klm | |
extendedNetwork airline = network airline | |
aeroflot :: Airports -> [(Airports, Fare)] | |
aeroflot AMS = [(HAM, nat2), (TXL, nat3)] | |
aeroflot AUC = [(LAX, nat4), (SFO, nat15)] | |
aeroflot DUS = [(FRA, nat1), (HAM, nat2)] | |
aeroflot FRA = [(DUS, nat1), (JFK, nat2), (HAJ, nat1), (MUC, nat2), (VIE, nat1)] | |
aeroflot HAJ = [(HAM, nat1), (FRA, nat1), (VIE, nat3)] | |
aeroflot HAM = [(AMS, nat1), (DUS, nat2), (HAJ, nat1), (TXL, nat1)] | |
aeroflot JFK = [(HAM, nat5), (LAX, nat20), (FRA, nat2), (SFO, nat2)] | |
aeroflot LAX = [(AUC, nat4), (JFK, nat20), (LAX, nat50) ,(SFO, nat23), | |
(TXL, nat4)] | |
aeroflot MUC = [(FRA, nat2), (SFO, nat3)] | |
aeroflot SFO = [(AUC, nat15), (JFK, nat2), (LAX, nat23), (MUC, nat3), | |
(VIE, nat1)] | |
aeroflot TXL = [(AMS, nat3), (HAM, nat1), (LAX, nat4), (VIE, nat4)] | |
aeroflot VIE = [(FRA, nat1), (HAJ, nat3), (SFO, nat1), (TXL, nat4)] | |
aua :: Airports -> [(Airports, Fare)] | |
aua LAX = [(VIE, nat100)] | |
aua _ = [] | |
klm :: Airports -> [(Airports, Fare)] | |
klm AUC = [(LAX, nat3)] | |
klm DUS = [(JFK, nat3), (VIE, nat3)] | |
klm HAM = [(DUS, nat2)] | |
klm JFK = [(AUC, nat3), (VIE, nat1)] | |
klm LAX = [(HAM, nat1)] | |
klm _ = [] | |
allianceAeroflotAUA :: Airlines -> [Airlines] | |
allianceAeroflotAUA Aeroflot = [AUA] | |
allianceAeroflotAUA AUA = [Aeroflot] | |
allianceAeroflotAUA _ = [] | |
allianceAll :: Airlines -> [Airlines] | |
allianceAll _ = [minBound :: Airlines .. maxBound :: Airlines] | |
-- Main ------------------------------------------------------------------------ | |
main = runTestTT $ TestList [ | |
testKIndependent | |
, testKIndependentLarge | |
, testIsConnected | |
, testIsTree | |
, testAirlineConnections | |
, testAllianceConnections | |
, testCheapestConnections | |
] | |
-- 1 --------------------------------------------------------------------------- | |
testKIndependent = TestLabel "kIndependent" $ TestList [ | |
TestCase $ assertEqual "kIndependent graph1 nat0" | |
[[]] (kIndependent graph1 nat0) | |
, TestCase $ assertEqual "kIndependent graph1 nat1" | |
[[1], [2], [3], [4], [5]] (kIndependent graph1 nat1) | |
, TestCase $ assertEqual "kIndependent graph1 nat2" | |
[[1,4],[1,5],[2,3],[2,5],[3,5],[4,5]] | |
(kIndependent graph1 nat2) | |
, TestCase $ assertEqual "kIndependent graph1 nat3" | |
[[1, 4, 5], [2, 3, 5]] | |
(kIndependent graph1 nat3) | |
, TestCase $ assertEqual "kIndependent graph3 nat2" | |
graph3independent2 | |
(kIndependent graph3 nat2) | |
] | |
testKIndependentLarge = TestLabel "kIndependent" $ TestList [ | |
TestCase $ assertEqual "kIndependent graph3 nat12" | |
graph3independent12 (kIndependent graph3 nat12) | |
, TestCase $ assertEqual "kIndependent graph3 nat13" | |
[] (kIndependent graph3 nat13) | |
] | |
testIsConnected = TestLabel "isConnected" $ TestList [ | |
TestCase $ assertEqual "isConnected graph1" False (isConnected graph1) | |
, TestCase $ assertEqual "isConnected graph2" False (isConnected graph2) | |
, TestCase $ assertEqual "isConnected graph3" True (isConnected graph3) | |
, TestCase $ assertEqual "isConnected tree1" True (isConnected tree1) | |
, TestCase $ assertEqual "isConnected forest1" False (isConnected forest1) | |
] | |
testIsTree = TestLabel "isTree" $ TestList [ | |
TestCase $ assertEqual "isTree graph1" False (isTree graph1) | |
, TestCase $ assertEqual "isTree graph2" False (isTree graph2) | |
, TestCase $ assertEqual "isTree graph3" False (isTree graph3) | |
, TestCase $ assertEqual "isTree tree1" True (isTree tree1) | |
, TestCase $ assertEqual "isTree forest1" False (isTree forest1) | |
] | |
-- 2 --------------------------------------------------------------------------- | |
testAirlineConnections = TestLabel "airlineConnections" $ TestList [ | |
TestCase $ assertEqual | |
"sort $ airlineConnections LAX VIE network Aeroflot" | |
[[(LAX, Aeroflot, SFO), (SFO, Aeroflot, VIE)], | |
[(LAX, Aeroflot, TXL), (TXL, Aeroflot, VIE)]] | |
(sort $ airlineConnections LAX VIE network Aeroflot) | |
, TestCase $ assertEqual | |
"airlineConnections LAX LAX network Aeroflot" | |
[[(LAX, Aeroflot, LAX)]] | |
(airlineConnections LAX LAX network Aeroflot) | |
, TestCase $ assertEqual | |
"sort $ airlineConnections HAM MUC network Aeroflot" | |
[[(HAM, Aeroflot, DUS), (DUS, Aeroflot, FRA), (FRA, Aeroflot, MUC)], | |
[(HAM, Aeroflot, HAJ), (HAJ, Aeroflot, FRA), (FRA, Aeroflot, MUC)]] | |
(sort $ airlineConnections HAM MUC network Aeroflot) | |
, TestCase $ assertEqual | |
"airlineConnections VIE LAX network AUA" | |
[] | |
(airlineConnections VIE LAX network AUA) | |
] | |
testAllianceConnections = TestLabel "allianceConnections" $ TestList [ | |
TestCase $ assertEqual | |
"sort $ allianceConnections LAX VIE network (\\_ -> []) Aeroflot" | |
[[(LAX, Aeroflot, SFO), (SFO, Aeroflot, VIE)], | |
[(LAX, Aeroflot, TXL), (TXL, Aeroflot, VIE)]] | |
(sort $ allianceConnections LAX VIE network (\_ -> []) Aeroflot) | |
, TestCase $ assertEqual | |
"allianceConnections LAX VIE network allianceAeroflotAUA Aeroflot" | |
[[(LAX, AUA, VIE)]] | |
(allianceConnections LAX VIE network allianceAeroflotAUA Aeroflot) | |
, TestCase $ assertEqual | |
"sort $ allianceConnections VIE LAX network allianceAeroflotAUA AUA" | |
[[(VIE, Aeroflot, SFO), (SFO, Aeroflot, LAX)], | |
[(VIE, Aeroflot, TXL), (TXL, Aeroflot, LAX)]] | |
(sort $ allianceConnections VIE LAX network allianceAeroflotAUA AUA) | |
, TestCase $ assertEqual | |
"sort $ allianceConnections AUC LAX extendedNetwork allianceAll AUA" | |
[[(AUC, Aeroflot, LAX)], [(AUC, KLM, LAX)]] | |
(sort $ allianceConnections AUC LAX extendedNetwork allianceAll AUA) | |
, TestCase $ assertEqual | |
"sort $ allianceConnections LAX AUC extendedNetwork allianceAll AUA" | |
[[(LAX, Aeroflot, AUC)]] | |
(sort $ allianceConnections LAX AUC extendedNetwork allianceAll AUA) | |
] | |
testCheapestConnections = TestLabel "cheapestConnections" $ TestList [ | |
TestCase $ assertEqual | |
"sort $ cheapestConnections LAX VIE network" | |
[([(LAX, Aeroflot, TXL), (TXL, Aeroflot, HAM), (HAM, Aeroflot, HAJ), | |
(HAJ, Aeroflot, FRA), (FRA, Aeroflot, VIE)], nat8), | |
([(LAX, Aeroflot, TXL), (TXL, Aeroflot, VIE)], nat8)] | |
(sort $ cheapestConnections LAX VIE network) | |
, TestCase $ assertEqual | |
"cheapestConnections LAX LAX noFlyZone" | |
[] | |
(cheapestConnections LAX LAX noFlyZone) | |
, TestCase $ assertEqual | |
"cheapestConnections LAX VIE extendedNetwork" | |
[([(LAX, KLM, HAM), (HAM, Aeroflot, HAJ), (HAJ, Aeroflot, FRA), | |
(FRA, Aeroflot, VIE)], nat4)] | |
(cheapestConnections LAX VIE extendedNetwork) | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment