-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #130 from msakai/feature/graph-clique
Add isCliqueOf and complementGraph to ToySolver.Graph.Base
- Loading branch information
Showing
5 changed files
with
87 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{-# OPTIONS_GHC -Wall -fno-warn-orphans #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
{-# LANGUAGE TemplateHaskell #-} | ||
{-# LANGUAGE TupleSections #-} | ||
module Test.Graph (graphTestGroup) where | ||
|
||
import Control.Monad | ||
import Data.Array | ||
import Data.IntSet (IntSet) | ||
import qualified Data.IntSet as IntSet | ||
import Test.Tasty | ||
import Test.Tasty.QuickCheck | ||
import Test.Tasty.TH | ||
|
||
import ToySolver.Graph.Base | ||
|
||
|
||
-- ------------------------------------------------------------------------ | ||
|
||
arbitrarySimpleGraph :: Gen Graph | ||
arbitrarySimpleGraph = do | ||
sized $ \n -> do | ||
m <- choose (0, n*n-1) | ||
fmap (graphFromUnorderedEdges n) $ replicateM m $ do | ||
node1 <- choose (0, n-1) | ||
node2 <- fmap (\i -> (node1 + i) `mod` n) $ choose (1, n-1) | ||
return (node1, node2, ()) | ||
|
||
vertexes :: EdgeLabeledGraph a -> IntSet | ||
vertexes = IntSet.fromAscList . uncurry enumFromTo . bounds | ||
|
||
arbitrarySubset :: IntSet -> Gen IntSet | ||
arbitrarySubset = fmap IntSet.fromAscList . sublistOf . IntSet.toAscList | ||
|
||
-- ------------------------------------------------------------------------ | ||
|
||
prop_indepndent_set_and_clique :: Property | ||
prop_indepndent_set_and_clique = | ||
forAll arbitrarySimpleGraph $ \g -> | ||
forAll (arbitrarySubset (vertexes g)) $ \s -> do | ||
counterexample (show (graphToUnorderedEdges g)) $ | ||
s `isIndependentSetOf` g === s `isCliqueOf` complementSimpleGraph g | ||
|
||
-- ------------------------------------------------------------------------ | ||
-- Test harness | ||
|
||
graphTestGroup :: TestTree | ||
graphTestGroup = $(testGroupGenerator) |
This file contains 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
This file contains 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