From 34924012e69f77b50b95c0a80d1822c8ea3cf593 Mon Sep 17 00:00:00 2001 From: Tim Makarios Date: Fri, 4 Apr 2014 17:13:41 +1300 Subject: [PATCH] Test if a ValueSimplex is empty --- Test/ValueSimplex.hs | 5 +++++ ValueSimplex.hs | 3 +++ 2 files changed, 8 insertions(+) diff --git a/Test/ValueSimplex.hs b/Test/ValueSimplex.hs index 54e64e4..f28d0ab 100644 --- a/Test/ValueSimplex.hs +++ b/Test/ValueSimplex.hs @@ -91,6 +91,10 @@ prop_nodes_fromFunction_Double :: (Arbitrary a, CoArbitrary a, Ord a, Show a) => Blind (a -> a -> Double) -> Property prop_nodes_fromFunction_Double = nodes_fromFunction +prop_empty :: (Arbitrary a, CoArbitrary a, Ord a, Show a) + => Blind (a -> a -> Double) -> Bool +prop_empty (Blind f) = isEmpty $ fromFunction f Set.empty + -------------------------------------------------------------------------------- fromFunction_vsLookup :: (Ord a, Eq b, Num b) => ValueSimplex a b -> Bool @@ -108,6 +112,7 @@ exact_ValueSimplex_validity_tests = testList [ printTestCase "fromFunction_vsLookup" . fromFunction_vsLookup , printTestCase "values_positive" . values_positive , printTestCase "non_degenerate" . non_degenerate + , printTestCase "non-empty" . not . isEmpty ] prop_exact_ValueSimplex_validity_tests_Double :: (Ord a, Show a) diff --git a/ValueSimplex.hs b/ValueSimplex.hs index 4860215..cf61930 100644 --- a/ValueSimplex.hs +++ b/ValueSimplex.hs @@ -26,6 +26,9 @@ data VSStatus nodes :: Ord a => ValueSimplex a b -> Set a nodes vs = Set.map fst $ Map.keysSet $ vsMap vs +isEmpty :: Ord a => ValueSimplex a b -> Bool +isEmpty = Set.null . nodes + pairUp :: a -> b -> (a, b) pairUp = curry id -- 2.11.4.GIT