Esempio n. 1
0
    def test_trim_ending_whitespace(self):
        #do no harm
        assert ja.JaggedTextArray(
            twoby).trim_ending_whitespace() == ja.JaggedTextArray(twoby)
        assert ja.JaggedTextArray(
            threeby).trim_ending_whitespace() == ja.JaggedTextArray(threeby)

        twoby_with_space = [[
            "Line 1:1", "This is the first second", "First third", "", "", ""
        ], ["Chapter 2, Verse 1", "2:2", "2:3", ""],
                            ["Third first", "Third second", "Third third"]]
        threeby_with_space = [
            [[
                "Part 1 Line 1:1", "This is the first second", "First third",
                "", "", ""
            ], ["Chapter 2, Verse 1", "2:2", "2:3", "", ""],
             ["Third first", "Third second", "Third third", ""]],
            [["Part 2 Line 1:1", "This is the first second", "First third"],
             ["Chapter 2, Verse 1", "2:2", "2:3", "", "", ""],
             ["Third first", "Third second", "Third third"]],
            [["Part 3 Line 1:1", "This is the first second", "First third"],
             ["Chapter 2, Verse 1", "2:2", "2:3"],
             ["Third first", "Third second", "Third third", ""]],
        ]
        assert ja.JaggedTextArray([
            "a", "b", "c", "", ""
        ]).trim_ending_whitespace() == ja.JaggedTextArray(["a", "b", "c"])
        assert ja.JaggedTextArray(twoby_with_space).trim_ending_whitespace(
        ) == ja.JaggedTextArray(twoby)
        assert ja.JaggedTextArray(threeby_with_space).trim_ending_whitespace(
        ) == ja.JaggedTextArray(threeby)
Esempio n. 2
0
    def test_FAILING_IN_SUITE_trim_ending_whitespace(self):
        # Note - this test can fail when run in the full suite, because earlier test data bleeds through.
        # See warning at top of jagged_array.py
        #do no harm
        assert ja.JaggedTextArray(
            twoby).trim_ending_whitespace() == ja.JaggedTextArray(twoby)
        assert ja.JaggedTextArray(
            threeby).trim_ending_whitespace() == ja.JaggedTextArray(threeby)

        twoby_with_space = [[
            "Line 1:1", "This is the first second", "First third", "", "", ""
        ], ["Chapter 2, Verse 1", "2:2", "2:3", ""],
                            ["Third first", "Third second", "Third third"]]
        threeby_with_space = [
            [[
                "Part 1 Line 1:1", "This is the first second", "First third",
                "", "", ""
            ], ["Chapter 2, Verse 1", "2:2", "2:3", "", ""],
             ["Third first", "Third second", "Third third", ""]],
            [["Part 2 Line 1:1", "This is the first second", "First third"],
             ["Chapter 2, Verse 1", "2:2", "2:3", "", "", ""],
             ["Third first", "Third second", "Third third"]],
            [["Part 3 Line 1:1", "This is the first second", "First third"],
             ["Chapter 2, Verse 1", "2:2", "2:3"],
             ["Third first", "Third second", "Third third", ""]],
        ]
        assert ja.JaggedTextArray([
            "a", "b", "c", "", ""
        ]).trim_ending_whitespace() == ja.JaggedTextArray(["a", "b", "c"])
        assert ja.JaggedTextArray(twoby_with_space).trim_ending_whitespace(
        ) == ja.JaggedTextArray(twoby)
        assert ja.JaggedTextArray(threeby_with_space).trim_ending_whitespace(
        ) == ja.JaggedTextArray(threeby)
Esempio n. 3
0
 def test_overlap(self):
     a = ja.JaggedTextArray([["", "b", ""], ["d", "", "f"], ["", "h", ""]])
     b = ja.JaggedTextArray([["", "", "c"], ["", "e", ""], ["g", "", ""]])
     c = ja.JaggedTextArray([["", "", ""], ["", "q", ""], ["", "", ""]])
     assert not a.overlaps(b)
     assert not a.overlaps(c)
     assert b.overlaps(c)
Esempio n. 4
0
 def test_sections(self):
     assert ja.JaggedTextArray(twoby).sections() == [[0], [1], [2]]
     assert ja.JaggedTextArray(threeby).sections() == [[0, 0], [0,
                                                                1], [0, 2],
                                                       [1, 0], [1,
                                                                1], [1, 2],
                                                       [2, 0], [2, 1],
                                                       [2, 2]]
Esempio n. 5
0
 def test_distance(self):
     jia = ja.JaggedTextArray(threeby)
     jia_empty = ja.JaggedTextArray(threeby_empty_section)
     assert jia.distance([0], [0, 0, 2]) == 2  #check if padding correctly
     assert jia.distance([0], [0, 2]) == 6  #padding for both inputs
     assert jia.distance([0, 0, 1], [2, 2, 2]) == 25  #recursive distance
     assert jia_empty.distance([0, 0, 1], [3, 2, 2]) == 25
     assert jia_empty.distance([0, 0, 1], [2, 1, 3]) == 17
