commit 9a084a6b9efc68ded8403335f416cade5c5f4ec5
parent b15d7b644227befd00c20675fc37c2f04ffdb19e
Author: Vint Leenaars <vl.software@leenaa.rs>
Date: Thu, 8 May 2025 18:16:24 +0200
Add entity test framework
Diffstat:
| M | test/Tests/Check.hs | | | 120 | +++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------- |
1 file changed, 81 insertions(+), 39 deletions(-)
diff --git a/test/Tests/Check.hs b/test/Tests/Check.hs
@@ -19,6 +19,7 @@ import KYCheck.SSL as SSL
import KYCheck.Type hiding (threshold_confidence)
import Tests.Targets.Individuals
+import Tests.Targets.Entities
import Test.Tasty
import Test.Tasty.HUnit
@@ -26,9 +27,10 @@ import Test.Tasty.HUnit
tests :: Config -> Targets -> TestTree
tests config targets = testGroup "target tests"
[ personTests config (SSL.individuals targets)
+ , entityTests config (SSL.entities targets)
]
-data Distribution = Distribution
+data IndividualDistribution = IndividualDistribution
{ threshold_address :: Maybe Float
, threshold_date :: Maybe Float
, threshold_id :: Maybe Float
@@ -37,17 +39,33 @@ data Distribution = Distribution
, threshold_confidence :: Maybe Float
} deriving (Show, Eq)
+data EntityDistribution = EntityDistribution
+ { e_threshold_address :: Maybe Float
+ , e_threshold_name :: Maybe Float
+ , e_threshold_confidence :: Maybe Float
+ } deriving (Show, Eq)
-testEntity :: Config -> Bool -> Int -> LegalEntity -> Map Int Entity -> Distribution -> TestTree
-testEntity config verbose number entity sanction_list distribution =
- testGroup ("Test entity " ++ show number)
+
+testTrustedEntity :: Config -> Bool -> Int -> LegalEntity -> Map Int Entity -> EntityDistribution -> TestTree
+testTrustedEntity config verbose number entity sanction_list distribution =
+ testGroup ("Test trusted entity " ++ show number)
[]
-- [ testSingleEntity config verbose number entity distribution Nothing
-- , dontFindEntity config verbose target sanction_list ("individual " ++ show number)
-- ]
+testSanctionedEntity :: Config -> Bool -> Int -> LegalEntity -> Map Int Entity -> EntityDistribution -> TestTree
+testSanctionedEntity config verbose number entity sanction_list distribution =
+ testGroup ("Test entity " ++ show number)
+ []
+
+dontFindEntity :: Config -> Bool -> LegalEntity -> Map Int Entity -> String -> TestTree
+dontFindEntity config verbose entity sanction_list title =
+ testGroup ("Do not find entity " ++ title)
+ []
+
-- | Test trusted individual (found in target_SSID.xml, not found in sanction list)
-testTrustedIndividual :: Config -> Bool -> Int -> NaturalPerson -> Map Int Individual -> Distribution -> TestTree
+testTrustedIndividual :: Config -> Bool -> Int -> NaturalPerson -> Map Int Individual -> IndividualDistribution -> TestTree
testTrustedIndividual config verbose number target sanction_list distribution =
testGroup ("Test trusted individual " ++ show number)
[ testSingleIndividual config verbose number target distribution Nothing
@@ -56,14 +74,14 @@ testTrustedIndividual config verbose number target sanction_list distribution =
-- | Test sanctioned individual (found in target_SSID.xml, found in sanction list)
-testSanctionedIndividual :: Config -> Bool -> Int -> NaturalPerson -> Map Int Individual -> Distribution -> TestTree
+testSanctionedIndividual :: Config -> Bool -> Int -> NaturalPerson -> Map Int Individual -> IndividualDistribution -> TestTree
testSanctionedIndividual config verbose number target sanction_list distribution =
testGroup ("Test individual " ++ show number)
[ testSingleIndividual config verbose number target distribution Nothing
, findRealIndividual config verbose number target distribution sanction_list
]
-testIndividualVersions :: Config -> Bool -> Int -> Map Int Individual -> [(NaturalPerson, String, Distribution)] -> TestTree
+testIndividualVersions :: Config -> Bool -> Int -> Map Int Individual -> [(NaturalPerson, String, IndividualDistribution)] -> TestTree
testIndividualVersions config verbose number sanction_list versions =
withResource getResource (\_ -> pure ()) $ \ssl ->
testGroup ("Test versions of target " ++ show number)
@@ -87,7 +105,7 @@ testIndividualVersions config verbose number sanction_list versions =
return ssl
-- | Find target in sanction list
-findRealIndividual :: Config -> Bool -> Int -> NaturalPerson -> Distribution -> Map Int Individual -> TestTree
+findRealIndividual :: Config -> Bool -> Int -> NaturalPerson -> IndividualDistribution -> Map Int Individual -> TestTree
findRealIndividual config verbose number target distribution sanction_list =
testCase ("Find target " ++ show number ++ " in Swiss Sanction List") $ do
let score = checkPersons config sanction_list target
@@ -108,7 +126,7 @@ dontFindIndividual config verbose target sanction_list title =
-- | Test if target matches target described in target_SSID.xml
-testSingleIndividual :: Config -> Bool -> Int -> NaturalPerson -> Distribution -> Maybe (IO (Map Int Individual)) -> TestTree
+testSingleIndividual :: Config -> Bool -> Int -> NaturalPerson -> IndividualDistribution -> Maybe (IO (Map Int Individual)) -> TestTree
testSingleIndividual config verbose number target distribution ssl_target =
testCase ("Find target " ++ show number ++ " in test file") $ do
ssl <- case ssl_target of
@@ -157,30 +175,52 @@ compareScore maybe_threshold score title =
Nothing -> assertBool (title ++ " should return not matches , but got " ++ show score ++ " instead") (score == [])
+entityTests :: Config -> Map Int Entity -> TestTree
+entityTests config sanction_list =
+ let
+ testSE ssid target = testSanctionedEntity config False ssid target sanction_list
+ testTE ssid target = testTrustedEntity config False ssid target sanction_list
+ dontFindE target = dontFindEntity config False target sanction_list
+ in
+ testGroup "Entities"
+ [ testGroup "Known Sanctioned"
+ {- testSE SSID target_SSID $ distribution ADDRESS NAME CONFIDENCE
+ MAX_SCORE 150 125 0.75 -}
+ [
+ ]
+ , testGroup "Fake entity with XML file"
+ {- testTE SSID target_SSID $ distribution ADDRESS NAME CONFIDENCE
+ MAX_SCORE 150 125 0.75 -}
+ [
+ ]
+ , testGroup "Trusted entity"
+ {- testSE SSID target_SSID TITLE -}
+ [
+ ]
+ ]
+
-- | Test individuals
personTests :: Config -> Map Int Individual -> TestTree
personTests config sanction_list =
let
- testSI = testSanctionedIndividual config False
- testTI = testTrustedIndividual config False
- dontFindI = dontFindIndividual config False
- toMaybe float = case float of 0 -> Nothing; f -> Just f
- distribution addr date id' name nat conf = Distribution (toMaybe addr) (toMaybe date) (toMaybe id') (toMaybe name) (toMaybe nat) (toMaybe conf)
+ testSI ssid target = testSanctionedIndividual config False ssid target sanction_list
+ testTI ssid target = testTrustedIndividual config False ssid target sanction_list
+ dontFindI target = dontFindIndividual config False target sanction_list
in
testGroup "Individuals"
[ testGroup "Known Sanctioned"
- {- testSI SSID target_SSID sanction_list $ distribution ADDRESS DATE ID NAME NATIONALITY CONFIDENCE
- MAX_SCORE 150 100 200 125 50 0.75 -}
- [ testSI 5144 target_5144 sanction_list $ distribution 125 100 0 125 0 0.9
- , testSI 5266 target_5266 sanction_list $ distribution 0 0 0 125 0 1
- , testSI 43462 target_43462 sanction_list $ distribution 0 100 0 125 0 0.75
- , testSI 43616 target_43616 sanction_list $ distribution 0 0 0 125 0 1
- , testSI 43641 target_43641 sanction_list $ distribution 0 100 0 125 0 0.75
- , testSI 43718 target_43718 sanction_list $ distribution 0 100 0 125 0 0.75
- , testSI 43662 target_43662 sanction_list $ distribution 0 100 0 125 0 0.75
- , testSI 43611 target_43611 sanction_list $ distribution 0 0 0 125 0 1
- , testSI 29723 target_29723 sanction_list $ distribution 0 100 0 125 0 0.75
- , testSI 68815 target_68815 sanction_list $ distribution 75 100 0 125 50 0.75
+ {- testSI SSID target_SSID $ distribution ADDRESS DATE ID NAME NATIONALITY CONFIDENCE
+ MAX_SCORE 150 100 200 125 50 0.75 -}
+ [ testSI 5144 target_5144 $ distribution 125 100 0 125 0 0.9
+ , testSI 5266 target_5266 $ distribution 0 0 0 125 0 1
+ , testSI 43462 target_43462 $ distribution 0 100 0 125 0 0.75
+ , testSI 43616 target_43616 $ distribution 0 0 0 125 0 1
+ , testSI 43641 target_43641 $ distribution 0 100 0 125 0 0.75
+ , testSI 43718 target_43718 $ distribution 0 100 0 125 0 0.75
+ , testSI 43662 target_43662 $ distribution 0 100 0 125 0 0.75
+ , testSI 43611 target_43611 $ distribution 0 0 0 125 0 1
+ , testSI 29723 target_29723 $ distribution 0 100 0 125 0 0.75
+ , testSI 68815 target_68815 $ distribution 75 100 0 125 50 0.75
{- testIndividualVersions False SSID sanction_list $
, (target_SSID_vN, "vN", distribution ADDRESS DATE ID NAME NATIONALITY CONFIDENCE -}
@@ -211,21 +251,23 @@ personTests config sanction_list =
]
, testGroup "Fake target with XML file"
- {- testFT SSID target_SSID sanction_list $ distribution ADDRESS DATE ID NAME NATIONALITY CONFIDENCE
- 150 100 200 125 50 0.75 -}
- [ testTI 6 target_6 sanction_list $ distribution 0 100 0 125 0 0.75
+ {- testFT SSID target_SSID $ distribution ADDRESS DATE ID NAME NATIONALITY CONFIDENCE
+ 150 100 200 125 50 0.75 -}
+ [ testTI 6 target_6 $ distribution 0 100 0 125 0 0.75
]
, testGroup "Public and imaginary figures"
- [ dontFindI public_figure_1 sanction_list "Hergé"
- , dontFindI public_figure_2 sanction_list "Bezos"
- , dontFindI public_figure_3 sanction_list "Lincoln"
- , dontFindI public_figure_4 sanction_list "Willem-Alexander"
- , dontFindI public_figure_5 sanction_list "Da Vinci"
- , dontFindI imaginary_figure_1 sanction_list "Smurf"
- , dontFindI imaginary_figure_2 sanction_list "Donald"
- , dontFindI imaginary_figure_3 sanction_list "Wonka"
- , dontFindI imaginary_figure_4 sanction_list "Bilbo"
- , dontFindI imaginary_figure_5 sanction_list "Batman"
+ [ dontFindI public_figure_1 "Hergé"
+ , dontFindI public_figure_2 "Bezos"
+ , dontFindI public_figure_3 "Lincoln"
+ , dontFindI public_figure_4 "Willem-Alexander"
+ , dontFindI public_figure_5 "Da Vinci"
+ , dontFindI imaginary_figure_1 "Smurf"
+ , dontFindI imaginary_figure_2 "Donald"
+ , dontFindI imaginary_figure_3 "Wonka"
+ , dontFindI imaginary_figure_4 "Bilbo"
+ , dontFindI imaginary_figure_5 "Batman"
]
]
+ where distribution addr date id' name nat conf = IndividualDistribution (toMaybe addr) (toMaybe date) (toMaybe id') (toMaybe name) (toMaybe nat) (toMaybe conf)
+ toMaybe float = case float of 0 -> Nothing; f -> Just f