Skip to content

Commit

Permalink
fix: Error in the feature ide reader and the tests for diagnosis
Browse files Browse the repository at this point in the history
  • Loading branch information
jagalindo committed Nov 14, 2023
1 parent 0283cc2 commit 90768c7
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ def get_destination_extension() -> str:
def __init__(self, source_model: FeatureModel) -> None:
super().__init__(source_model)
self.destination_model = DiagnosisModel()
# self.r_cnf = self.destination_model.r_cnf
# self.ctc_cnf = self.destination_model.ctc_cnf


def add_root(self, feature: Feature) -> None:
#self.r_cnf.append([self.destination_model.variables.get(feature.name)])

var = self.destination_model.variables.get(feature.name)
if var is None:
raise KeyError(f'Feature {feature.name} not found in the model')
Expand All @@ -47,10 +47,8 @@ def get_term_variable(term: Any) -> int:
term = term[1:]
negated = True

var = self.destination_model.variables.get(term)
if var is None:
raise KeyError(f'Feature {term} not found in the model')

var = self.destination_model.get_variable(term)

if negated:
return -var
return var
Expand All @@ -63,3 +61,4 @@ def get_term_variable(term: Any) -> int:
self.destination_model.add_clause(clause_variables)

self.destination_model.add_clause_to_map(str(ctc), ctc_clauses)

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import itertools
from typing import Any, List

