graph-wrapper 0.2.5.2 → 0.2.6.0
raw patch · 3 files changed
+38/−1 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Data.Graph.Wrapper.Internal: instance (GHC.Classes.Ord i, GHC.Classes.Eq v) => GHC.Classes.Eq (Data.Graph.Wrapper.Internal.Graph i v)
Files
- graph-wrapper.cabal +1/−1
- src/Data/Graph/Wrapper/Internal.hs +6/−0
- test/Data/Graph/WrapperSpec.hs +31/−0
graph-wrapper.cabal view
@@ -1,7 +1,7 @@ Cabal-Version: >= 1.8 Build-Type: Simple Name: graph-wrapper-Version: 0.2.5.2+Version: 0.2.6.0 Maintainer: Max Bolingbroke <batterseapower@hotmail.com>, Sönke Hahn <soenkehahn@gmail.com> Homepage: https://github.com/soenkehahn/graph-wrapper License: BSD3
src/Data/Graph/Wrapper/Internal.hs view
@@ -11,6 +11,7 @@ #endif import Data.Array+import Data.List (sort) import Data.Maybe (fromMaybe) import qualified Data.Graph as G @@ -32,6 +33,11 @@ indexGVertexArray :: Array G.Vertex i, gVertexVertexArray :: Array G.Vertex v }++instance (Ord i, Eq v) => Eq (Graph i v) where+ g1 == g2 = fmap sort (graph g1) == fmap sort (graph g2)+ && indexGVertexArray g1 == indexGVertexArray g2+ && gVertexVertexArray g1 == gVertexVertexArray g2 instance (Ord i, Show i, Show v) => Show (Graph i v) where show g = "fromVerticesEdges " ++ show ([(i, vertex g i) | i <- vertices g]) ++ " " ++ show (edges g)
test/Data/Graph/WrapperSpec.hs view
@@ -21,3 +21,34 @@ it "returns the empty list" $ do reachableVertices (fromList [] :: Graph Integer ()) 0 `shouldBe` []++ describe "Eq Graph" $ do+ context "when the graphs are identical" $ do+ it "returns True" $ do+ let g1 = fromList [('a', 'a', ['a', 'b', 'c']), ('b', 'b', ['b', 'c']), ('c', 'c', ['a'])]+ let g2 = fromList [('a', 'a', ['a', 'b', 'c']), ('b', 'b', ['b', 'c']), ('c', 'c', ['a'])]+ g1 == g2 `shouldBe` True++ context "when the graphs are isomorphic" $ do+ it "returns False" $ do+ let g1 = fromList [('1', 'a', ['2']), ('2', 'b', [])]+ let g2 = fromList [('2', 'a', ['1']), ('1', 'b', [])]+ g1 == g2 `shouldBe` False++ context "when the vertices are listed in a different order" $ do+ it "returns True" $ do+ let g1 = fromList [('a', 'a', ['a', 'b', 'c']), ('b', 'b', ['b', 'c']), ('c', 'c', ['a'])]+ let g2 = fromList [('b', 'b', ['b', 'c']), ('c', 'c', ['a']), ('a', 'a', ['a', 'b', 'c'])]+ g1 == g2 `shouldBe` True++ context "when the edges are listed in a different order" $ do+ it "returns True" $ do+ let g1 = fromList [('a', 'a', ['a', 'b', 'c']), ('b', 'b', ['b', 'c']), ('c', 'c', ['a'])]+ let g2 = fromList [('a', 'a', ['b', 'c', 'a']), ('b', 'b', ['c', 'b']), ('c', 'c', ['a'])]+ g1 == g2 `shouldBe` True++ context "when the graphs are different" $ do+ it "returns False" $ do+ let g1 = fromList [('a', 'a', ['a', 'b', 'c']), ('b', 'b', ['b', 'c']), ('c', 'c', ['a'])]+ let g2 = fromList [('a', 'a', ['a', 'b', 'c']), ('b', 'b', ['b', 'a']), ('c', 'c', ['a'])]+ g1 == g2 `shouldBe` False