diff options
| author | Gregor Kleen <gkleen@yggdrasil.li> | 2016-02-18 21:59:00 +0000 |
|---|---|---|
| committer | Gregor Kleen <gkleen@yggdrasil.li> | 2016-02-18 21:59:00 +0000 |
| commit | 55074a07fdb847749e4f57c6c2eac4ffab1d48b6 (patch) | |
| tree | 5cd211775cf84fffa934a17ce276be2d6b3990f6 /server/src/Thermoprint/Server | |
| parent | 2d16ad6786e6047fc61b34e6bd7e59e794a9d5a3 (diff) | |
| download | thermoprint-55074a07fdb847749e4f57c6c2eac4ffab1d48b6.tar thermoprint-55074a07fdb847749e4f57c6c2eac4ffab1d48b6.tar.gz thermoprint-55074a07fdb847749e4f57c6c2eac4ffab1d48b6.tar.bz2 thermoprint-55074a07fdb847749e4f57c6c2eac4ffab1d48b6.tar.xz thermoprint-55074a07fdb847749e4f57c6c2eac4ffab1d48b6.zip | |
Api tests for Thermoprint.Server
Diffstat (limited to 'server/src/Thermoprint/Server')
| -rw-r--r-- | server/src/Thermoprint/Server/Queue.hs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/server/src/Thermoprint/Server/Queue.hs b/server/src/Thermoprint/Server/Queue.hs index cc87886..3c8fb9e 100644 --- a/server/src/Thermoprint/Server/Queue.hs +++ b/server/src/Thermoprint/Server/Queue.hs | |||
| @@ -46,6 +46,11 @@ import Data.Foldable | |||
| 46 | import Data.Monoid | 46 | import Data.Monoid |
| 47 | import Data.Ord | 47 | import Data.Ord |
| 48 | 48 | ||
| 49 | import Test.QuickCheck.Arbitrary (Arbitrary(..), CoArbitrary(..)) | ||
| 50 | import Test.QuickCheck.Gen (Gen, scale) | ||
| 51 | import Test.QuickCheck.Instances | ||
| 52 | import Test.QuickCheck.Modifiers | ||
| 53 | |||
| 49 | -- | Zipper for 'Seq QueueEntry' with additional support for 'PrintingError' in the section after point | 54 | -- | Zipper for 'Seq QueueEntry' with additional support for 'PrintingError' in the section after point |
| 50 | data Queue = Queue | 55 | data Queue = Queue |
| 51 | { pending :: Seq QueueEntry -- ^ Pending jobs, closest last | 56 | { pending :: Seq QueueEntry -- ^ Pending jobs, closest last |
| @@ -54,6 +59,14 @@ data Queue = Queue | |||
| 54 | } | 59 | } |
| 55 | deriving (Typeable, Generic, NFData, Show) | 60 | deriving (Typeable, Generic, NFData, Show) |
| 56 | 61 | ||
| 62 | instance Arbitrary Queue where | ||
| 63 | arbitrary = Queue | ||
| 64 | <$> scale (`div` 2) arbitrary | ||
| 65 | <*> arbitrary | ||
| 66 | <*> scale (`div` 2) arbitrary | ||
| 67 | |||
| 68 | instance CoArbitrary Queue | ||
| 69 | |||
| 57 | class HasQueue a where | 70 | class HasQueue a where |
| 58 | extractQueue :: a -> TVar Queue | 71 | extractQueue :: a -> TVar Queue |
| 59 | 72 | ||
| @@ -73,6 +86,12 @@ data QueueEntry = QueueEntry | |||
| 73 | } | 86 | } |
| 74 | deriving (Typeable, Generic, NFData, Eq, Ord, Show) | 87 | deriving (Typeable, Generic, NFData, Eq, Ord, Show) |
| 75 | 88 | ||
| 89 | instance Arbitrary QueueEntry where | ||
| 90 | arbitrary = QueueEntry <$> (fromIntegral . getNonNegative <$> (arbitrary :: Gen (NonNegative Integer))) <*> arbitrary | ||
| 91 | |||
| 92 | instance CoArbitrary QueueEntry where | ||
| 93 | coarbitrary QueueEntry{..} = coarbitrary created . coarbitrary (fromIntegral jobId :: Integer) | ||
| 94 | |||
| 76 | data QueueItem = Pending Int QueueEntry | Current QueueEntry | History Int QueueEntry (Maybe PrintingError) | 95 | data QueueItem = Pending Int QueueEntry | Current QueueEntry | History Int QueueEntry (Maybe PrintingError) |
| 77 | 96 | ||
| 78 | instance Eq QueueItem where | 97 | instance Eq QueueItem where |