Esempio n. 6
0
    def test_resize_with_empty_string(self):
        a = ["Foo","Bar","","Quux"]
        assert ja.JaggedTextArray(a).resize(1).resize(-1) == ja.JaggedTextArray(a)

        # A bug had left [] alone during downsize.
        b = [["Foo"],["Bar"],[],["Quux"]]
        c = [["Foo"],["Bar"],[""],["Quux"]]

        jb = ja.JaggedTextArray(b).resize(-1)
        jc = ja.JaggedTextArray(c).resize(-1)
        assert jb == jc, "{} != {}".format(jb.array(), jc.array())
Esempio n. 7
0
 def test_mask(self):
     assert ja.JaggedTextArray(twoby).mask() == ja.JaggedIntArray(two_by_mask)
     assert ja.JaggedTextArray(
         [
             ["a",[],[],["",""],["b"]],
             ["a",[],["","a"],["",""],["b"]]
         ]
     ).mask() == ja.JaggedIntArray(
         [
             [1,[],[],[0,0],[1]],
             [1,[],[0,1],[0,0],[1]]
         ]
     )
Esempio n. 8
0
 def test_depth_0(self):
     j = ja.JaggedTextArray("Fee Fi Fo Fum")
     assert j.store == "Fee Fi Fo Fum"
     assert j.is_full()
     assert not j.is_empty()
     assert j.verse_count() == 1
     assert j.mask() == ja.JaggedIntArray(1)
Esempio n. 9
0
    def test_next_prev(self):
        sparse_ja = ja.JaggedTextArray([["","",""],["","foo","","bar",""],["","",""]])
        assert sparse_ja.next_index([0,0]) == [1, 1]
        assert sparse_ja.next_index([]) == [1, 1]
        assert sparse_ja.next_index() == [1, 1]

        assert sparse_ja.prev_index([]) == [1, 3]
        assert sparse_ja.prev_index() == [1, 3]
Esempio n. 10
0
 def test_set_element(self):
     j = ja.JaggedTextArray(twoby).set_element([1, 1], "Foobar")
     assert j.get_element([1, 1]) == "Foobar"
     assert j.array() == [[
         "Line 1:1", "This is the first second", "First third"
     ], ["Chapter 2, Verse 1", "Foobar", "2:3"],
                          ["Third first", "Third second", "Third third"]]
     j = ja.JaggedTextArray(twoby).set_element([1],
                                               ["Foobar", "Flan", "Bob"])
     assert j.get_element([1]) == ["Foobar", "Flan", "Bob"]
     assert j.array() == [[
         "Line 1:1", "This is the first second", "First third"
     ], ["Foobar", "Flan", "Bob"],
                          ["Third first", "Third second", "Third third"]]
     j = ja.JaggedTextArray()
     assert j.set_element([2, 3],
                          "Foo").array() == [[], [],
                                             [None, None, None, "Foo"]]
Esempio n. 11
0
 def test_is_empty(self):
     assert not ja.JaggedTextArray(twoby).is_empty()
     assert not ja.JaggedTextArray(threeby).is_empty()
     assert ja.JaggedTextArray([]).is_empty()
     assert ja.JaggedTextArray([[]]).is_empty()
     assert ja.JaggedTextArray([[""]]).is_empty()
     assert not ja.JaggedTextArray([["a", "b", "c", ""]]).is_empty()
     assert not ja.JaggedTextArray([["a", "b", "c", [""]]]).is_empty()
Esempio n. 12
0
 def test_flatten(self):
     assert ja.JaggedTextArray(threeby).flatten_to_array() == [
         "Part 1 Line 1:1", "This is the first second", "First third",
         "Chapter 2, Verse 1", "2:2", "2:3", "Third first", "Third second",
         "Third third", "Part 2 Line 1:1", "This is the first second",
         "First third", "Chapter 2, Verse 1", "2:2", "2:3", "Third first",
         "Third second", "Third third", "Part 3 Line 1:1",
         "This is the first second", "First third", "Chapter 2, Verse 1",
         "2:2", "2:3", "Third first", "Third second", "Third third"
     ]
Esempio n. 13
0
    def test_modify_by_func(self):
        j = ja.JaggedTextArray(threeby_empty_section)
        self.modifier_input = []
        j.modify_by_function(self.modifier)
        assert self.modifier_input[0][1] == [0, 0, 0]
        assert self.modifier_input[-1][1] == [3, 2, 2]
        assert self.modifier_input[-1][0] == threeby_empty_section[3][2][2]

        self.modifier_input = []
        j.modify_by_function(self.modifier, start_sections=[1, 2, 3, 4, 5])
        assert self.modifier_input[0][1] == [1, 2, 3, 4, 5]
        assert self.modifier_input[-1][1] == [1, 2, 6, 2, 2]
