mirror of
https://github.com/13hannes11/bachelor_thesis_m.recommend.git
synced 2024-09-04 01:11:00 +02:00
add recommender to repository
This commit is contained in:
28
tests/test_model/test_configuration_model.py
Normal file
28
tests/test_model/test_configuration_model.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from model.configuration_model import ConfigurationModel, ConfigurationVariablesModel
|
||||
import math
|
||||
import pytest
|
||||
|
||||
class TestConfigurationModel:
|
||||
def test_simple_parsing(self):
|
||||
data = {
|
||||
'configuration': ['code1', 'code2'],
|
||||
'variables': [
|
||||
{
|
||||
'code': 'abc',
|
||||
'value': 1
|
||||
}
|
||||
]
|
||||
}
|
||||
conf = ConfigurationModel(data)
|
||||
assert len(conf.configuration) == 2
|
||||
assert len(conf.variables) == 1
|
||||
|
||||
class TestConfigurationVariableModel:
|
||||
def test_simple_parsing(self):
|
||||
data = {
|
||||
'code': 'abc',
|
||||
'value': 1
|
||||
}
|
||||
var = ConfigurationVariablesModel(data)
|
||||
assert var.code == 'abc'
|
||||
assert var.value == 1
|
||||
113
tests/test_model/test_preference_model.py
Normal file
113
tests/test_model/test_preference_model.py
Normal file
@@ -0,0 +1,113 @@
|
||||
from model.preferences_model import Preferences, Rating, UserPreference
|
||||
import math
|
||||
import pytest
|
||||
|
||||
class TestRating:
|
||||
def test_range_conversion_minus_one_to_zero(self):
|
||||
data = {
|
||||
'code': 'abs',
|
||||
'value': 0
|
||||
}
|
||||
assert math.isclose(0, Rating(data).getValue())
|
||||
def test_range_conversion_one_to_one(self):
|
||||
data = {
|
||||
'code': 'abs',
|
||||
'value': 1
|
||||
}
|
||||
assert math.isclose(1, Rating(data).getValue())
|
||||
def test_range_conversion_zero_to_half(self):
|
||||
data = {
|
||||
'code': 'abs',
|
||||
'value': 0.5
|
||||
}
|
||||
assert math.isclose(0.5, Rating(data).getValue())
|
||||
def test_value_to_large(self):
|
||||
with pytest.raises(ValueError):
|
||||
data = {
|
||||
'code': 'abs',
|
||||
'value': 1.1
|
||||
}
|
||||
rating = Rating(data)
|
||||
def test_value_to_small(self):
|
||||
with pytest.raises(ValueError):
|
||||
data = {
|
||||
'code': 'abs',
|
||||
'value': -0.1
|
||||
}
|
||||
rating = Rating(data)
|
||||
|
||||
class TestUserPreference:
|
||||
data = {
|
||||
'user': "user0",
|
||||
'ratings':[ {
|
||||
'code': 'abs',
|
||||
'value': 0
|
||||
}, {
|
||||
'code': '2',
|
||||
'value': 1
|
||||
}, {
|
||||
'code': '3',
|
||||
'value': 0.5
|
||||
}
|
||||
]
|
||||
}
|
||||
def test_get_all_ratings(self):
|
||||
user_pref = UserPreference(self.data)
|
||||
assert len(user_pref.getAllRatings()) == 3
|
||||
def test_get_rating_by_code(self):
|
||||
user_pref = UserPreference(self.data)
|
||||
rating = user_pref.getRatingByCode('2')
|
||||
assert rating.code == '2'
|
||||
assert rating.getValue() == 1
|
||||
def test_get_rating_by_code_default(self):
|
||||
user_pref = UserPreference(self.data)
|
||||
rating = user_pref.getRatingByCode('notFOUND')
|
||||
assert rating.code == 'notFOUND'
|
||||
assert rating.getValue() == 0.5
|
||||
|
||||
class TestPreferences:
|
||||
preferences = Preferences({
|
||||
'preferences': [
|
||||
{
|
||||
'user': "user0",
|
||||
'ratings':[ {
|
||||
'code': 'in_both',
|
||||
'value': 0
|
||||
}, {
|
||||
'code': 'only_in_one',
|
||||
'value': 1
|
||||
}, {
|
||||
'code': '3',
|
||||
'value': 0.5
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'user': "user1",
|
||||
'ratings':[ {
|
||||
'code': 'in_both',
|
||||
'value': 1
|
||||
}, {
|
||||
'code': '3',
|
||||
'value': 1
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
})
|
||||
def test_get_all_user_preferences(self):
|
||||
assert len(self.preferences.getAllUserPreferences()) == 2
|
||||
def test_get_all_rating_by_code(self):
|
||||
assert len(self.preferences.getAllRatingsByCode('only_in_one')) == 2
|
||||
assert len(self.preferences.getAllRatingsByCode('in_both')) == 2
|
||||
def test_get_all_users(self):
|
||||
assert len(self.preferences.getAllUsers()) == 2
|
||||
assert "user0" in self.preferences.getAllUsers()
|
||||
assert "user1" in self.preferences.getAllUsers()
|
||||
def test_get_rating_by_user_and_code(self):
|
||||
assert self.preferences.getRatingValueByUserAndCode("user0", "only_in_one") == 1
|
||||
def test_empty_preferences(self):
|
||||
assert len(Preferences({ 'preferences' : []}).getAllUsers()) == 0
|
||||
def test_getIndividual_preferences(self):
|
||||
assert len(self.preferences.getIndividualPreferences()) == 2
|
||||
|
||||
100
tests/test_model/test_product_structure_model.py
Normal file
100
tests/test_model/test_product_structure_model.py
Normal file
@@ -0,0 +1,100 @@
|
||||
from model.product_structure_model import ProductStructureModel, ProductStructureElementModel, ProductStructureTypeEnum
|
||||
|
||||
class TestProductStructureModelEnum:
|
||||
def test_string_characteristic(self):
|
||||
assert ProductStructureTypeEnum['CHARACTERISTIC'] == ProductStructureTypeEnum.CHARACTERISTIC
|
||||
def test_string_cluster(self):
|
||||
assert ProductStructureTypeEnum['CLUSTER'] == ProductStructureTypeEnum.CLUSTER
|
||||
def test_string_variable(self):
|
||||
assert ProductStructureTypeEnum['VARIABLE'] == ProductStructureTypeEnum.VARIABLE
|
||||
def test_string_feature(self):
|
||||
assert ProductStructureTypeEnum['FEATURE'] == ProductStructureTypeEnum.FEATURE
|
||||
|
||||
class TestProductStructureElementModel:
|
||||
def test_get_list_of_all(self):
|
||||
data = {
|
||||
'elementId': 'parent',
|
||||
'name': 'parent_element',
|
||||
'type': "FEATURE",
|
||||
'additionalData': [],
|
||||
'children': [
|
||||
{
|
||||
'elementId': 'child',
|
||||
'name': 'child',
|
||||
'children': [],
|
||||
'additionalData': [],
|
||||
'type': "CHARACTERISTIC"
|
||||
}
|
||||
],
|
||||
}
|
||||
element = ProductStructureElementModel(data)
|
||||
assert len(element.get_list_of_all(ProductStructureTypeEnum.CHARACTERISTIC)) == 1
|
||||
|
||||
class TestProductStructureModel:
|
||||
def test_get_list_of_features(self):
|
||||
data = {
|
||||
'ProductStructure': [
|
||||
{
|
||||
'elementId': 'parent',
|
||||
'name': 'parent_element',
|
||||
'type': "FEATURE",
|
||||
'additionalData': [],
|
||||
'children': [
|
||||
{
|
||||
'elementId': 'child',
|
||||
'name': 'child',
|
||||
'children': [],
|
||||
'additionalData': [],
|
||||
'type': "CHARACTERISTIC"
|
||||
}
|
||||
],
|
||||
}
|
||||
]
|
||||
}
|
||||
ps_structure = ProductStructureModel(data)
|
||||
assert len(ps_structure.get_list_of_features()) == 1
|
||||
def test_get_list_of_characteristics(self):
|
||||
data = {
|
||||
'ProductStructure': [
|
||||
{
|
||||
'elementId': 'parent',
|
||||
'name': 'parent_element',
|
||||
'type': "FEATURE",
|
||||
'additionalData': [],
|
||||
'children': [
|
||||
{
|
||||
'elementId': 'child',
|
||||
'name': 'child',
|
||||
'children': [],
|
||||
'additionalData': [],
|
||||
'type': "CHARACTERISTIC"
|
||||
}
|
||||
],
|
||||
}
|
||||
]
|
||||
}
|
||||
ps_structure = ProductStructureModel(data)
|
||||
assert len(ps_structure.get_list_of_characteristics()) == 1
|
||||
def test_is_characteristic(self):
|
||||
data = {
|
||||
'ProductStructure': [
|
||||
{
|
||||
'elementId': 'parent',
|
||||
'name': 'parent_element',
|
||||
'type': "FEATURE",
|
||||
'additionalData': [],
|
||||
'children': [
|
||||
{
|
||||
'elementId': 'child',
|
||||
'name': 'child',
|
||||
'children': [],
|
||||
'additionalData': [],
|
||||
'type': "CHARACTERISTIC"
|
||||
}
|
||||
],
|
||||
}
|
||||
]
|
||||
}
|
||||
ps_structure = ProductStructureModel(data)
|
||||
assert ps_structure.isCharacteristic('child') == True
|
||||
assert ps_structure.isCharacteristic('parent') == False
|
||||
Reference in New Issue
Block a user