Commit 50d199ba authored by Alfredo Di Napoli's avatar Alfredo Di Napoli

Add proper Arbitrary instances for Phylo

parent 14fa1393
...@@ -40,6 +40,7 @@ import Gargantext.Core.Utils.Prefix (unPrefixSwagger) ...@@ -40,6 +40,7 @@ import Gargantext.Core.Utils.Prefix (unPrefixSwagger)
import Gargantext.Prelude import Gargantext.Prelude
import Test.QuickCheck import Test.QuickCheck
import Test.QuickCheck.Instances.Text() import Test.QuickCheck.Instances.Text()
import Test.QuickCheck.Instances.Vector()
--------------------- ---------------------
-- | PhyloConfig | -- -- | PhyloConfig | --
...@@ -311,6 +312,8 @@ data Software = ...@@ -311,6 +312,8 @@ data Software =
instance ToSchema Software where instance ToSchema Software where
declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_software_") declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_software_")
instance Arbitrary Software where
arbitrary = pure defaultSoftware
...@@ -330,8 +333,6 @@ data PhyloParam = ...@@ -330,8 +333,6 @@ data PhyloParam =
instance ToSchema PhyloParam where instance ToSchema PhyloParam where
declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_phyloParam_") declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_phyloParam_")
defaultPhyloParam :: PhyloParam defaultPhyloParam :: PhyloParam
defaultPhyloParam = defaultPhyloParam =
PhyloParam { _phyloParam_version = pack "v3" PhyloParam { _phyloParam_version = pack "v3"
...@@ -376,6 +377,9 @@ data PhyloFoundations = PhyloFoundations ...@@ -376,6 +377,9 @@ data PhyloFoundations = PhyloFoundations
, _foundations_rootsInGroups :: Map Int [PhyloGroupId] -- map of roots associated to groups , _foundations_rootsInGroups :: Map Int [PhyloGroupId] -- map of roots associated to groups
} deriving (Generic, Show, Eq, ToExpr) } deriving (Generic, Show, Eq, ToExpr)
instance Arbitrary PhyloFoundations where
arbitrary = PhyloFoundations <$> arbitrary <*> arbitrary
data PhyloCounts = PhyloCounts data PhyloCounts = PhyloCounts
{ coocByDate :: !(Map Date Cooc) { coocByDate :: !(Map Date Cooc)
, docsByDate :: !(Map Date Double) , docsByDate :: !(Map Date Double)
...@@ -394,6 +398,15 @@ instance ToSchema PhyloCounts where ...@@ -394,6 +398,15 @@ instance ToSchema PhyloCounts where
declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_") declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_")
instance ToSchema PhyloSources where instance ToSchema PhyloSources where
declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_") declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_")
instance Arbitrary PhyloCounts where
arbitrary = PhyloCounts <$> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
instance Arbitrary PhyloSources where
arbitrary = PhyloSources <$> arbitrary
--------------------------- ---------------------------
-- | Coocurency Matrix | -- -- | Coocurency Matrix | --
...@@ -454,6 +467,9 @@ data PhyloPeriod = ...@@ -454,6 +467,9 @@ data PhyloPeriod =
instance ToSchema PhyloPeriod where instance ToSchema PhyloPeriod where
declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_phylo_") declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_phylo_")
instance Arbitrary PhyloPeriod where
arbitrary = PhyloPeriod <$> arbitrary <*> arbitrary <*> arbitrary
--------------- ---------------
-- | Scale | -- -- | Scale | --
...@@ -476,6 +492,8 @@ data PhyloScale = ...@@ -476,6 +492,8 @@ data PhyloScale =
instance ToSchema PhyloScale where instance ToSchema PhyloScale where
declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_phylo_") declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_phylo_")
instance Arbitrary PhyloScale where
arbitrary = PhyloScale <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary
type PhyloGroupId = (PhyloScaleId, Int) type PhyloGroupId = (PhyloScaleId, Int)
...@@ -511,7 +529,28 @@ data PhyloGroup = ...@@ -511,7 +529,28 @@ data PhyloGroup =
instance ToSchema PhyloGroup where instance ToSchema PhyloGroup where
declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_phylo_") declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_phylo_")
instance Arbitrary PhyloGroup where
arbitrary = PhyloGroup <$> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
-- | Weight : A generic mesure that can be associated with an Id -- | Weight : A generic mesure that can be associated with an Id
type Weight = Double type Weight = Double
...@@ -757,3 +796,6 @@ instance Arbitrary Order where ...@@ -757,3 +796,6 @@ instance Arbitrary Order where
instance Arbitrary Filter where instance Arbitrary Filter where
arbitrary = ByBranchSize <$> arbitrary arbitrary = ByBranchSize <$> arbitrary
instance Arbitrary PhyloParam where
arbitrary = pure defaultPhyloParam
...@@ -39,7 +39,6 @@ import Gargantext.Prelude ...@@ -39,7 +39,6 @@ import Gargantext.Prelude
import Network.HTTP.Media ((//), (/:)) import Network.HTTP.Media ((//), (/:))
import Prelude qualified import Prelude qualified
import Servant import Servant
import Test.QuickCheck (elements)
import Test.QuickCheck.Arbitrary (Arbitrary, arbitrary) import Test.QuickCheck.Arbitrary (Arbitrary, arbitrary)
import Web.HttpApiData (readTextData) import Web.HttpApiData (readTextData)
import Gargantext.Database.Query.Table.Node.Error import Gargantext.Database.Query.Table.Node.Error
...@@ -195,10 +194,6 @@ putPhylo = undefined ...@@ -195,10 +194,6 @@ putPhylo = undefined
-- | Instances -- | Instances
-- instance Arbitrary Phylo where arbitrary = elements [phylo]
instance Arbitrary PhyloGroup where arbitrary = elements []
-- instance Arbitrary PhyloView where arbitrary = elements [phyloView]
-- instance Arbitrary PhyloConfig where arbitrary = elements []
instance FromHttpApiData DisplayMode where parseUrlPiece = readTextData instance FromHttpApiData DisplayMode where parseUrlPiece = readTextData
instance FromHttpApiData ExportMode where parseUrlPiece = readTextData instance FromHttpApiData ExportMode where parseUrlPiece = readTextData
instance FromHttpApiData Filiation where parseUrlPiece = readTextData instance FromHttpApiData Filiation where parseUrlPiece = readTextData
......
...@@ -20,7 +20,6 @@ import Control.Concurrent ...@@ -20,7 +20,6 @@ import Control.Concurrent
import Control.Concurrent.Async import Control.Concurrent.Async
import Control.Concurrent.Async qualified as Async import Control.Concurrent.Async qualified as Async
import Control.Concurrent.STM import Control.Concurrent.STM
import Data.List (isInfixOf)
import Data.Sequence ((|>), fromList) import Data.Sequence ((|>), fromList)
import Data.Time import Data.Time
import Debug.RecoverRTTI (anythingToString) import Debug.RecoverRTTI (anythingToString)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment