Example #1
0
    def test_universal(self):
        """
        testing all features on a single rope object at once
        Note: This is a time consuming testcase(6-8 min. depending on system).
        It uses bruteforce string operations and compares them with equivalent
        Rope operations. It's an exahustive testcase which checks all possible
        valid combinations of rope operations. You can track progress of test
        at file stored in "current_directory/test_universal.txt" file.

        Also note that this testcase tests only complex rope methods where there
        can be chances of missing corner cases.
        """
        s = string.ascii_lowercase
        r = Rope()
        for c in s:
            r.append(c)
        s += string.ascii_uppercase
        for c in string.ascii_uppercase:
            r += c

        output_file = open('test_universal.txt', 'w')

        # test_equality
        print("testing... equality", flush=True, file=output_file)
        self.assertEqual(s, str(r))
        self.assertEqual(len(s), len(r))
        self.assertEqual(len(r), r.size)

        print("testing... find", flush=True, file=output_file)
        self.test_find(s, r)

        print("testing... delete", flush=True, file=output_file)
        self.test_delete(list(s), r)
        # passed 'list' in delete because str don't support deletion

        print("testing... index_onenode", flush=True, file=output_file)
        self.test_index_onenode(s, r)

        print("testing... index_threenode", flush=True, file=output_file)
        self.test_index_threenode(s, r)

        print("testing... length", flush=True, file=output_file)
        self.test_length(s, r)

        print("testing... word_iteration", flush=True, file=output_file)
        self.test_word_iteration(s, r)

        print("testing... stride_threenode", flush=True, file=output_file)
        self.test_stride_threenode(s, r)

        print("testing... slice_threenode", flush=True, file=output_file)
        self.test_slice_threenode(s, r)

        print("testing... slice_onenode", flush=True, file=output_file)
        self.test_slice_onenode(s, r)

        print("testing... reverse", flush=True, file=output_file)
        self.test_reverse(s, r)

        output_file.close()
Example #2
0
 def test_split(self, s=None, r=None):
     if s is None or r is None:
         s = string.ascii_letters
         r = Rope(s, 3)
     for i in range(-len(s), len(s) + 1):
         left, right = r.split(i)
         self.assertEqual(str(left), s[:i])
         self.assertEqual(str(right), s[i:])
         r.append(right)
Example #3
0
    def test_append(self):
        s = [
            'this_is a test', 'string', 'used for testing',
            'concatnation of ropes', 'of different leafsize'
        ]
        rope_array = []
        for sub in s:
            rope_array.append(Rope(sub, 4))

        for string, rope in zip(s, rope_array):
            self.assertEqual(string, str(rope))
            self.assertEqual(len(string), len(rope))
            self.assertEqual(len(string), rope.size)

        s = ''.join(s)

        rope = Rope()
        for sub in rope_array:
            rope.append(sub)
        self.assertEqual(s, str(rope))
        self.assertEqual(len(s), len(rope))
        self.assertEqual(len(s), rope.size)