1-----------------------------------------------------------------------------
2-- |
3-- Module     : Algebra.Graph.Test.Undirected
4-- Copyright  : (c) Andrey Mokhov 2016-2020
5-- License    : MIT (see the file LICENSE)
6-- Maintainer : andrey.mokhov@gmail.com
7-- Stability  : experimental
8--
9-- Testsuite for "Algebra.Graph.Undirected".
10-----------------------------------------------------------------------------
11module Algebra.Graph.Test.Undirected (
12    -- * Testsuite
13    testUndirected
14    ) where
15
16import Algebra.Graph.Undirected
17import Algebra.Graph.Test
18import Algebra.Graph.Test.API (toIntAPI, undirectedGraphAPI)
19import Algebra.Graph.Test.Generic
20
21import qualified Algebra.Graph as G
22import qualified Algebra.Graph.Undirected as U
23
24tPoly :: Testsuite Graph Ord
25tPoly = ("Graph.Undirected.", undirectedGraphAPI)
26
27t :: TestsuiteInt Graph
28t = fmap toIntAPI tPoly
29
30type G = Graph Int
31type UGI = U.Graph Int
32type AGI = G.Graph Int
33
34testUndirected :: IO ()
35testUndirected = do
36    putStrLn "\n============ Graph.Undirected ============"
37    test "Axioms of undirected graphs" $ size10 $ undirectedAxioms @ G
38
39    testSymmetricShow t
40
41    putStrLn $ "\n============ Graph.Undirected.toUndirected ============"
42    test "toUndirected (edge 1 2)         == edge 1 2" $
43          toUndirected (G.edge 1 2)       == edge 1 (2 :: Int)
44
45    test "toUndirected . fromUndirected   == id" $ \(x :: G) ->
46          (toUndirected . fromUndirected) x == id x
47
48    test "vertexCount      . toUndirected == vertexCount" $ \(x :: AGI) ->
49          vertexCount (toUndirected x) == G.vertexCount x
50
51    test "(*2) . edgeCount . toUndirected >= edgeCount" $ \(x :: AGI) ->
52          ((*2) . edgeCount . toUndirected) x >= G.edgeCount x
53
54    putStrLn $ "\n============ Graph.Undirected.fromUndirected ============"
55    test "fromUndirected (edge 1 2)    == edges [(1,2),(2,1)]" $
56          fromUndirected (edge 1 2)    == G.edges [(1,2), (2,1 :: Int)]
57
58    test "toUndirected . fromUndirected == id" $ \(x :: G) ->
59          (toUndirected . fromUndirected) x == id x
60
61    test "vertexCount . fromUndirected == vertexCount" $ \(x :: G) ->
62          (G.vertexCount . fromUndirected) x == vertexCount x
63
64    test "edgeCount   . fromUndirected <= (*2) . edgeCount" $ \(x :: G) ->
65          (G.edgeCount . fromUndirected) x <= ((*2) . edgeCount) x
66
67    putStrLn $ "\n============ Graph.Undirected.complement ================"
68    test "complement empty              == empty" $
69          complement (empty :: UGI)     == empty
70
71    test "complement (vertex x)         == vertex x" $ \x ->
72          complement (vertex x :: UGI)  == vertex x
73
74    test "complement (edge 1 1)         == edge 1 1" $
75          complement (edge 1 1)         == edge 1 (1 :: Int)
76
77    test "complement (edge 1 2)         == vertices [1, 2]" $
78          complement (edge 1 2 :: UGI)  == vertices [1, 2]
79
80    test "complement (star 1 [2, 3])    == overlay (vertex 1) (edge 2 3)" $
81          complement (star 1 [2, 3])    == overlay (vertex 1) (edge 2 3 :: UGI)
82
83    test "complement . complement       == id" $ \(x :: UGI) ->
84         (complement . complement $ x)  == x
85
86    testSymmetricBasicPrimitives t
87    testSymmetricIsSubgraphOf    t
88    testSymmetricGraphFamilies   t
89    testSymmetricTransformations t
90    testInduceJust               tPoly
91