def test_similarity_must_return_expected_ratio_considering_annotation(): f = ElementType(name='ModelType') f.annotation = 'A simple documentation for type' f2 = ElementType(name='AnotherElementType') f2.annotation = 'A simple documentation for type' assert f2.similarity(f) > 0.8 # With a small change in documentation f2.annotation = 'A simple documentation' assert f2.similarity(f) > 0.7
def test_similarity_must_return_expected_ratio_considering_children(): element_type = ElementType('xsd:string') name_elem = Element(name='Name', element_type=element_type) surname_elem = Element(name='Surname', element_type=element_type) f = ElementType(name='ContactType', children=[name_elem, surname_elem]) other_name_elem = Element(name='Name', element_type=element_type) f2 = ElementType(name='OtherContactType', children=[other_name_elem, surname_elem]) assert f2.similarity(f) > 0.9 other_name_elem.name = 'FirstName' assert f2.similarity(f) > 0.8
def test_element_similarity_with_equal_elements_must_return_as_expected(): element_type = ElementType('xsd:string') name_elem = Element(name='Name', element_type=element_type) surname_elem = Element(name='Surname', element_type=element_type) first = ElementType(name='Contract', children=[name_elem, surname_elem]) first.annotation = 'foo' second = ElementType(name='Contract', children=[name_elem, surname_elem]) second.annotation = 'foo' assert first.similarity(second) == 1.0