forked from tuura/pangraph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraphML.hs
55 lines (48 loc) · 1.83 KB
/
GraphML.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
{-# LANGUAGE OverloadedStrings #-}
module GraphML (
graphmlTests
) where
import Test.HUnit
import Data.Maybe
import Pangraph
import Pangraph.GraphML.Parser
import Pangraph.GraphML.Writer
graphmlTests :: [Test]
graphmlTests = [case1, case2]
case1 :: Test
case1 =
let
file = parse "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \
\<graphml xmlns=\"http://graphml.graphdrawing.org/xmlns\"\
\ xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\
\ xsi:schemaLocation=\"http://graphml.graphdrawing.org/xmlns\
\ http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd\">\
\ <graph id=\"G\" edgedefault=\"undirected\">\
\ <node id=\"n0\"/>\
\ <node id=\"n1\"/>\
\ <node id=\"n2\"/>\
\ <edge id=\"e1\" source=\"n0\" target=\"n2\"/>\
\ </graph>\
\</graphml>"
sampleVertices = [
makeVertex "n0" [ ("id","n0")],
makeVertex "n1" [ ("id","n1")],
makeVertex "n2" [ ("id","n2")]]
graph = makePangraph sampleVertices
[makeEdge
[("source","n0"),("target","n2")]
(head sampleVertices, sampleVertices !! 2)]
in TestCase $ assertEqual "GraphML Parse case 1" (graph :: Maybe Pangraph) file
case2 :: Test
case2 =
let
sampleVertices = [
makeVertex "n0" [ ("id","n0")],
makeVertex "n1" [ ("id","n1")],
makeVertex "n2" [ ("id","n2")]]
graph = makePangraph sampleVertices
[makeEdge
[("source","n0"),("target","n2")]
(head sampleVertices, sampleVertices !! 2)]
justGraph = fromMaybe (error "Sample graph failed to compile") graph
in TestCase $ assertEqual "GraphML Write case 1" (graph :: Maybe Pangraph) (parse $ write justGraph)