[test] more arbitrary instances moved to tests (phylo)

parent b2f9777d
Pipeline #6991 failed with stages
in 62 minutes and 50 seconds
{-# OPTIONS_GHC -Wno-orphans #-} --instance ToSchema Value {-|
Module : Gargantext.API.Viz.Types
Description :
Copyright : (c) CNRS, 2017-Present
License : AGPL + CECILL v3
Maintainer : team@gargantext.org
Stability : experimental
Portability : POSIX
-}
{-# OPTIONS_GHC -Wno-orphans #-}
module Gargantext.API.Viz.Types ( module Gargantext.API.Viz.Types (
SVG(..) SVG(..)
, PhyloData(..) , PhyloData(..)
) where ) where
import Data.Aeson import Data.Aeson ((.=), (.:), Value, object, withObject)
import Gargantext.Core.Viz.Phylo (PhyloConfig(..)) import Gargantext.Core.Viz.Phylo (PhyloConfig(..))
import Data.ByteString qualified as DB import Data.ByteString qualified as DB
import Data.ByteString.Lazy qualified as DBL import Data.ByteString.Lazy qualified as DBL
import Data.Swagger import Data.Swagger (ToSchema(..))
import Gargantext.Core.Types (TODO(..)) import Gargantext.Core.Types (TODO(..))
import Gargantext.Core.Types.Phylo (GraphData(..)) import Gargantext.Core.Types.Phylo (GraphData(..))
import Gargantext.Database.Admin.Types.Node -- (PhyloId, ListId, CorpusId, UserId, NodeId(..)) import Gargantext.Database.Admin.Types.Node -- (PhyloId, ListId, CorpusId, UserId, NodeId(..))
import Gargantext.Prelude import Gargantext.Prelude
import Network.HTTP.Media ((//), (/:)) import Network.HTTP.Media ((//), (/:))
import Prelude qualified
import Servant import Servant
import Test.QuickCheck.Arbitrary (Arbitrary, arbitrary)
newtype SVG = SVG DB.ByteString newtype SVG = SVG DB.ByteString
deriving (Show, Generic)
--instance Show a => MimeRender PlainText a where mimeRender _ val = cs ("" <> show val) --instance Show a => MimeRender PlainText a where mimeRender _ val = cs ("" <> show val)
instance Accept SVG where contentType _ = "SVG" // "image/svg+xml" /: ("charset", "utf-8") instance Accept SVG where contentType _ = "SVG" // "image/svg+xml" /: ("charset", "utf-8")
instance MimeRender SVG SVG where mimeRender _ (SVG s) = DBL.fromStrict s instance MimeRender SVG SVG where mimeRender _ (SVG s) = DBL.fromStrict s
instance MimeUnrender SVG SVG where mimeUnrender _ lbs = Right $ SVG (DBL.toStrict lbs) instance MimeUnrender SVG SVG where mimeUnrender _ lbs = Right $ SVG (DBL.toStrict lbs)
instance Prelude.Show SVG where show (SVG a) = show a
instance ToSchema SVG where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy TODO) instance ToSchema SVG where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy TODO)
------------------------------------------------------------------------ ------------------------------------------------------------------------
...@@ -58,8 +68,5 @@ instance FromJSON PhyloData where ...@@ -58,8 +68,5 @@ instance FromJSON PhyloData where
pd_config <- o .: "pd_config" pd_config <- o .: "pd_config"
pure $ PhyloData{..} pure $ PhyloData{..}
instance Arbitrary PhyloData where
arbitrary = PhyloData <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary
instance ToSchema PhyloData instance ToSchema PhyloData
...@@ -22,27 +22,24 @@ one 8, e54847. ...@@ -22,27 +22,24 @@ one 8, e54847.
-} -}
{-# LANGUAGE DeriveAnyClass #-} {-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE DerivingStrategies #-} {-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeApplications #-}
module Gargantext.Core.Viz.Phylo where module Gargantext.Core.Viz.Phylo where
import Control.Lens (over) import Control.Lens (over)
import Data.Swagger import Data.Aeson.Types qualified as JS
import Data.Text.Lazy qualified as TextLazy import Data.List.NonEmpty qualified as NE
import Data.Swagger (ToSchema(..), genericDeclareNamedSchema)
import Data.Text (pack) import Data.Text (pack)
import Data.Text.Lazy qualified as TextLazy
import Data.TreeDiff (ToExpr (..)) import Data.TreeDiff (ToExpr (..))
import Data.Vector (Vector) import Data.Vector (Vector)
import Gargantext.Core.Utils.Prefix (unPrefix, unPrefixSwagger) import Gargantext.Core.Utils.Prefix (unPrefix, unPrefixSwagger)
import Gargantext.Prelude import Gargantext.Prelude
import Gargantext.Utils.UTCTime (ElapsedSeconds) import Gargantext.Utils.UTCTime (ElapsedSeconds)
import qualified Data.Aeson.Types as JS
import qualified Data.List.NonEmpty as NE
import Test.QuickCheck
import Test.QuickCheck.Instances.Text()
import Test.QuickCheck.Instances.Vector()
--------------------- ---------------------
-- | PhyloConfig | -- -- | PhyloConfig | --
...@@ -314,10 +311,6 @@ data Software = ...@@ -314,10 +311,6 @@ 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
defaultSoftware :: Software defaultSoftware :: Software
defaultSoftware = defaultSoftware =
...@@ -325,6 +318,8 @@ defaultSoftware = ...@@ -325,6 +318,8 @@ defaultSoftware =
, _software_version = pack "v5" } , _software_version = pack "v5" }
-- | Global parameters of a Phylo -- | Global parameters of a Phylo
data PhyloParam = data PhyloParam =
PhyloParam { _phyloParam_version :: Text PhyloParam { _phyloParam_version :: Text
...@@ -335,13 +330,13 @@ data PhyloParam = ...@@ -335,13 +330,13 @@ 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"
, _phyloParam_software = defaultSoftware , _phyloParam_software = defaultSoftware
, _phyloParam_config = defaultConfig } , _phyloParam_config = defaultConfig }
------------------ ------------------
-- | Document | -- -- | Document | --
------------------ ------------------
...@@ -379,9 +374,6 @@ data PhyloFoundations = PhyloFoundations ...@@ -379,9 +374,6 @@ 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)
...@@ -400,15 +392,6 @@ instance ToSchema PhyloCounts where ...@@ -400,15 +392,6 @@ 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 | --
...@@ -481,8 +464,6 @@ data PhyloPeriod = ...@@ -481,8 +464,6 @@ 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
--------------- ---------------
...@@ -506,8 +487,6 @@ data PhyloScale = ...@@ -506,8 +487,6 @@ 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)
...@@ -543,28 +522,6 @@ data PhyloGroup = ...@@ -543,28 +522,6 @@ 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
...@@ -744,104 +701,6 @@ instance NFData Sort ...@@ -744,104 +701,6 @@ instance NFData Sort
instance NFData Tagger instance NFData Tagger
instance NFData PhyloLabel instance NFData PhyloLabel
-- Arbitrary instances
instance Arbitrary PhyloConfig where
arbitrary = PhyloConfig <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary
<*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary
<*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary
<*> vectorOf 10 arbitrary <*> arbitrary <*> vectorOf 10 arbitrary
instance Arbitrary CorpusParser where
arbitrary = oneof [ Wos <$> arbitrary
, Tsv <$> arbitrary
, Tsv' <$> arbitrary
, Csv <$> arbitrary
, Csv' <$> arbitrary
]
instance Arbitrary ListParser where
arbitrary = elements [V3, V4]
instance Arbitrary PhyloSimilarity where
arbitrary = oneof [ WeightedLogJaccard <$> arbitrary <*> arbitrary
, WeightedLogSim <$> arbitrary <*> arbitrary
, Hamming <$> arbitrary <*> arbitrary
]
instance Arbitrary SeaElevation where
arbitrary = oneof [ Constante <$> arbitrary <*> arbitrary
, Adaptative <$> arbitrary
, Evolving <$> arbitrary
]
instance Arbitrary Synchrony where
arbitrary = oneof [ ByProximityThreshold <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary
, ByProximityDistribution <$> arbitrary <*> arbitrary
]
instance Arbitrary SynchronyScope where
arbitrary = elements [SingleBranch, SiblingBranches, AllBranches]
instance Arbitrary SynchronyStrategy where
arbitrary = elements [MergeRegularGroups, MergeAllGroups]
instance Arbitrary Quality where
arbitrary = Quality <$> arbitrary <*> arbitrary
instance Arbitrary TimeUnit where
arbitrary = oneof [ Epoch <$> arbitrary <*> arbitrary <*> arbitrary
, Year <$> arbitrary <*> arbitrary <*> arbitrary
, Month <$> arbitrary <*> arbitrary <*> arbitrary
, Week <$> arbitrary <*> arbitrary <*> arbitrary
, Day <$> arbitrary <*> arbitrary <*> arbitrary
]
instance Arbitrary Cluster where
arbitrary = oneof [ Fis <$> arbitrary <*> arbitrary
, MaxClique <$> arbitrary <*> arbitrary <*> arbitrary
]
instance Arbitrary MaxCliqueFilter where
arbitrary = elements [ByThreshold, ByNeighbours]
instance Arbitrary PhyloLabel where
arbitrary = oneof [ BranchLabel <$> arbitrary <*> arbitrary
, GroupLabel <$> arbitrary <*> arbitrary
]
instance Arbitrary Tagger where
arbitrary = elements [MostInclusive, MostEmergentInclusive, MostEmergentTfIdf]
instance Arbitrary Sort where
arbitrary = oneof [ ByBirthDate <$> arbitrary
, ByHierarchy <$> arbitrary]
instance Arbitrary Order where
arbitrary = elements [Asc, Desc]
instance Arbitrary Filter where
arbitrary = ByBranchSize <$> arbitrary
instance Arbitrary PhyloParam where
arbitrary = pure defaultPhyloParam
instance Arbitrary ComputeTimeHistory where
arbitrary = oneof [ ComputeTimeHistory . NE.fromList . getNonEmpty <$> arbitrary ]
-- The 'resize' ensure our tests won't take too long as
-- we won't be generating very long lists.
instance Arbitrary Phylo where
arbitrary = Phylo <$> resize 6 arbitrary
<*> resize 6 arbitrary
<*> resize 6 arbitrary
<*> resize 6 arbitrary
<*> resize 6 arbitrary
<*> resize 6 arbitrary
<*> resize 6 arbitrary
<*> resize 6 arbitrary
<*> resize 6 arbitrary
-- --
-- Functions that uses the lenses -- Functions that uses the lenses
-- --
......
...@@ -38,11 +38,12 @@ import Gargantext.API.Node.New.Types (PostNode(..)) ...@@ -38,11 +38,12 @@ import Gargantext.API.Node.New.Types (PostNode(..))
import Gargantext.API.Node.Share.Types (ShareNodeParams(..)) import Gargantext.API.Node.Share.Types (ShareNodeParams(..))
import Gargantext.API.Node.Update.Types qualified as NU import Gargantext.API.Node.Update.Types qualified as NU
import Gargantext.API.Node.Types (NewWithForm, RenameNode(..), WithQuery) import Gargantext.API.Node.Types (NewWithForm, RenameNode(..), WithQuery)
import Gargantext.API.Viz.Types (PhyloData)
import Gargantext.Core.Notifications.CentralExchange.Types qualified as CET import Gargantext.Core.Notifications.CentralExchange.Types qualified as CET
import Gargantext.Core.Notifications.Dispatcher.Types qualified as DET import Gargantext.Core.Notifications.Dispatcher.Types qualified as DET
import Gargantext.Core.Types.Individu qualified as Individu import Gargantext.Core.Types.Individu qualified as Individu
import Gargantext.Core.Types.Main (ListType(CandidateTerm, StopTerm, MapTerm)) import Gargantext.Core.Types.Main (ListType(CandidateTerm, StopTerm, MapTerm))
import Gargantext.Core.Viz.Phylo (PhyloSubConfigAPI) import Gargantext.Core.Viz.Phylo qualified as Phylo
import Gargantext.Core.Worker.Jobs.Types (Job(..)) import Gargantext.Core.Worker.Jobs.Types (Job(..))
import Gargantext.Database.Admin.Types.Hyperdata qualified as Hyperdata import Gargantext.Database.Admin.Types.Hyperdata qualified as Hyperdata
import Gargantext.Database.Admin.Types.Node (NodeId(..), UserId(..), NodeType(..)) import Gargantext.Database.Admin.Types.Node (NodeId(..), UserId(..), NodeType(..))
...@@ -53,6 +54,8 @@ import Text.Parsec.Error (ParseError, Message(..), newErrorMessage) ...@@ -53,6 +54,8 @@ import Text.Parsec.Error (ParseError, Message(..), newErrorMessage)
import Text.Parsec.Pos import Text.Parsec.Pos
import Test.QuickCheck import Test.QuickCheck
import Test.QuickCheck.Arbitrary.Generic import Test.QuickCheck.Arbitrary.Generic
import Test.QuickCheck.Instances.Text ()
import Test.QuickCheck.Instances.Vector ()
instance Arbitrary AuthenticatedUser where arbitrary = genericArbitrary instance Arbitrary AuthenticatedUser where arbitrary = genericArbitrary
...@@ -143,7 +146,71 @@ instance Arbitrary ShareNodeParams where ...@@ -143,7 +146,71 @@ instance Arbitrary ShareNodeParams where
, SharePublicParams (UnsafeMkNodeId 1) , SharePublicParams (UnsafeMkNodeId 1)
] ]
instance Arbitrary PhyloSubConfigAPI where arbitrary = genericArbitrary -- phylo
instance Arbitrary Phylo.PhyloSubConfigAPI where arbitrary = genericArbitrary
instance Arbitrary Phylo.Software where
arbitrary = pure Phylo.defaultSoftware
instance Arbitrary Phylo.Cluster where arbitrary = genericArbitrary
instance Arbitrary Phylo.ComputeTimeHistory where
arbitrary = oneof [ Phylo.ComputeTimeHistory . NE.fromList . getNonEmpty <$> arbitrary ]
instance Arbitrary Phylo.CorpusParser where arbitrary = genericArbitrary
instance Arbitrary Phylo.Filter where arbitrary = genericArbitrary
instance Arbitrary Phylo.ListParser where arbitrary = genericArbitrary
instance Arbitrary Phylo.MaxClqueFilter where arbitrary = genericArbitrary
instance Arbitrary Phylo.Order where arbitrary = genericArbitrary
-- The 'resize' ensure our tests won't take too long as
-- we won't be generating very long lists.
instance Arbitrary Phylo.Phylo where
arbitrary = Phylo.Phylo <$> resize 6 arbitrary
<*> resize 6 arbitrary
<*> resize 6 arbitrary
<*> resize 6 arbitrary
<*> resize 6 arbitrary
<*> resize 6 arbitrary
<*> resize 6 arbitrary
<*> resize 6 arbitrary
<*> resize 6 arbitrary
instance Arbitrary Phylo.PhyloFoundations where arbitrary = genericArbitrary
instance Arbitrary Phylo.PhyloCounts where arbitrary = genericArbitrary
instance Arbitrary Phylo.PhyloGroup where arbitrary = genericArbitrary
instance Arbitrary Phylo.PhyloLabel where arbitrary = genericArbitrary
instance Arbitrary Phylo.PhyloParam where
arbitrary = Phylo.defaultPhyloParam
instance Arbitrary Phylo.PhyloPeriod where arbitrary = genericArbitrary
instance Arbitrary Phylo.PhyloScale where arbitrary = genericArbitrary
instance Arbitrary Phylo.PhyloSimilarity where arbitrary = genericArbitrary
instance Arbitrary Phylo.PhyloSources where arbitrary = genericArbitrary
instance Arbitrary Phylo.PhyloConfig where
arbitrary = Phylo.PhyloConfig <$> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> vectorOf 10 arbitrary
<*> arbitrary
<*> vectorOf 10 arbitrary
instance Arbitrary Phylo.Quality where arbitrary = genericArbitrary
instance Arbitrary Phylo.SeaElevation where arbitrary = genericArbitrary
instance Arbitrary Phylo.Sort where arbitrary = genericArbitrary
instance Arbitrary Phylo.Synchrony where arbitrary = genericArbitrary
instance Arbitrary Phylo.SynchronyScope where arbitrary = genericArbitrary
instance Arbitrary Phylo.SynchronyStrategy where arbitrary = genericArbitrary
instance Arbitrary Phylo.Tagger where arbitrary = genericArbitrary
instance Arbitrary Phylo.TimeUnit where arbitrary = genericArbitrary
instance Arbitrary PhyloData where arbitrary = genericArbitrary
instance Arbitrary NU.UpdateNodeParams where arbitrary = genericArbitrary instance Arbitrary NU.UpdateNodeParams where arbitrary = genericArbitrary
instance Arbitrary NU.Method where arbitrary = arbitraryBoundedEnum instance Arbitrary NU.Method where arbitrary = arbitraryBoundedEnum
instance Arbitrary NU.Granularity where arbitrary = arbitraryBoundedEnum instance Arbitrary NU.Granularity where arbitrary = arbitraryBoundedEnum
......
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