import logging
from flamapy.core.transformations import ModelToModel
from flamapy.metamodels.fm_metamodel.models.feature_model import (
FeatureModel,
Expand Down
50 changes: 21 additions & 29 deletions tests/operations/operations_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,24 @@
from flamapy.metamodels.configuration_metamodel.models import Configuration
from flamapy.metamodels.fm_metamodel.models import Feature
from flamapy.metamodels.pysat_metamodel.models.pysat_model import PySATModel
from flamapy.metamodels.pysat_metamodel.operations.glucose3_core_features import (
Glucose3CoreFeatures,
from flamapy.metamodels.pysat_metamodel.operations.pysat_core_features import (
PySATCoreFeatures,
)
from flamapy.metamodels.pysat_metamodel.operations.glucose3_dead_features import (
Glucose3DeadFeatures,
from flamapy.metamodels.pysat_metamodel.operations.pysat_dead_features import (
PySATDeadFeatures,
)
from flamapy.metamodels.pysat_metamodel.operations.glucose3_error_detection import (
Glucose3ErrorDetection,
from flamapy.metamodels.pysat_metamodel.operations.pysat_false_optional_features import (
PySATFalseOptionalFeatures,
)
from flamapy.metamodels.pysat_metamodel.operations.glucose3_false_optional_features import (
Glucose3FalseOptionalFeatures,
from flamapy.metamodels.pysat_metamodel.operations.pysat_products import (
PySATProducts,
)
from flamapy.metamodels.pysat_metamodel.operations.glucose3_products import (
Glucose3Products,
from flamapy.metamodels.pysat_metamodel.operations.pysat_products_number import (
PySATProductsNumber,
)
from flamapy.metamodels.pysat_metamodel.operations.glucose3_products_number import (
Glucose3ProductsNumber,
)
from flamapy.metamodels.pysat_metamodel.operations.glucose3_valid import Glucose3Valid
from flamapy.metamodels.pysat_metamodel.operations.glucose3_valid_product import (
Glucose3ValidProduct,
from flamapy.metamodels.pysat_metamodel.operations.pysat_valid import PySATValid
from flamapy.metamodels.pysat_metamodel.operations.pysat_valid_product import (
PySATValidProduct,
)


Expand All @@ -41,50 +38,45 @@ def run(
) -> None:

if expected_core_features is not None:
core_features = Glucose3CoreFeatures()
core_features = PySATCoreFeatures()
core_features.execute(model)
assert core_features.get_result() == expected_core_features

if expected_dead_features is not None:
dead_features = Glucose3DeadFeatures()
dead_features = PySATDeadFeatures()
dead_features.execute(model)
assert dead_features.get_result() == expected_dead_features

if expected_error_detection is not None:
error_detection = Glucose3ErrorDetection()
error_detection.execute(model)
assert error_detection.get_result() == expected_error_detection

if expected_false_optional_features is not None:
false_optional_features = Glucose3FalseOptionalFeatures()
false_optional_features = PySATFalseOptionalFeatures()
false_optional_features.execute(model)
assert false_optional_features.get_result() == expected_false_optional_features

if expected_products_number is not None:
products_number = Glucose3ProductsNumber()
products_number = PySATProductsNumber()
products_number.execute(model)
assert products_number.get_result() == expected_products_number

if expected_products is not None:
products = Glucose3Products()
products = PySATProducts()
products.execute(model)
assert products.get_result() == expected_products

if expected_valid is not None:
valid = Glucose3Valid()
valid = PySATValid()
valid.execute(model)
assert valid.result == expected_valid

if expected_valid_product_list is not None:
for product in expected_valid_product_list:
valid_product = Glucose3ValidProduct()
valid_product = PySATValidProduct()
valid_product.set_configuration(product)
valid_product.execute(model)
assert valid_product.result

if expected_non_valid_product_list is not None:
for product in expected_non_valid_product_list:
valid_product = Glucose3ValidProduct()
valid_product = PySATValidProduct()
valid_product.set_configuration(product)
valid_product.execute(model)
assert not valid_product.result
Expand Down
57 changes: 30 additions & 27 deletions tests/unit_tests/diagnosis_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from flamapy.metamodels.fm_metamodel.transformations import FeatureIDEReader
from flamapy.metamodels.pysat_diagnosis_metamodel.transformations import FmToDiagPysat

from flamapy.metamodels.pysat_diagnosis_metamodel.operations import Glucose3Diagnosis, Glucose3Conflict
from flamapy.metamodels.pysat_diagnosis_metamodel.operations import PySATDiagnosis, PySATConflict


# def test_with_DiscoverMetamodels():
Expand All @@ -14,9 +14,9 @@
# In fact, Glucose3FastDiag implements ValidConfiguration, so it requires a configuration.
# """
# dm = DiscoverMetamodels()
# result = dm.use_operation_from_file("Glucose3FastDiag", "../resources/smartwatch_inconsistent.fide")
# result = dm.use_operation_from_file("Glucose3FastDiag", "./tests/resources/smartwatch_inconsistent.fide")
# print(result)
# result = dm.use_operation_from_file("Glucose3FastDiag", "../resources/smartwatch_consistent.fide")
# result = dm.use_operation_from_file("Glucose3FastDiag", "./tests/resources/smartwatch_consistent.fide")
# print(result)
# assert result == ['Diagnosis: [[-8, -4]]']

Expand All @@ -25,10 +25,12 @@ def test_fastdiag_all():
"""
Identify all diagnoses
"""
feature_model = FeatureIDEReader("../resources/smartwatch_inconsistent.fide").transform()
feature_model = FeatureIDEReader("./tests/resources/smartwatch_inconsistent.fide").transform()
print("numer of feats " + str(len(feature_model.get_features())))
print(feature_model)
model = FmToDiagPysat(feature_model).transform()

hsdag_fastdiag = Glucose3Diagnosis()
hsdag_fastdiag = PySATDiagnosis()
hsdag_fastdiag.execute(model)
result = hsdag_fastdiag.get_result()

Expand All @@ -41,10 +43,10 @@ def test_fastdiag_one():
"""
Identify one diagnosis
"""
feature_model = FeatureIDEReader("../resources/smartwatch_inconsistent.fide").transform()
feature_model = FeatureIDEReader("./tests/resources/smartwatch_inconsistent.fide").transform()
model = FmToDiagPysat(feature_model).transform()

hsdag_fastdiag = Glucose3Diagnosis()
hsdag_fastdiag = PySATDiagnosis()
hsdag_fastdiag.max_diagnoses = 1
hsdag_fastdiag.execute(model)
result = hsdag_fastdiag.get_result()
Expand All @@ -58,10 +60,10 @@ def test_fastdiag_two():
"""
Identify two diagnoses
"""
feature_model = FeatureIDEReader("../resources/smartwatch_inconsistent.fide").transform()
feature_model = FeatureIDEReader("./tests/resources/smartwatch_inconsistent.fide").transform()
model = FmToDiagPysat(feature_model).transform()

hsdag_fastdiag = Glucose3Diagnosis()
hsdag_fastdiag = PySATDiagnosis()
hsdag_fastdiag.max_diagnoses = 2
hsdag_fastdiag.execute(model)
result = hsdag_fastdiag.get_result()
Expand All @@ -72,10 +74,11 @@ def test_fastdiag_two():


def test_quickxplain_all():
feature_model = FeatureIDEReader("../resources/smartwatch_inconsistent.fide").transform()
feature_model = FeatureIDEReader("./tests/resources/smartwatch_inconsistent.fide").transform()

model = FmToDiagPysat(feature_model).transform()

hsdag_quickxplain = Glucose3Conflict()
hsdag_quickxplain = PySATConflict()
hsdag_quickxplain.execute(model)
result = hsdag_quickxplain.get_result()

Expand All @@ -86,10 +89,10 @@ def test_quickxplain_all():


def test_quickxplain_one():
feature_model = FeatureIDEReader("../resources/smartwatch_inconsistent.fide").transform()
feature_model = FeatureIDEReader("./tests/resources/smartwatch_inconsistent.fide").transform()
model = FmToDiagPysat(feature_model).transform()

hsdag_quickxplain = Glucose3Conflict()
hsdag_quickxplain = PySATConflict()
hsdag_quickxplain.max_conflicts = 1
hsdag_quickxplain.execute(model)
result = hsdag_quickxplain.get_result()
Expand All @@ -101,10 +104,10 @@ def test_quickxplain_one():


def test_quickxplain_two():
feature_model = FeatureIDEReader("../resources/smartwatch_inconsistent.fide").transform()
feature_model = FeatureIDEReader("./tests/resources/smartwatch_inconsistent.fide").transform()
model = FmToDiagPysat(feature_model).transform()

hsdag_quickxplain = Glucose3Conflict()
hsdag_quickxplain = PySATConflict()
hsdag_quickxplain.max_conflicts = 2
hsdag_quickxplain.execute(model)
result = hsdag_quickxplain.get_result()
Expand All @@ -116,12 +119,12 @@ def test_quickxplain_two():


def test_fastdiag_with_configuration():
feature_model = FeatureIDEReader("../resources/smartwatch_consistent.fide").transform()
feature_model = FeatureIDEReader("./tests/resources/smartwatch_consistent.fide").transform()
model = FmToDiagPysat(feature_model).transform()

configuration = ConfigurationBasicReader("../resources/smartwatch_nonvalid.csvconf").transform()
configuration = ConfigurationBasicReader("./tests/resources/smartwatch_nonvalid.csvconf").transform()

hsdag_fastdiag = Glucose3Diagnosis()
hsdag_fastdiag = PySATDiagnosis()
hsdag_fastdiag.set_configuration(configuration)
hsdag_fastdiag.execute(model)
result = hsdag_fastdiag.get_result()
Expand All @@ -132,12 +135,12 @@ def test_fastdiag_with_configuration():


def test_quickxplain_with_configuration():
feature_model = FeatureIDEReader("../resources/smartwatch_consistent.fide").transform()
feature_model = FeatureIDEReader("./tests/resources/smartwatch_consistent.fide").transform()
model = FmToDiagPysat(feature_model).transform()

configuration = ConfigurationBasicReader("../resources/smartwatch_nonvalid.csvconf").transform()
configuration = ConfigurationBasicReader("./tests/resources/smartwatch_nonvalid.csvconf").transform()

hsdag_quickxplain = Glucose3Conflict()
hsdag_quickxplain = PySATConflict()
hsdag_quickxplain.set_configuration(configuration)
hsdag_quickxplain.execute(model)
result = hsdag_quickxplain.get_result()
Expand All @@ -147,12 +150,12 @@ def test_quickxplain_with_configuration():


def test_fastdiag_with_test_case():
feature_model = FeatureIDEReader("../resources/smartwatch_deadfeature.fide").transform()
feature_model = FeatureIDEReader("./tests/resources/smartwatch_deadfeature.fide").transform()
model = FmToDiagPysat(feature_model).transform()

test_case = ConfigurationBasicReader("../resources/smartwatch_testcase.csvconf").transform()
test_case = ConfigurationBasicReader("./tests/resources/smartwatch_testcase.csvconf").transform()

hsdag_fastdiag = Glucose3Diagnosis()
hsdag_fastdiag = PySATDiagnosis()
hsdag_fastdiag.set_test_case(test_case)
hsdag_fastdiag.execute(model)
result = hsdag_fastdiag.get_result()
Expand All @@ -165,12 +168,12 @@ def test_fastdiag_with_test_case():


def test_quickxplain_with_testcase():
feature_model = FeatureIDEReader("../resources/smartwatch_deadfeature.fide").transform()
feature_model = FeatureIDEReader("./tests/resources/smartwatch_deadfeature.fide").transform()
model = FmToDiagPysat(feature_model).transform()

test_case = ConfigurationBasicReader("../resources/smartwatch_testcase.csvconf").transform()
test_case = ConfigurationBasicReader("./tests/resources/smartwatch_testcase.csvconf").transform()

hsdag_quickxplain = Glucose3Conflict()
hsdag_quickxplain = PySATConflict()
hsdag_quickxplain.set_test_case(test_case)
hsdag_quickxplain.execute(model)
result = hsdag_quickxplain.get_result()
Expand Down

0 comments on commit 90768c7

Please sign in to comment.