Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
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
Grégoire Locqueville
purescript-gargantext
Commits
a128f427
Verified
Commit
a128f427
authored
Jun 23, 2023
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[test] remove KarpRabin (spec is moved to string-search)
Also some refactoring (move to Test directory).
parent
5f83b235
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
41 additions
and
98 deletions
+41
-98
test.dhall
test.dhall
+5
-6
Spec.purs
test/Gargantext/Utils/KarpRabin/Spec.purs
+0
-66
Spec.purs
test/Test/Gargantext/Components/NgramsTable/Spec.purs
+34
-24
Spec.purs
test/Test/Gargantext/Data/Spec.purs
+1
-1
Spec.purs
test/Test/Gargantext/Utils/Spec.purs
+1
-1
Main.purs
test/Test/Main.purs
+0
-0
Utils.purs
test/Test/Utils.purs
+0
-0
No files found.
test.dhall
View file @
a128f427
let conf = ./spago.dhall
let conf = ./spago.dhall
in conf // {
in conf
sources = conf.sources # [ "test/**/*.purs" ],
// { sources = conf.sources # [ "test/**/*.purs" ]
dependencies = conf.dependencies # [ "spec"
, dependencies =
, "spec-discovery"
conf.dependencies # [ "spec", "spec-discovery", "spec-quickcheck" ]
, "spec-quickcheck" ]
}
}
test/Gargantext/Utils/KarpRabin/Spec.purs
deleted
100644 → 0
View file @
5f83b235
module Gargantext.Utils.KarpRabin.Spec where
import Prelude
import Data.Array (index)
import Data.Foldable (all)
import Data.Maybe (Maybe(..), isJust)
import Data.String (drop, stripPrefix, Pattern(..))
import Data.Tuple (Tuple(..))
import Gargantext.Utils.KarpRabin (indicesOfAny)
-- import Test.QuickCheck ((===), (/==), (<?>), Result(..))
import Test.Spec (Spec, describe, it)
import Test.Spec.Assertions (shouldEqual)
import Test.Spec.QuickCheck (quickCheck')
validIndices :: Array String -> String -> Boolean
validIndices pats input = all validIndex (indicesOfAny pats input)
where
validIndex (Tuple i ps) = all validPat ps
where
input' = drop i input
validPat p =
case index pats p of
Just pat -> isJust (stripPrefix (Pattern pat) input')
-- <?> (show input' <> " should start with " <> show pat)
Nothing -> false -- Failed "out of bounds pattern"
spec :: Spec Unit
spec =
describe "KarpRabin" do
it "works on a single pattern matching two times" do
let pats = ["ab"]
let input = "abcbab"
let output = [Tuple 0 [0], Tuple 4 [0]]
indicesOfAny pats input `shouldEqual` output
it "works on a many unmatching patterns" do
let pats = ["abd","e","bac","abcbabe"]
let input = "abcbab"
let output = []
indicesOfAny pats input `shouldEqual` output
it "works on a simple case" do
let pats = ["ab","cb","bc","bca"]
let input = "abcbab"
let output = [Tuple 0 [0]
,Tuple 1 [2]
,Tuple 2 [1]
,Tuple 4 [0]
]
indicesOfAny pats input `shouldEqual` output
it "works with overlaps" do
let pats = ["aba"]
let input = "ababa"
let output = [Tuple 0 [0]
,Tuple 2 [0]
]
indicesOfAny pats input `shouldEqual` output
it "returns valid indices" do
validIndices ["a","ab","ba","abc","aba","abab","abcde"]
"ababarbabacbbababcaccacabbababa"
`shouldEqual` true
it "returns valid indices 2000 random samples" do
quickCheck' 2000 validIndices
test/Gargantext/Components/NgramsTable/Spec.purs
→
test/
Test/
Gargantext/Components/NgramsTable/Spec.purs
View file @
a128f427
module Gargantext.Components.NgramsTable.Spec where
module
Test.
Gargantext.Components.NgramsTable.Spec where
import Prelude
import Prelude
import Data.List as L
import Data.List as L
import Data.Maybe (Maybe(..))
import Data.Maybe (Maybe(..))
import Data.Map as Map
import Data.Map as Map
import Data.Set as Set
import Data.Set as Set
import Data.Tuple (Tuple(..))
import Data.Tuple (Tuple(..)
, fst
)
import Test.Spec (Spec, describe, it)
import Test.Spec (Spec, describe, it)
-- import Test.Spec.Assertions (shouldEqual)
-- import Test.Spec.Assertions (shouldEqual)
-- import Test.Spec.QuickCheck (quickCheck')
-- import Test.Spec.QuickCheck (quickCheck')
import Test.Utils (shouldEqualArray)
import Test.Utils (shouldEqualArray)
import Gargantext.Core.NgramsTable.Functions (highlightNgrams, normNgram)
import Gargantext.Core.NgramsTable.Functions (highlightNgrams, normNgram
, computeCache
)
import Gargantext.Core.NgramsTable.Types (HighlightElement, NgramsElement(..), NgramsRepoElement(..), NgramsTable(..), NgramsTerm)
import Gargantext.Core.NgramsTable.Types (HighlightElement, NgramsElement(..), NgramsRepoElement(..), NgramsTable(..), NgramsTerm)
import Gargantext.Types (CTabNgramType(..), TermList(..))
import Gargantext.Types (CTabNgramType(..), TermList(..))
...
@@ -61,13 +61,15 @@ spec = do
...
@@ -61,13 +61,15 @@ spec = do
describe "NgramsTable.highlightNgrams" do
describe "NgramsTable.highlightNgrams" do
it "works on a simple example" do
it "works on a simple example" do
let ngramType = CTabSources
let ngramType = CTabSources
let table = NgramsTable
let tnres = [ tnre "which" StopTerm ngramType
{ ngrams_repo_elements: Map.fromFoldable [ tnre "which" StopTerm ngramType
, tnre "stops" StopTerm ngramType
, tnre "stops" StopTerm ngramType
, tnre "candidate" CandidateTerm ngramType
, tnre "candidate" CandidateTerm ngramType
]
]
let table = NgramsTable
{ ngrams_repo_elements: Map.fromFoldable tnres
, ngrams_scores: Map.fromFoldable [] }
, ngrams_scores: Map.fromFoldable [] }
input = "this is a graph about a biography which stops at every candidate"
input = "this is a graph about a biography which stops at every candidate"
cache = computeCache table $ Set.fromFoldable $ fst <$> tnres
output = [ highlightNil " this is a graph about a biography "
output = [ highlightNil " this is a graph about a biography "
, highlightSingleton " which" ngramType StopTerm
, highlightSingleton " which" ngramType StopTerm
, highlightNil " "
, highlightNil " "
...
@@ -76,17 +78,19 @@ spec = do
...
@@ -76,17 +78,19 @@ spec = do
, highlightSingleton " candidate" ngramType CandidateTerm
, highlightSingleton " candidate" ngramType CandidateTerm
, highlightNil " "
, highlightNil " "
]
]
highlightNgrams CTabTerms table input `shouldEqualArray` output
highlightNgrams
cache
CTabTerms table input `shouldEqualArray` output
it "works when pattern overlaps" do
it "works when pattern overlaps" do
let ngramType = CTabSources
let ngramType = CTabSources
let table = NgramsTable
let tnres = [ tnre "is" StopTerm ngramType
{ ngrams_repo_elements: Map.fromFoldable [ tnre "is" StopTerm ngramType
, tnre "a" StopTerm ngramType
, tnre "a" StopTerm ngramType
, tnre "of" StopTerm ngramType
, tnre "of" StopTerm ngramType
]
]
let table = NgramsTable
{ ngrams_repo_elements: Map.fromFoldable tnres
, ngrams_scores: Map.fromFoldable [] }
, ngrams_scores: Map.fromFoldable [] }
input = "This is a new state of the"
input = "This is a new state of the"
cache = computeCache table $ Set.fromFoldable $ fst <$> tnres
output = [ highlightNil " This "
output = [ highlightNil " This "
, highlightSingleton " is" ngramType StopTerm
, highlightSingleton " is" ngramType StopTerm
, highlightNil " "
, highlightNil " "
...
@@ -95,33 +99,37 @@ spec = do
...
@@ -95,33 +99,37 @@ spec = do
, highlightSingleton " of" ngramType StopTerm
, highlightSingleton " of" ngramType StopTerm
, highlightNil " the "
, highlightNil " the "
]
]
highlightNgrams CTabTerms table input `shouldEqualArray` output
highlightNgrams
cache
CTabTerms table input `shouldEqualArray` output
it "works when pattern overlaps 2" do
it "works when pattern overlaps 2" do
let ngramType = CTabSources
let ngramType = CTabSources
let table = NgramsTable
let tnres = [ tnre "from" CandidateTerm ngramType
{ ngrams_repo_elements: Map.fromFoldable [ tnre "from" CandidateTerm ngramType
, tnre "i" StopTerm ngramType
, tnre "i" StopTerm ngramType
, tnre "images" CandidateTerm ngramType
, tnre "images" CandidateTerm ngramType
]
]
let table = NgramsTable
{ ngrams_repo_elements: Map.fromFoldable tnres
, ngrams_scores: Map.fromFoldable [] }
, ngrams_scores: Map.fromFoldable [] }
input = "This is from space images"
input = "This is from space images"
cache = computeCache table $ Set.fromFoldable $ fst <$> tnres
output = [ highlightNil " This is "
output = [ highlightNil " This is "
, highlightSingleton " from" ngramType CandidateTerm
, highlightSingleton " from" ngramType CandidateTerm
, highlightNil " space "
, highlightNil " space "
, highlightSingleton " images" ngramType CandidateTerm
, highlightSingleton " images" ngramType CandidateTerm
, highlightNil " "
, highlightNil " "
]
]
highlightNgrams CTabTerms table input `shouldEqualArray` output
highlightNgrams
cache
CTabTerms table input `shouldEqualArray` output
it "works when pattern overlaps 3" do
it "works when pattern overlaps 3" do
let ngramType = CTabSources
let ngramType = CTabSources
let table = NgramsTable
let tnres = [ tnre "something" CandidateTerm ngramType
{ ngrams_repo_elements: Map.fromFoldable [ tnre "something" CandidateTerm ngramType
, tnre "something different" MapTerm ngramType
, tnre "something different" MapTerm ngramType
]
]
let table = NgramsTable
{ ngrams_repo_elements: Map.fromFoldable tnres
, ngrams_scores: Map.fromFoldable [] }
, ngrams_scores: Map.fromFoldable [] }
input = "and now for something different"
input = "and now for something different"
cache = computeCache table $ Set.fromFoldable $ fst <$> tnres
output = [ highlightNil " and now for "
output = [ highlightNil " and now for "
, Tuple " something" $ L.fromFoldable [
, Tuple " something" $ L.fromFoldable [
highlightTuple "something different" ngramType MapTerm
highlightTuple "something different" ngramType MapTerm
...
@@ -130,16 +138,18 @@ spec = do
...
@@ -130,16 +138,18 @@ spec = do
, Tuple " different" $ L.singleton $ highlightTuple "something different" ngramType MapTerm
, Tuple " different" $ L.singleton $ highlightTuple "something different" ngramType MapTerm
, highlightNil " "
, highlightNil " "
]
]
highlightNgrams CTabTerms table input `shouldEqualArray` output
highlightNgrams
cache
CTabTerms table input `shouldEqualArray` output
it "works with punctuation" do
it "works with punctuation" do
let ngramType = CTabSources
let ngramType = CTabSources
let tnres = [ tnre "graph" CandidateTerm ngramType ]
let table = NgramsTable
let table = NgramsTable
{ ngrams_repo_elements: Map.fromFoldable
[ tnre "graph" CandidateTerm ngramType ]
{ ngrams_repo_elements: Map.fromFoldable
tnres
, ngrams_scores: Map.fromFoldable [] }
, ngrams_scores: Map.fromFoldable [] }
input = "before graph, after"
input = "before graph, after"
cache = computeCache table $ Set.fromFoldable $ fst <$> tnres
output = [ highlightNil " before "
output = [ highlightNil " before "
, highlightSingleton " graph" ngramType CandidateTerm
, highlightSingleton " graph" ngramType CandidateTerm
, highlightNil ", after "
, highlightNil ", after "
]
]
highlightNgrams CTabTerms table input `shouldEqualArray` output
highlightNgrams
cache
CTabTerms table input `shouldEqualArray` output
test/Gargantext/Data/Spec.purs
→
test/
Test/
Gargantext/Data/Spec.purs
View file @
a128f427
module Gargantext.Data.Spec where
module
Test.
Gargantext.Data.Spec where
import Prelude
import Prelude
import Data.Array (index)
import Data.Array (index)
...
...
test/Gargantext/Utils/Spec.purs
→
test/
Test/
Gargantext/Utils/Spec.purs
View file @
a128f427
module Gargantext.Utils.Spec where
module
Test.
Gargantext.Utils.Spec where
import Data.Argonaut as Argonaut
import Data.Argonaut as Argonaut
import Data.Argonaut.Decode.Error (JsonDecodeError)
import Data.Argonaut.Decode.Error (JsonDecodeError)
...
...
test/Main.purs
→
test/
Test/
Main.purs
View file @
a128f427
File moved
test/Utils.purs
→
test/
Test/
Utils.purs
View file @
a128f427
File moved
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