Skip to content

Commit

Permalink
port commit 707d7dc, ScriptureRef test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
mshannon-sil committed Aug 16, 2024
1 parent 953f203 commit ce7a9ef
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
7 changes: 1 addition & 6 deletions machine/corpora/scripture_ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import List, Optional

from ..scripture.constants import ENGLISH_VERSIFICATION
from ..scripture.verse_ref import VerseRef, Versification, are_overlapping_verse_ranges
from ..scripture.verse_ref import VerseRef, Versification
from ..utils.comparable import Comparable
from .scripture_element import ScriptureElement

Expand Down Expand Up @@ -86,11 +86,6 @@ def change_versification(self, versification: Versification) -> ScriptureRef:
vr.change_versification(versification)
return ScriptureRef(vr, self.path)

def overlaps(self, other: ScriptureRef) -> bool:
if not are_overlapping_verse_ranges(self.verse_ref, other.verse_ref):
return False
return self.path == other.path

def compare_to(self, other: object, compare_segments: bool = True, strict: bool = True):
if not isinstance(other, ScriptureRef):
raise TypeError("other is not a ScriptureRef object.")
Expand Down
29 changes: 28 additions & 1 deletion tests/corpora/test_scripture_ref.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,49 @@
from pytest import raises

from machine.corpora import ScriptureRef


def test_compare_to_strict():
assert compare_to_strict("MAT 1:1", "MAT 1:2") == -1, "VerseLessThan"
assert compare_to_strict("MAT 1:1", "MAT 1:1") == 0, "VerseEqualTo"
assert compare_to_strict("MAT 1:2", "MAT 1:1") == 1, "VerseGreaterThan"
assert compare_to_strict("MAT 1:1-3", "MAT 1:1") == 1, "MultiVerseExtensionGreaterThan"
assert compare_to_strict("MAT 1:1", "MAT 1:1-3") == -1, "MultiVerseExtensionLessThan"
assert compare_to_strict("MAT 1:1-3", "MAT 1:2") == -1, "MultiVerseStartLessThan"
assert compare_to_strict("MAT 1:2", "MAT 1:1-3") == 1, "MultiVerseEndGreaterThan"
assert compare_to_strict("MAT 1:0/1:p", "MAT 1:0/2:p") == -1, "NonVerseLessThan"
assert compare_to_strict("MAT 1:0/1:p", "MAT 1:0/1:p") == 0, "NonVerseEqualTo"
assert compare_to_strict("MAT 1:0/2:p", "MAT 1:0/1:p") == 1, "NonVerseGreaterThan"
assert compare_to_strict("MAT 1:0/1:esb", "MAT 1:0/1:esb/1:p") == -1, "NonVerseParentChild"
assert compare_to_strict("MAT 1:0/2:esb", "MAT 1:0/1:esb/1:p") == 1, "NonVerseParentOtherChild"


def test_compare_to_relaxed():
assert compare_to_relaxed("MAT 1:1", "MAT 1:2") == -1, "VerseLessThan"
assert compare_to_relaxed("MAT 1:1", "MAT 1:1") == 0, "VerseEqualTo"
assert compare_to_relaxed("MAT 1:2", "MAT 1:1") == 1, "VerseGreaterThan"
assert compare_to_relaxed("MAT 1:0/1:p", "MAT 1:0/2:p") == 0, "NonVerseSameMarkerDifferentPosition"
assert compare_to_relaxed("MAT 1:0/2:esb", "MAT 1:0/1:esb/1:p") == -1, "NonVerseParentChild"
assert compare_to_relaxed("MAT 1:0/1:esb", "MAT 1:0/1:esb/1:p") == -1, "NonVerseParentChild"
assert compare_to_relaxed("MAT 1:0/2:esb", "MAT 1:0/1:esb/1:p") == -1, "NonVerseParentOtherChild"


def test_is_equal_to():
ref1 = ScriptureRef.parse("MAT 1:1/1:p")
ref1dup = ScriptureRef.parse("MAT 1:1/1:p")
ref2 = ScriptureRef.parse("MAT 1:2/1:p")
obj1 = "A different type"

assert ref1 == ref1dup
assert ref1 != ref2
assert ref1 != obj1


def test_is_equal_to_throws_argument_exception():
ref1 = ScriptureRef.parse("MAT 1:1/1:p")
obj1 = "A different type"

with raises(TypeError):
ref1.compare_to(obj1)


def compare_to_strict(ref1_str, ref2_str):
Expand Down

0 comments on commit ce7a9ef

Please sign in to comment.