Esempio n. 14
0
    def test_mask(self):
        assert ja.JaggedTextArray(twoby).mask() == ja.JaggedIntArray(
            two_by_mask)
        assert ja.JaggedTextArray([["a", [], [], ["", ""], ["b"]],
                                   ["a", [], ["", "a"], ["", ""],
                                    ["b"]]]).mask() == ja.JaggedIntArray(
                                        [[1, [], [], [0, 0], [1]],
                                         [1, [], [0, 1], [0, 0], [1]]])

        assert ja.JaggedTextArray([["a", [], [], ["", ""], ["b"]],
                                   ["a", [], ["", "a"], ["", ""],
                                    ["b"]]]).zero_mask() == ja.JaggedIntArray(
                                        [[0, [], [], [0, 0], [0]],
                                         [0, [], [0, 0], [0, 0], [0]]])

        assert ja.JaggedTextArray(
            [["a", [], [], ["", ""], ["b"]],
             ["a", [], ["", "a"], ["", ""],
              ["b"]]]).constant_mask(None) == ja.JaggedIntArray(
                  [[None, [], [], [None, None], [None]],
                   [None, [], [None, None], [None, None], [None]]])
    def test_subarray(self):
        assert ja.JaggedTextArray(threeby).subarray(
            [0], [0]) == ja.JaggedTextArray([[
                "Part 1 Line 1:1", "This is the first second", "First third"
            ], ["Chapter 2, Verse 1", "2:2",
                "2:3"], ["Third first", "Third second", "Third third"]])
        assert ja.JaggedTextArray(threeby).subarray(
            [1], [1]) == ja.JaggedTextArray([[
                "Part 2 Line 1:1", "This is the first second", "First third"
            ], ["Chapter 2, Verse 1", "2:2",
                "2:3"], ["Third first", "Third second", "Third third"]])
        assert ja.JaggedTextArray(threeby).subarray(
            [1, 1, 1],
            [1, 2, 1]) == ja.JaggedTextArray([["2:2", "2:3"],
                                              ["Third first", "Third second"]])

        assert ja.JaggedTextArray(threeby).subarray(
            [1, 1, 1], [1, 1, 2]) == ja.JaggedTextArray(["2:2", "2:3"], )
Esempio n. 16
0
 def test_equality(self):
     assert ja.JaggedTextArray(twoby) == ja.JaggedTextArray(twoby)
     assert ja.JaggedTextArray(threeby) == ja.JaggedTextArray(threeby)
     assert ja.JaggedTextArray(twoby) != ja.JaggedTextArray(threeby)
 def test_count_words(self):
     assert ja.JaggedTextArray(twoby).count_words() == 21
Esempio n. 18
0
 def test_count_chars(self):
     assert ja.JaggedTextArray(twoby).char_count() == 101
     assert ja.JaggedTextArray(threeby).char_count() == 324
Esempio n. 19
0
 def test_verse_count(self):
     assert ja.JaggedTextArray(twoby).verse_count() == 9
     assert ja.JaggedTextArray(threeby).verse_count() == 27
 def test_count_chars(self):
     assert ja.JaggedTextArray(twoby).count_chars() == 101
Esempio n. 21
0
 def test_count_words(self):
     assert ja.JaggedTextArray(twoby).word_count() == 21
     assert ja.JaggedTextArray(threeby).word_count() == 69
Esempio n. 22
0
 def test_resize(self):
     assert ja.JaggedTextArray(twoby).resize(1).resize(
         -1) == ja.JaggedTextArray(twoby)
Esempio n. 23
0
 def test_shape(self):
     assert ja.JaggedTextArray(twoby).shape() == [3, 3, 3]
     assert ja.JaggedTextArray(threeby).shape() == [[3, 3, 3], [3, 3, 3],
                                                    [3, 3, 3]]
     assert ja.JaggedTextArray(["a", "b", "c"]).shape() == 3
 def test_flatten_to_string(self):
     assert ja.JaggedTextArray("Test").flatten_to_string() == "Test"
     assert ja.JaggedTextArray(["Test", "More", "Test"
                                ]).flatten_to_string() == "Test More Test"
 def test_until_last_nonempty(self):
     sparse_ja = ja.JaggedTextArray([["", "",
                                      ""], ["", "foo", "", "bar", ""],
                                     ["", "", ""], []])
     assert sparse_ja.sub_array_length([], until_last_nonempty=True) == 3
 def test_distance(self):
     jia = ja.JaggedTextArray(threeby)
     assert jia.distance([0], [0, 0, 2]) == 2  #check if padding correctly
     assert jia.distance([0], [0, 2]) == 6  #padding for both inputs
     assert jia.distance([0, 0, 1], [2, 2, 2]) == 25  #recursive distance