Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
148
Issues
148
List
Board
Labels
Milestones
Merge Requests
7
Merge Requests
7
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
haskell-gargantext
Commits
f84d7734
Verified
Commit
f84d7734
authored
Nov 19, 2024
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[test] more arbitrary instances moved to tests (phylo)
parent
b2f9777d
Pipeline
#6991
failed with stages
in 62 minutes and 50 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
94 additions
and
161 deletions
+94
-161
Types.hs
src/Gargantext/API/Viz/Types.hs
+16
-9
Phylo.hs
src/Gargantext/Core/Viz/Phylo.hs
+9
-150
Instances.hs
test/Test/Instances.hs
+69
-2
No files found.
src/Gargantext/API/Viz/Types.hs
View file @
f84d7734
{-# 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
(
SVG
(
..
)
,
PhyloData
(
..
)
)
where
import
Data.Aeson
import
Data.Aeson
((
.=
),
(
.:
),
Value
,
object
,
withObject
)
import
Gargantext.Core.Viz.Phylo
(
PhyloConfig
(
..
))
import
Data.ByteString
qualified
as
DB
import
Data.ByteString.Lazy
qualified
as
DBL
import
Data.Swagger
import
Data.Swagger
(
ToSchema
(
..
))
import
Gargantext.Core.Types
(
TODO
(
..
))
import
Gargantext.Core.Types.Phylo
(
GraphData
(
..
))
import
Gargantext.Database.Admin.Types.Node
-- (PhyloId, ListId, CorpusId, UserId, NodeId(..))
import
Gargantext.Prelude
import
Network.HTTP.Media
((
//
),
(
/:
))
import
Prelude
qualified
import
Servant
import
Test.QuickCheck.Arbitrary
(
Arbitrary
,
arbitrary
)
newtype
SVG
=
SVG
DB
.
ByteString
deriving
(
Show
,
Generic
)
--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
MimeRender
SVG
SVG
where
mimeRender
_
(
SVG
s
)
=
DBL
.
fromStrict
s
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
)
------------------------------------------------------------------------
...
...
@@ -58,8 +68,5 @@ instance FromJSON PhyloData where
pd_config
<-
o
.:
"pd_config"
pure
$
PhyloData
{
..
}
instance
Arbitrary
PhyloData
where
arbitrary
=
PhyloData
<$>
arbitrary
<*>
arbitrary
<*>
arbitrary
<*>
arbitrary
instance
ToSchema
PhyloData
src/Gargantext/Core/Viz/Phylo.hs
View file @
f84d7734
...
...
@@ -22,27 +22,24 @@ one 8, e54847.
-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}
module
Gargantext.Core.Viz.Phylo
where
import
Control.Lens
(
over
)
import
Data.Swagger
import
Data.Text.Lazy
qualified
as
TextLazy
import
Data.Aeson.Types
qualified
as
JS
import
Data.List.NonEmpty
qualified
as
NE
import
Data.Swagger
(
ToSchema
(
..
),
genericDeclareNamedSchema
)
import
Data.Text
(
pack
)
import
Data.Text.Lazy
qualified
as
TextLazy
import
Data.TreeDiff
(
ToExpr
(
..
))
import
Data.Vector
(
Vector
)
import
Gargantext.Core.Utils.Prefix
(
unPrefix
,
unPrefixSwagger
)
import
Gargantext.Prelude
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 | --
...
...
@@ -314,10 +311,6 @@ data Software =
instance
ToSchema
Software
where
declareNamedSchema
=
genericDeclareNamedSchema
(
unPrefixSwagger
"_software_"
)
instance
Arbitrary
Software
where
arbitrary
=
pure
defaultSoftware
defaultSoftware
::
Software
defaultSoftware
=
...
...
@@ -325,6 +318,8 @@ defaultSoftware =
,
_software_version
=
pack
"v5"
}
-- | Global parameters of a Phylo
data
PhyloParam
=
PhyloParam
{
_phyloParam_version
::
Text
...
...
@@ -335,13 +330,13 @@ data PhyloParam =
instance
ToSchema
PhyloParam
where
declareNamedSchema
=
genericDeclareNamedSchema
(
unPrefixSwagger
"_phyloParam_"
)
defaultPhyloParam
::
PhyloParam
defaultPhyloParam
=
PhyloParam
{
_phyloParam_version
=
pack
"v3"
,
_phyloParam_software
=
defaultSoftware
,
_phyloParam_config
=
defaultConfig
}
------------------
-- | Document | --
------------------
...
...
@@ -379,9 +374,6 @@ data PhyloFoundations = PhyloFoundations
,
_foundations_rootsInGroups
::
Map
Int
[
PhyloGroupId
]
-- map of roots associated to groups
}
deriving
(
Generic
,
Show
,
Eq
,
ToExpr
)
instance
Arbitrary
PhyloFoundations
where
arbitrary
=
PhyloFoundations
<$>
arbitrary
<*>
arbitrary
data
PhyloCounts
=
PhyloCounts
{
coocByDate
::
!
(
Map
Date
Cooc
)
,
docsByDate
::
!
(
Map
Date
Double
)
...
...
@@ -400,15 +392,6 @@ instance ToSchema PhyloCounts where
declareNamedSchema
=
genericDeclareNamedSchema
(
unPrefixSwagger
"_"
)
instance
ToSchema
PhyloSources
where
declareNamedSchema
=
genericDeclareNamedSchema
(
unPrefixSwagger
"_"
)
instance
Arbitrary
PhyloCounts
where
arbitrary
=
PhyloCounts
<$>
arbitrary
<*>
arbitrary
<*>
arbitrary
<*>
arbitrary
<*>
arbitrary
<*>
arbitrary
instance
Arbitrary
PhyloSources
where
arbitrary
=
PhyloSources
<$>
arbitrary
---------------------------
-- | Coocurency Matrix | --
...
...
@@ -481,8 +464,6 @@ data PhyloPeriod =
instance
ToSchema
PhyloPeriod
where
declareNamedSchema
=
genericDeclareNamedSchema
(
unPrefixSwagger
"_phylo_"
)
instance
Arbitrary
PhyloPeriod
where
arbitrary
=
PhyloPeriod
<$>
arbitrary
<*>
arbitrary
<*>
arbitrary
---------------
...
...
@@ -506,8 +487,6 @@ data PhyloScale =
instance
ToSchema
PhyloScale
where
declareNamedSchema
=
genericDeclareNamedSchema
(
unPrefixSwagger
"_phylo_"
)
instance
Arbitrary
PhyloScale
where
arbitrary
=
PhyloScale
<$>
arbitrary
<*>
arbitrary
<*>
arbitrary
<*>
arbitrary
type
PhyloGroupId
=
(
PhyloScaleId
,
Int
)
...
...
@@ -543,28 +522,6 @@ data PhyloGroup =
instance
ToSchema
PhyloGroup
where
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
type
Weight
=
Double
...
...
@@ -744,104 +701,6 @@ instance NFData Sort
instance
NFData
Tagger
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
--
...
...
test/Test/Instances.hs
View file @
f84d7734
...
...
@@ -38,11 +38,12 @@ import Gargantext.API.Node.New.Types (PostNode(..))
import
Gargantext.API.Node.Share.Types
(
ShareNodeParams
(
..
))
import
Gargantext.API.Node.Update.Types
qualified
as
NU
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.Dispatcher.Types
qualified
as
DET
import
Gargantext.Core.Types.Individu
qualified
as
Individu
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.Database.Admin.Types.Hyperdata
qualified
as
Hyperdata
import
Gargantext.Database.Admin.Types.Node
(
NodeId
(
..
),
UserId
(
..
),
NodeType
(
..
))
...
...
@@ -53,6 +54,8 @@ import Text.Parsec.Error (ParseError, Message(..), newErrorMessage)
import
Text.Parsec.Pos
import
Test.QuickCheck
import
Test.QuickCheck.Arbitrary.Generic
import
Test.QuickCheck.Instances.Text
()
import
Test.QuickCheck.Instances.Vector
()
instance
Arbitrary
AuthenticatedUser
where
arbitrary
=
genericArbitrary
...
...
@@ -143,7 +146,71 @@ instance Arbitrary ShareNodeParams where
,
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
.
Method
where
arbitrary
=
arbitraryBoundedEnum
instance
Arbitrary
NU
.
Granularity
where
arbitrary
=
arbitraryBoundedEnum
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment