def test_maybe_joinable_different_lengths(self) -> None: # the below (different length) is not supported even though transf2 could be represented by [EditTransformation("asdf", "", "foo")] # a construction like this will never happen in current use cases, though # (e.g. ("abc", "", "") + ("def", "foo", "bar") = ("abcdef", "foo", "bar") and ("abc", "foo", "bar") + ("", "hugo", "ilse") = ("abc", "foohugo", "barilse")) subt1 = word_analysis.EditTransformation("", "", "foo") subt2 = word_analysis.EditTransformation("asdf", "", "") transf1 = word_analysis.WordTransformationSequence([subt1]) transf2 = word_analysis.WordTransformationSequence([subt2, subt1]) self.assertFalse(transf1.maybe_joinable(transf2)) self.assertFalse(transf2.maybe_joinable(transf1))
def test_join_unjoinable(self) -> None: subt1 = word_analysis.EditTransformation("abc", "ba", "ge") subt2 = word_analysis.EditTransformation("abc", "ba", "hugo") subt3 = word_analysis.EditTransformation("abc", "ab", "ge") transf1 = word_analysis.WordTransformationSequence([subt1]) transf2 = word_analysis.WordTransformationSequence([subt2]) transf3 = word_analysis.WordTransformationSequence([subt3]) with self.assertRaises(ValueError): transf1.join(transf2) transf2.join(transf1) transf1.join(transf3) transf3.join(transf1) transf2.join(transf3) transf3.join(transf2)
def test_equals(self) -> None: transf1 = word_analysis.EditTransformation("", "ugo", "il") transf2 = word_analysis.EditTransformation("", "ugo", "il") transf3 = word_analysis.EditTransformation("", "ugo", "") transf4 = word_analysis.EditTransformation("", "", "il") transf5 = word_analysis.EditTransformation("foo", "ugo", "il") transf5b = word_analysis.EditTransformation("foo", "ugo", "il") transf6 = word_analysis.EditTransformation("oo", "ugo", "il") transf7 = word_analysis.EditTransformation("oo", "ug", "il") self.assertEquals(transf1, transf2) self.assertEquals(transf2 ,transf1) self.assertEquals(transf5, transf5b) self.assertEquals(transf5b, transf5) self.assertNotEquals(transf1, transf3) self.assertNotEquals(transf3, transf1) self.assertNotEquals(transf1, transf4) self.assertNotEquals(transf4, transf1) self.assertNotEquals(transf2, transf3) self.assertNotEquals(transf5, transf1) self.assertNotEquals(transf1, transf5) self.assertNotEquals(transf5, transf6) self.assertNotEquals(transf6, transf5) self.assertNotEquals(transf6, transf7) self.assertNotEquals(transf7, transf6) self.assertNotEquals(transf1, word_analysis.WordTransformationSequence([transf1]))
def test_join(self) -> None: subt1 = word_analysis.EditTransformation("abc", "", "ge") subt2 = word_analysis.EditTransformation("dc", "", "ge") subt3 = word_analysis.EditTransformation("hef", "ghi", "asdf") transf1 = word_analysis.WordTransformationSequence([subt3, subt1]) transf11 = word_analysis.WordTransformationSequence([subt3, subt1]) self.assertEquals(transf1, transf1.join(transf11)) self.assertEquals(transf1, transf11.join(transf1)) transf2 = word_analysis.WordTransformationSequence([subt3, subt2]) transf3 = word_analysis.WordTransformationSequence([subt1, subt3]) transf4 = word_analysis.WordTransformationSequence([subt2, subt3]) expected12 = word_analysis.WordTransformationSequence([ word_analysis.EditTransformation("hef", "ghi", "asdf"), word_analysis.EditTransformation("c", "", "ge") ]) joined12 = transf1.join(transf2) joined21 = transf2.join(transf1) self.assertEquals(expected12, joined12) self.assertEquals(expected12, joined21) expected34 = word_analysis.WordTransformationSequence([ word_analysis.EditTransformation("c", "", "ge"), word_analysis.EditTransformation("hef", "ghi", "asdf") ]) joined34 = transf3.join(transf4) joined43 = transf4.join(transf3) self.assertEquals(expected34, joined34) self.assertEquals(expected34, joined43) joined11 = transf1.join(transf1) self.assertEquals(transf1, joined11)
def test_apply(self) -> None: transf = word_analysis.WordTransformationSequence( [word_analysis.EditTransformation("f", "uncti", ""), word_analysis.EditTransformation("o", "n", "o"), word_analysis.EditTransformation("", "", "bar")] ) transformed, transformee = transf.apply_step("", "function") self.assertEqual(transformed, "foobar") self.assertEqual(transformee, "")
def test_build_word_transformation_schmieren_geschmiert(self) -> None: subsequence_intervals = word_analysis.WordSubsequenceIntervals(word_analysis.LCSMatrix("schmieren", "geschmiert")) transf = word_analysis.build_word_transformation(subsequence_intervals) expected = word_analysis.WordTransformationSequence( [word_analysis.EditTransformation("", "", "ge"), #word_analysis.SkipToTransformation("schmier", "en"), word_analysis.EditTransformation("schmier", "en", "t")] ) self.assertEqual(transf, expected) transformed, transformee = transf.apply_step("", "schmieren") self.assertEqual(transformed, "geschmiert") self.assertEqual(transformee, "")
def test_build_word_transformation_liegen_gelegen(self) -> None: subsequence_intervals = word_analysis.WordSubsequenceIntervals(word_analysis.LCSMatrix("liegen", "gelegen")) transf = word_analysis.build_word_transformation(subsequence_intervals) expected = word_analysis.WordTransformationSequence( [word_analysis.EditTransformation("", "", "ge"), word_analysis.EditTransformation("l", "i", ""), word_analysis.EditTransformation("egen", "", "")] ) self.assertEqual(transf, expected) transformed, transformee = transf.apply_step("", "liegen") self.assertEqual(transformed, "gelegen") self.assertEqual(transformee, "")
def test_join_unjoinable(self) -> None: transf1 = word_analysis.EditTransformation("oo", "ugo", "il") transf3 = word_analysis.EditTransformation("oo", "ugo", "") transf4 = word_analysis.EditTransformation("oo", "", "il") with self.assertRaises(ValueError): transf1.join(transf3) transf1.join(transf4) transf3.join(transf1) transf4.join(transf1) transf3.join(transf4) transf4.join(transf3) transf1.join(word_analysis.SkipToTransformation("foo", "bar")) transf1.join(word_analysis.WordTransformationSequence([transf1]))
def test_maybe_joinable(self) -> None: subt1a = word_analysis.EditTransformation("", "", "ge") subt1b = word_analysis.EditTransformation("", "", "hugo") subt2a = word_analysis.EditTransformation("foo", "bar", "") subt2b = word_analysis.EditTransformation("o", "bar", "") transf1 = word_analysis.WordTransformationSequence([subt1a, subt2a]) transf2 = word_analysis.WordTransformationSequence([subt1b, subt2a]) transf3 = word_analysis.WordTransformationSequence([subt1a, subt2b]) transf4 = word_analysis.WordTransformationSequence([subt1b, subt2b]) transf5 = word_analysis.WordTransformationSequence([subt2a, subt1a]) transf6 = word_analysis.WordTransformationSequence([subt2a, subt1b]) transf7 = word_analysis.WordTransformationSequence([subt2b, subt1a]) self.assertTrue(transf1.maybe_joinable(transf1)) self.assertFalse(transf1.maybe_joinable(transf2)) self.assertFalse(transf2.maybe_joinable(transf1)) self.assertTrue(transf1.maybe_joinable(transf3)) self.assertTrue(transf3.maybe_joinable(transf1)) self.assertFalse(transf1.maybe_joinable(transf4)) self.assertFalse(transf1.maybe_joinable(transf5)) self.assertTrue(transf2.maybe_joinable(transf4)) self.assertFalse(transf2.maybe_joinable(transf3)) self.assertFalse(transf5.maybe_joinable(transf6)) self.assertTrue(transf5.maybe_joinable(transf7))
def test_equals(self) -> None: subt1 = word_analysis.EditTransformation("", "", "ge") subt1f = word_analysis.EditTransformation("", "", "hugo") subt2a = word_analysis.EditTransformation("foo", "bar", "") subt2b = word_analysis.EditTransformation("o", "bar", "") transf1 = word_analysis.WordTransformationSequence([subt1, subt2a]) transf11 = word_analysis.WordTransformationSequence([subt1, subt2a]) transf2 = word_analysis.WordTransformationSequence([subt1, subt2b]) transf3 = word_analysis.WordTransformationSequence([subt1f, subt2a]) transf4 = word_analysis.WordTransformationSequence([subt1]) transf5 = word_analysis.WordTransformationSequence([subt2a, subt1]) self.assertEquals(transf1, transf1) self.assertEquals(transf1, transf11) self.assertEquals(transf11, transf1) self.assertNotEquals(transf2, transf1) self.assertNotEquals(transf1, transf2) self.assertNotEquals(transf11, transf2) self.assertNotEquals(transf2, transf11) self.assertNotEquals(transf1, transf3) self.assertNotEquals(transf1, transf4) self.assertNotEquals(transf1, transf5)
def test_join_single_elements(self) -> None: subt1 = word_analysis.EditTransformation("abc", "foo", "bar") transf1 = word_analysis.WordTransformationSequence([subt1]) transf2 = word_analysis.WordTransformationSequence([word_analysis.EditTransformation("abc", "o", "bar")]) self.assertEquals(transf1, transf1.join(subt1)) self.assertRaises(ValueError, transf2.join, subt1)
def test_maybe_joinable_single_elements(self) -> None: subt1 = word_analysis.EditTransformation("abc", "foo", "bar") transf1 = word_analysis.WordTransformationSequence([subt1]) transf2 = word_analysis.WordTransformationSequence([word_analysis.EditTransformation("abc", "o", "bar")]) self.assertTrue(transf1.maybe_joinable(subt1)) self.assertFalse(transf2.maybe_joinable(subt1))
def test_join_sequence(self) -> None: transf1 = word_analysis.EditTransformation("abc", "deff", "gh") transf2 = word_analysis.WordTransformationSequence([transf1]) transf3 = word_analysis.WordTransformationSequence([word_analysis.EditTransformation("abc", "hk", "dh")]) self.assertEquals(transf2, transf1.join(transf2)) self.assertRaises(ValueError, transf1.join, transf3)
def test_maybe_joinable_sequence(self) -> None: transf1 = word_analysis.EditTransformation("abc", "deff", "gh") transf2 = word_analysis.WordTransformationSequence([transf1]) transf3 = word_analysis.WordTransformationSequence([word_analysis.EditTransformation("abc", "hk", "dh")]) self.assertTrue(transf1.maybe_joinable(transf2)) self.assertFalse(transf1.maybe_joinable(transf3))