Initial commit: Requirements to Gherkin CLI Converter
This commit is contained in:
116
tests/test_ambiguity.py
Normal file
116
tests/test_ambiguity.py
Normal file
@@ -0,0 +1,116 @@
|
||||
"""Tests for the ambiguity detection module."""
|
||||
|
||||
import pytest
|
||||
from nl2gherkin.nlp.ambiguity import AmbiguityDetector, AmbiguityType
|
||||
|
||||
|
||||
class TestAmbiguityDetector:
|
||||
"""Test cases for AmbiguityDetector."""
|
||||
|
||||
@pytest.fixture
|
||||
def detector(self):
|
||||
"""Create a detector instance."""
|
||||
return AmbiguityDetector()
|
||||
|
||||
def test_pronoun_detection(self, detector):
|
||||
"""Test detection of ambiguous pronouns."""
|
||||
text = "When the user clicks it, the system should show the results"
|
||||
result = detector.detect(text)
|
||||
|
||||
assert len(result) >= 0
|
||||
|
||||
def test_vague_quantifier_some(self, detector):
|
||||
"""Test detection of 'some' quantifier."""
|
||||
text = "The system should handle some requests efficiently"
|
||||
result = detector.detect(text)
|
||||
|
||||
quantifier_types = [w.type for w in result]
|
||||
assert AmbiguityType.VAGUE_QUANTIFIER in quantifier_types
|
||||
|
||||
def test_vague_quantifier_many(self, detector):
|
||||
"""Test detection of 'many' quantifier."""
|
||||
text = "Many users should be able to login"
|
||||
result = detector.detect(text)
|
||||
|
||||
quantifier_types = [w.type for w in result]
|
||||
assert AmbiguityType.VAGUE_QUANTIFIER in quantifier_types
|
||||
|
||||
def test_vague_quantifier_few(self, detector):
|
||||
"""Test detection of 'few' quantifier."""
|
||||
text = "Only few options are available"
|
||||
result = detector.detect(text)
|
||||
|
||||
quantifier_types = [w.type for w in result]
|
||||
assert AmbiguityType.VAGUE_QUANTIFIER in quantifier_types
|
||||
|
||||
def test_temporal_ambiguity(self, detector):
|
||||
"""Test detection of temporal ambiguities."""
|
||||
text = "The task should be completed soon"
|
||||
result = detector.detect(text)
|
||||
|
||||
temporal_types = [w.type for w in result]
|
||||
assert AmbiguityType.TEMPORAL in temporal_types
|
||||
|
||||
def test_missing_condition(self, detector):
|
||||
"""Test detection of missing conditions."""
|
||||
text = "The user must login to access the dashboard"
|
||||
result = detector.detect(text)
|
||||
|
||||
condition_types = [w.type for w in result]
|
||||
assert AmbiguityType.MISSING_CONDITION in condition_types
|
||||
|
||||
def test_passive_voice_detection(self, detector):
|
||||
"""Test detection of passive voice."""
|
||||
text = "The file was created by the system"
|
||||
result = detector.detect(text)
|
||||
|
||||
voice_types = [w.type for w in result]
|
||||
assert AmbiguityType.PASSIVE_VOICE in voice_types
|
||||
|
||||
def test_clear_requirement_no_warnings(self, detector):
|
||||
"""Test that clear requirements have few warnings."""
|
||||
text = "When the user clicks the submit button, the form data is validated on the server"
|
||||
result = detector.detect(text)
|
||||
|
||||
assert len(result) <= 2
|
||||
|
||||
def test_warning_has_suggestion(self, detector):
|
||||
"""Test that warnings include suggestions."""
|
||||
text = "Some data should be processed"
|
||||
result = detector.detect(text)
|
||||
|
||||
if result:
|
||||
assert any(w.suggestion is not None for w in result)
|
||||
|
||||
def test_warning_severity_levels(self, detector):
|
||||
"""Test that warnings have severity levels."""
|
||||
text = "The report was generated"
|
||||
result = detector.detect(text)
|
||||
|
||||
for warning in result:
|
||||
assert warning.severity in ["low", "medium", "high"]
|
||||
|
||||
def test_to_dict_method(self, detector):
|
||||
"""Test that warnings can be converted to dict."""
|
||||
text = "It should work"
|
||||
result = detector.detect(text)
|
||||
|
||||
if result:
|
||||
warning_dict = result[0].to_dict()
|
||||
assert "type" in warning_dict
|
||||
assert "message" in warning_dict
|
||||
assert "suggestion" in warning_dict
|
||||
|
||||
def test_multiple_ambiguities(self, detector):
|
||||
"""Test detection of multiple ambiguities in one text."""
|
||||
text = "When it happens, some users might see many results eventually"
|
||||
result = detector.detect(text)
|
||||
|
||||
assert len(result) >= 2
|
||||
|
||||
def test_empty_text(self, detector):
|
||||
"""Test handling of empty text."""
|
||||
result = detector.detect("")
|
||||
|
||||
assert isinstance(result, list)
|
||||
assert len(result) == 0
|
||||
Reference in New Issue
Block a user