Commit 75488abc authored by Alfredo Di Napoli's avatar Alfredo Di Napoli

Add more pagination tests

parent 7b955a56
...@@ -849,6 +849,7 @@ test-suite garg-test ...@@ -849,6 +849,7 @@ test-suite garg-test
Ngrams.Metrics Ngrams.Metrics
Ngrams.NLP Ngrams.NLP
Ngrams.Query Ngrams.Query
Ngrams.Query.PaginationCorpus
Parsers.Date Parsers.Date
Parsers.Types Parsers.Types
Parsers.WOS Parsers.WOS
......
...@@ -10,15 +10,12 @@ Portability : POSIX ...@@ -10,15 +10,12 @@ Portability : POSIX
import Gargantext.Prelude import Gargantext.Prelude
import Gargantext.Core (Lang(..))
import qualified Core.Utils as Utils import qualified Core.Utils as Utils
--import qualified Ngrams.Lang.Fr as Fr --import qualified Ngrams.Lang.Fr as Fr
--import qualified Ngrams.Lang as Lang --import qualified Ngrams.Lang as Lang
import qualified Ngrams.Lang.Occurrences as Occ
import qualified Ngrams.NLP as NLP import qualified Ngrams.NLP as NLP
import qualified Ngrams.Query as NgramsQuery import qualified Ngrams.Query as NgramsQuery
import qualified Ngrams.Metrics as Metrics
import qualified Parsers.Date as PD import qualified Parsers.Date as PD
-- import qualified Graph.Distance as GD -- import qualified Graph.Distance as GD
import qualified Graph.Clustering as Graph import qualified Graph.Clustering as Graph
......
...@@ -11,6 +11,7 @@ import Data.Map.Strict (Map) ...@@ -11,6 +11,7 @@ import Data.Map.Strict (Map)
import Gargantext.Core.Types.Query import Gargantext.Core.Types.Query
import Gargantext.Core.Types.Main import Gargantext.Core.Types.Main
import Ngrams.Query.PaginationCorpus
import Test.Tasty import Test.Tasty
import Test.Tasty.HUnit import Test.Tasty.HUnit
...@@ -47,6 +48,9 @@ unitTests = testGroup "Query tests" ...@@ -47,6 +48,9 @@ unitTests = testGroup "Query tests"
, testCase "Simple query (listType = StopTerm)" testFlat04 , testCase "Simple query (listType = StopTerm)" testFlat04
-- Full text search -- Full text search
, testCase "Simple query (search with match)" testFlat05 , testCase "Simple query (search with match)" testFlat05
-- Pagination
, testCase "Simple pagination on MapTerm" test_pagination01
, testCase "Simple pagination on MapTerm (limit < total terms)" test_pagination02
] ]
-- Let's test that if we request elements sorted in -- Let's test that if we request elements sorted in
...@@ -132,3 +136,37 @@ testFlat05 = do ...@@ -132,3 +136,37 @@ testFlat05 = do
, _nsq_orderBy = Just TermDesc , _nsq_orderBy = Just TermDesc
, _nsq_searchQuery = mockQueryFn (Just "curry") , _nsq_searchQuery = mockQueryFn (Just "curry")
} }
-- Pagination tests
-- In this test, I'm asking for 5 /map terms/, and as the
-- corpus has only 2, that's what I should get back.
test_pagination01 :: Assertion
test_pagination01 = do
let res = searchTableNgrams paginationCorpus searchQuery
res @?= VersionedWithCount 0 4 ( NgramsTable [implementationElem, languagesElem, termsElem, proofElem] )
where
searchQuery = NgramsSearchQuery {
_nsq_limit = Limit 5
, _nsq_offset = Nothing
, _nsq_listType = Just MapTerm
, _nsq_minSize = Nothing
, _nsq_maxSize = Nothing
, _nsq_orderBy = Just ScoreDesc
, _nsq_searchQuery = mockQueryFn Nothing
}
test_pagination02 :: Assertion
test_pagination02 = do
let res = searchTableNgrams paginationCorpus searchQuery
res @?= VersionedWithCount 0 4 ( NgramsTable [implementationElem, languagesElem, termsElem] )
where
searchQuery = NgramsSearchQuery {
_nsq_limit = Limit 3
, _nsq_offset = Nothing
, _nsq_listType = Just MapTerm
, _nsq_minSize = Nothing
, _nsq_maxSize = Nothing
, _nsq_orderBy = Just ScoreDesc
, _nsq_searchQuery = mockQueryFn Nothing
}
module Ngrams.Query.PaginationCorpus where
import Data.Map.Strict (Map)
import Gargantext.API.Ngrams
import Gargantext.Core.Types.Main
import Gargantext.Database.Admin.Types.Node
import Gargantext.Prelude
import qualified Data.Map.Strict as Map
import qualified Data.Set as Set
implementationElem :: NgramsElement
implementationElem = NgramsElement {
_ne_ngrams = "implementation"
, _ne_size = 1
, _ne_list = MapTerm
, _ne_occurrences = Set.fromList [ NodeId 1, NodeId 2, NodeId 3, NodeId 4, NodeId 5 ]
, _ne_root = Nothing
, _ne_parent = Nothing
, _ne_children = mSetFromList [ "code", "functions", "language", "programs" ]
}
languagesElem :: NgramsElement
languagesElem = NgramsElement {
_ne_ngrams = NgramsTerm {unNgramsTerm = "languages"}
, _ne_size = 1
, _ne_list = MapTerm
, _ne_occurrences = Set.fromList [ NodeId 1, NodeId 2 , NodeId 3 , NodeId 4 ]
, _ne_root = Nothing
, _ne_parent = Nothing
, _ne_children = mSetFromList [ "approach", "use" ]
}
termsElem :: NgramsElement
termsElem = NgramsElement {
_ne_ngrams = NgramsTerm {unNgramsTerm = "terms"}
, _ne_size = 1
, _ne_list = MapTerm
, _ne_occurrences = Set.fromList [ NodeId 1, NodeId 2 , NodeId 3 ]
, _ne_root = Nothing
, _ne_parent = Nothing
, _ne_children = mSetFromList [ "algorithm", "evaluation", "monad", "programmers" ]
}
proofElem :: NgramsElement
proofElem = NgramsElement {
_ne_ngrams = NgramsTerm {unNgramsTerm = "proof"}
, _ne_size = 1
, _ne_list = MapTerm
, _ne_occurrences = Set.fromList [ NodeId 1, NodeId 2 ]
, _ne_root = Nothing
, _ne_parent = Nothing
, _ne_children = mSetFromList [ "proofs" ]
}
sideEffectsElem :: NgramsElement
sideEffectsElem = NgramsElement {
_ne_ngrams = NgramsTerm {unNgramsTerm = "side effects"}
, _ne_size = 1
, _ne_list = StopTerm
, _ne_occurrences = Set.fromList [ NodeId 1, NodeId 2, NodeId 3, NodeId 4, NodeId 5, NodeId 6 ]
, _ne_root = Nothing
, _ne_parent = Nothing
, _ne_children = mSetFromList [ ]
}
ooElem :: NgramsElement
ooElem = NgramsElement {
_ne_ngrams = NgramsTerm {unNgramsTerm = "object oriented"}
, _ne_size = 1
, _ne_list = StopTerm
, _ne_occurrences = Set.fromList [ NodeId 1, NodeId 2, NodeId 3, NodeId 4, NodeId 5 ]
, _ne_root = Nothing
, _ne_parent = Nothing
, _ne_children = mSetFromList [ "null pointer exception" ]
}
haskellElem :: NgramsElement
haskellElem = NgramsElement {
_ne_ngrams = NgramsTerm {unNgramsTerm = "haskell"}
, _ne_size = 1
, _ne_list = CandidateTerm
, _ne_occurrences = Set.fromList [ NodeId 1, NodeId 2, NodeId 3, NodeId 4, NodeId 5, NodeId 6, NodeId 7, NodeId 8 ]
, _ne_root = Nothing
, _ne_parent = Nothing
, _ne_children = mSetFromList [ ]
}
concHaskellElem :: NgramsElement
concHaskellElem = NgramsElement {
_ne_ngrams = NgramsTerm {unNgramsTerm = "concurrent haskell"}
, _ne_size = 1
, _ne_list = CandidateTerm
, _ne_occurrences = Set.fromList [ NodeId 1, NodeId 2, NodeId 3, NodeId 4, NodeId 5 ]
, _ne_root = Nothing
, _ne_parent = Nothing
, _ne_children = mSetFromList [ "Simon Marlow" ]
}
-- | A big (for the sake of the tests anyway) corpus which has
-- * 4 @MapTerm@s
-- * 4 @StopTerm@s
-- * 2 @CandidateTerm@s
paginationCorpus :: Versioned (Map NgramsTerm NgramsElement)
paginationCorpus = Versioned 0 $ Map.fromList [
-- Map terms
( "implementation", implementationElem)
, ( "languages", languagesElem)
, ( "terms", termsElem)
, ("proof", proofElem)
-- Stop terms
, ("side effects", sideEffectsElem)
, ("object oriented", ooElem)
-- Candidate terms
, ("haskell", haskellElem)
, ("concurrent haskell", concHaskellElem)
]
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