Update SemEq test, use dict for property weights

master
Chris Lenk 2019-12-20 17:01:21 -05:00
parent 77eda29471
commit 457564f2f9
2 changed files with 8 additions and 11 deletions

View File

@ -263,7 +263,10 @@ class Environment(DataStoreMixin):
sum_weights += w sum_weights += w
matching_score += contributing_score matching_score += contributing_score
prop_scores[prop] = (w, contributing_score) prop_scores[prop] = {
"weight": w,
"contributing_score": contributing_score,
}
logger.debug("'%s' check -- weight: %s, contributing score: %s", prop, w, contributing_score) logger.debug("'%s' check -- weight: %s, contributing score: %s", prop, w, contributing_score)
prop_scores["matching_score"] = matching_score prop_scores["matching_score"] = matching_score

View File

@ -755,6 +755,7 @@ def custom_semantic_equivalence_method(obj1, obj2, **weights):
def test_semantic_equivalence_method_provided(): def test_semantic_equivalence_method_provided():
# Because `method` is provided, `partial_list_based` will be ignored
TOOL2_KWARGS = dict( TOOL2_KWARGS = dict(
name="Random Software", name="Random Software",
tool_types=["information-gathering"], tool_types=["information-gathering"],
@ -780,18 +781,11 @@ def test_semantic_equivalence_prop_scores():
tool_types=["information-gathering"], tool_types=["information-gathering"],
) )
weights = {
"tool": {
"tool_types": (20, stix2.environment.partial_list_based),
"name": (80, stix2.environment.partial_string_based),
},
}
prop_scores = {} prop_scores = {}
tool1 = stix2.v21.Tool(id=TOOL_ID, **TOOL_KWARGS) tool1 = stix2.v21.Tool(id=TOOL_ID, **TOOL_KWARGS)
tool2 = stix2.v21.Tool(id=TOOL_ID, **TOOL2_KWARGS) tool2 = stix2.v21.Tool(id=TOOL_ID, **TOOL2_KWARGS)
stix2.Environment().semantically_equivalent(tool1, tool2, prop_scores, **weights) stix2.Environment().semantically_equivalent(tool1, tool2, prop_scores)
assert len(prop_scores) == 4 assert len(prop_scores) == 4
assert round(prop_scores["matching_score"], 1) == 37.6 assert round(prop_scores["matching_score"], 1) == 37.6
assert round(prop_scores["sum_weights"], 1) == 100.0 assert round(prop_scores["sum_weights"], 1) == 100.0
@ -811,8 +805,8 @@ def test_semantic_equivalence_prop_scores_method_provided():
weights = { weights = {
"tool": { "tool": {
"tool_types": (20, stix2.environment.partial_list_based), "tool_types": 20,
"name": (80, stix2.environment.partial_string_based), "name": 80,
"method": custom_semantic_equivalence_method_prop_scores, "method": custom_semantic_equivalence_method_prop_scores,
}, },
} }