| 1 |
{-| Common tests for PartialParams instances |
| 2 |
|
| 3 |
-} |
| 4 |
|
| 5 |
{- |
| 6 |
|
| 7 |
Copyright (C) 2012 Google Inc. |
| 8 |
All rights reserved. |
| 9 |
|
| 10 |
Redistribution and use in source and binary forms, with or without |
| 11 |
modification, are permitted provided that the following conditions are |
| 12 |
met: |
| 13 |
|
| 14 |
1. Redistributions of source code must retain the above copyright notice, |
| 15 |
this list of conditions and the following disclaimer. |
| 16 |
|
| 17 |
2. Redistributions in binary form must reproduce the above copyright |
| 18 |
notice, this list of conditions and the following disclaimer in the |
| 19 |
documentation and/or other materials provided with the distribution. |
| 20 |
|
| 21 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
| 22 |
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
| 23 |
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 24 |
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
| 25 |
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 26 |
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 27 |
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 28 |
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 29 |
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 30 |
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 31 |
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 32 |
|
| 33 |
-} |
| 34 |
|
| 35 |
module Test.Ganeti.PartialParams |
| 36 |
( testFillParamsLaw1 |
| 37 |
, testToParamsLaw2 |
| 38 |
, testToFilledLaw3 |
| 39 |
, testToFilledMonoidLaw1 |
| 40 |
, testToFilledMonoidLaw2 |
| 41 |
) where |
| 42 |
|
| 43 |
import Data.Semigroup ((<>)) |
| 44 |
|
| 45 |
import Test.QuickCheck |
| 46 |
|
| 47 |
import Ganeti.PartialParams |
| 48 |
|
| 49 |
import Test.Ganeti.TestCommon |
| 50 |
|
| 51 |
-- | Checks for serialisation idempotence. |
| 52 |
testFillParamsLaw1 :: (PartialParams f p, Show f, Eq f) |
| 53 |
=> f -> p -> Property |
| 54 |
testFillParamsLaw1 f p = fillParams (fillParams f p) p ==? fillParams f p |
| 55 |
|
| 56 |
-- | Tests that filling partial parameters satisfies the law. |
| 57 |
testToParamsLaw2 :: (PartialParams f p, Show f, Eq f) => f -> f -> Property |
| 58 |
testToParamsLaw2 x f = fillParams x (toPartial f) ==? f |
| 59 |
|
| 60 |
-- | Tests that converting partial to filled parameters satisfies the law. |
| 61 |
testToFilledLaw3 :: (PartialParams f p, Show f, Eq f) => f -> Property |
| 62 |
testToFilledLaw3 f = toFilled (toPartial f) ==? Just f |
| 63 |
|
| 64 |
-- | Tests that the partial params behave correctly as a monoid action. |
| 65 |
testToFilledMonoidLaw1 :: (PartialParams f p, Show f, Eq f, Monoid p) |
| 66 |
=> f -> Property |
| 67 |
testToFilledMonoidLaw1 f = fillParams f mempty ==? f |
| 68 |
|
| 69 |
-- | Tests that the partial params behave correctly as a monoid action. |
| 70 |
testToFilledMonoidLaw2 :: (PartialParams f p, Show f, Eq f, Monoid p) |
| 71 |
=> f -> p -> p -> Property |
| 72 |
testToFilledMonoidLaw2 f p1 p2 = |
| 73 |
fillParams f (p1 <> p2) ==? fillParams (fillParams f p1) p2 |