root / htest / Test / Ganeti / HTools / PeerMap.hs @ e1ee7d5a
History | View | Annotate | Download (2.7 kB)
1 |
{-# LANGUAGE TemplateHaskell #-} |
---|---|
2 |
{-# OPTIONS_GHC -fno-warn-orphans #-} |
3 |
|
4 |
{-| Unittests for ganeti-htools. |
5 |
|
6 |
-} |
7 |
|
8 |
{- |
9 |
|
10 |
Copyright (C) 2009, 2010, 2011, 2012 Google Inc. |
11 |
|
12 |
This program is free software; you can redistribute it and/or modify |
13 |
it under the terms of the GNU General Public License as published by |
14 |
the Free Software Foundation; either version 2 of the License, or |
15 |
(at your option) any later version. |
16 |
|
17 |
This program is distributed in the hope that it will be useful, but |
18 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
19 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
20 |
General Public License for more details. |
21 |
|
22 |
You should have received a copy of the GNU General Public License |
23 |
along with this program; if not, write to the Free Software |
24 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
25 |
02110-1301, USA. |
26 |
|
27 |
-} |
28 |
|
29 |
module Test.Ganeti.HTools.PeerMap (testPeerMap) where |
30 |
|
31 |
import Test.QuickCheck |
32 |
|
33 |
import Test.Ganeti.TestHelper |
34 |
import Test.Ganeti.TestCommon |
35 |
|
36 |
import qualified Ganeti.HTools.PeerMap as PeerMap |
37 |
|
38 |
-- | Make sure add is idempotent. |
39 |
prop_PeerMap_addIdempotent :: PeerMap.PeerMap |
40 |
-> PeerMap.Key -> PeerMap.Elem -> Property |
41 |
prop_PeerMap_addIdempotent pmap key em = |
42 |
fn puniq ==? fn (fn puniq) |
43 |
where fn = PeerMap.add key em |
44 |
puniq = PeerMap.accumArray const pmap |
45 |
|
46 |
-- | Make sure remove is idempotent. |
47 |
prop_PeerMap_removeIdempotent :: PeerMap.PeerMap -> PeerMap.Key -> Property |
48 |
prop_PeerMap_removeIdempotent pmap key = |
49 |
fn puniq ==? fn (fn puniq) |
50 |
where fn = PeerMap.remove key |
51 |
puniq = PeerMap.accumArray const pmap |
52 |
|
53 |
-- | Make sure a missing item returns 0. |
54 |
prop_PeerMap_findMissing :: PeerMap.PeerMap -> PeerMap.Key -> Property |
55 |
prop_PeerMap_findMissing pmap key = |
56 |
PeerMap.find key (PeerMap.remove key puniq) ==? 0 |
57 |
where puniq = PeerMap.accumArray const pmap |
58 |
|
59 |
-- | Make sure an added item is found. |
60 |
prop_PeerMap_addFind :: PeerMap.PeerMap |
61 |
-> PeerMap.Key -> PeerMap.Elem -> Property |
62 |
prop_PeerMap_addFind pmap key em = |
63 |
PeerMap.find key (PeerMap.add key em puniq) ==? em |
64 |
where puniq = PeerMap.accumArray const pmap |
65 |
|
66 |
-- | Manual check that maxElem returns the maximum indeed, or 0 for null. |
67 |
prop_PeerMap_maxElem :: PeerMap.PeerMap -> Property |
68 |
prop_PeerMap_maxElem pmap = |
69 |
PeerMap.maxElem puniq ==? if null puniq then 0 |
70 |
else (maximum . snd . unzip) puniq |
71 |
where puniq = PeerMap.accumArray const pmap |
72 |
|
73 |
-- | List of tests for the PeerMap module. |
74 |
testSuite "PeerMap" |
75 |
[ 'prop_PeerMap_addIdempotent |
76 |
, 'prop_PeerMap_removeIdempotent |
77 |
, 'prop_PeerMap_maxElem |
78 |
, 'prop_PeerMap_addFind |
79 |
, 'prop_PeerMap_findMissing |
80 |
] |