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