Пример #1
0
 def testSlicing(self):
     r1 = ropes.Rope(para1)
     r1 += ropes.Rope(para2)
     s1 = para1 + para2
     start = random.randint(0, len(r1) - 1)
     end = random.randint(start + 1, len(r1))
     self.assertEqual(str(r1[start:end]), s1[start:end])
Пример #2
0
 def testCut_On_commonPrefix(self):
     editor = TextEditor.SimpleEditor(commonPrefix,commonPrefix)
     length = len(commonPrefix_as_str)
     random_i = randint(0,length - 1)
     random_j = randint(random_i,length)
     editor.cut(random_i,random_j)
     self.assertEqual(editor.paste_text, ropes.Rope(commonPrefix_as_str[random_i:random_j]))
     self.assertEqual(editor.document, ropes.Rope(commonPrefix_as_str[:random_i]) + ropes.Rope(commonPrefix_as_str[random_j:]))
Пример #3
0
 def testCut_On_manySpaces(self):
     editor = TextEditor.SimpleEditor(manySpaces,manySpaces)
     length = len(manySpaces_as_str)
     random_i = randint(0,length - 1)
     random_j = randint(random_i,length)
     editor.cut(random_i,random_j)
     self.assertEqual(editor.paste_text, ropes.Rope(manySpaces_as_str[random_i:random_j]))
     self.assertEqual(editor.document, ropes.Rope(manySpaces_as_str[:random_i]) + ropes.Rope(manySpaces_as_str[random_j:]))
Пример #4
0
 def testCut_On_numbersAndWords(self):
     editor = TextEditor.SimpleEditor(numbersAndWords,numbersAndWords)
     length = len(numbersAndWords_as_str)
     random_i = randint(0,length - 1)
     random_j = randint(random_i,length)
     editor.cut(random_i,random_j)
     self.assertEqual(editor.paste_text, ropes.Rope(numbersAndWords_as_str[random_i:random_j]))
     self.assertEqual(editor.document, ropes.Rope(numbersAndWords_as_str[:random_i]) + ropes.Rope(numbersAndWords_as_str[random_j:]))
Пример #5
0
 def testCopy_On_commonText(self):
     editor = TextEditor.SimpleEditor(commonText1,commonText1)
     length = len(commonPrefix_as_str)
     random_i = randint(0,length - 1)
     random_j = randint(random_i,length)
     editor.copy(random_i,random_j)
     self.assertEqual(editor.paste_text, ropes.Rope(commonText1_as_str[random_i:random_j]))
Пример #6
0
 def populateDocumentWithInputText(self, filename):
     '''
     A function to populate the self.document as a rope containing rope the input file's text.
     '''
     with open(filename, "r") as fi:
         data_text = fi.read()
         self.document = ropes.Rope(data_text)
Пример #7
0
 def testCopyPaste_On_manySpaces(self):
     editor = TextEditor.SimpleEditor(manySpaces,manySpaces)
     length = len(manySpaces_as_str)
     random_i = randint(0,length - 1)
     random_j = randint(random_i,length)
     editor.copy(random_i,random_j)
     random_paste_index = randint(0,length)
     editor.paste(random_paste_index)
     self.assertEqual(editor.document, ropes.Rope(manySpaces_as_str[:random_paste_index ]) + ropes.Rope(manySpaces_as_str[random_i:random_j]) + ropes.Rope(manySpaces_as_str[random_paste_index :]) )
Пример #8
0
 def testCopyPaste_On_commonPrefix(self):
     editor = TextEditor.SimpleEditor(commonPrefix,commonPrefix)
     length = len(commonPrefix_as_str)
     random_i = randint(0,length - 1)
     random_j = randint(random_i,length)
     editor.copy(random_i,random_j)
     random_paste_index = randint(0,length)
     editor.paste(random_paste_index)
     self.assertEqual(editor.document, ropes.Rope(commonPrefix_as_str[:random_paste_index ]) + ropes.Rope(commonPrefix_as_str[random_i:random_j]) + ropes.Rope(commonPrefix_as_str[random_paste_index :]) )
Пример #9
0
 def testCopyPaste_On_numbersAndWords(self):
     editor = TextEditor.SimpleEditor(numbersAndWords,numbersAndWords)
     length = len(numbersAndWords_as_str)
     random_i = randint(0,length - 1)
     random_j = randint(random_i,length)
     editor.copy(random_i,random_j)
     random_paste_index = randint(0,length)
     editor.paste(random_paste_index)
     self.assertEqual(editor.document, ropes.Rope(numbersAndWords_as_str[:random_paste_index ]) + ropes.Rope(numbersAndWords_as_str[random_i:random_j]) + ropes.Rope(numbersAndWords_as_str[random_paste_index :]) )
Пример #10
0
 def __init__(self, documentPath, dictionaryFilePath):
     # Create Trie to store dictionary words
     self.dictionaryTrie = Trie.Trie()
     # Create rope structure for document
     self.document = None
     self.populateDocumentWithInputText(documentPath)
     # Insert dictionary words in Trie
     for word in self.yieldWords(dictionaryFilePath):
         self.dictionaryTrie.insert(word, self.dictionaryTrie.root)
     # Create an empty rope object to later store pasted text
     self.paste_text = ropes.Rope("")
Пример #11
0
 def testAppends(self):
     r1 = ropes.Rope()
     r2 = ropes.Rope()
     r2 += ropes.Rope(para4)
     r2 += ropes.Rope(para5)
     r1 += ropes.Rope(para1)
     r1 += ropes.Rope(para2)
     r1 += ropes.Rope(para3)
     r1 += r2
     self.assertEqual(str(r1), para1 + para2 + para3 + para4 + para5)
Пример #12
0
 def testComparisons(self):
     r1 = ropes.Rope(para1 + para2)
     r2 = ropes.Rope(para1)
     r2 += ropes.Rope(para2)
     self.assertEqual(r1, r2)
     r1 = ropes.Rope('hello') * 3
     r2 = ropes.Rope('hello') * 2
     r2 += ropes.Rope('hello')
     self.assertEqual(r1, r2)
Пример #13
0
 def testBalance(self):
     r1 = ropes.Rope()
     r1 += ropes.Rope(para1)
     r1 += ropes.Rope(para2)
     r1 += ropes.Rope(para3)
     r1 += ropes.Rope(para4)
     r1 += ropes.Rope(para5)
     r1.balance()
     self.assertEqual(str(r1), para1 + para2 + para3 + para4 + para5)
Пример #14
0
 def testRepetition(self):
     r1 = ropes.Rope('hello')
     r1 *= 100
     self.assertEqual(str(r1), 'hello' * 100)
Пример #15
0
 def testLength(self):
     r1 = ropes.Rope('hell')
     r1 += ropes.Rope('o, w')
     r1 += ropes.Rope('orld')
     self.assertEqual(len(r1), 12)
Пример #16
0
 def testCopy_On_empty(self):
     editor = TextEditor.SimpleEditor(empty,empty)
     editor.copy(0,0)
     self.assertEqual(editor.paste_text, ropes.Rope(""))
Пример #17
0
 def testEditorCreation_On_numbersAndWords(self):
     editor = TextEditor.SimpleEditor(numbersAndWords,numbersAndWords)
     self.assertEqual(editor.paste_text, ropes.Rope(""))
     for word in numbersAndWords_WordsWithoutPunctuation:
         self.assertEqual(editor.dictionaryTrie.find(word),True)
     self.assertEqual(editor.document,ropes.Rope(numbersAndWords_as_str))
Пример #18
0
 def testEditorCreation_On_manySpaces(self):
     editor = TextEditor.SimpleEditor(manySpaces,manySpaces)
     self.assertEqual(editor.paste_text, ropes.Rope(""))
     for word in manySpaces_WordsWithoutPunctuation:
         self.assertEqual(editor.dictionaryTrie.find(word),True)
     self.assertEqual(editor.document,ropes.Rope(manySpaces_as_str))
Пример #19
0
 def testEditorCreation_On_Empty(self):
     editor = TextEditor.SimpleEditor(empty,empty)
     self.assertEqual(editor.paste_text, ropes.Rope(""))
     self.assertEqual(len(editor.dictionaryTrie.root.children),0)
     self.assertEqual(editor.document,ropes.Rope(empty_as_str))
Пример #20
0
 def testEditorCreation_On_CommonPrefix(self):
     editor = TextEditor.SimpleEditor(commonPrefix,commonPrefix)
     self.assertEqual(editor.paste_text, ropes.Rope(""))
     for word in commonPrefix_WordsWithoutPunctuation:
         self.assertEqual(editor.dictionaryTrie.find(word),True)
     self.assertEqual(editor.document,ropes.Rope(commonPrefix_as_str))
Пример #21
0
 def testLength(self):
     r1 = ropes.Rope('hello')
     r1 *= 100
     self.assertEqual(len(r1), 500)
Пример #22
0
 def testHashing(self):
     r1 = ropes.Rope(para1 + para2 + para3)
     r2 = ropes.Rope(para1)
     r2 += ropes.Rope(para2)
     r2 = r2 + ropes.Rope(para3)
     self.assertEqual(hash(r1), hash(r2))
Пример #23
0
 def testCut_On_empty(self):
     editor = TextEditor.SimpleEditor(empty,empty)
     editor.cut(0,0)
     self.assertEqual(editor.paste_text, ropes.Rope(""))
     self.assertEqual(editor.document, ropes.Rope(""))
Пример #24
0
 def testIteration(self):
     r1 = ropes.Rope(para1 + para2 + para3)
     r2 = ropes.Rope('')
     for c in r1:
         r2 += ropes.Rope(c)
     self.assertEqual(str(r1), str(r2))
Пример #25
0
 def testCopyPaste_On_empty(self):
     editor = TextEditor.SimpleEditor(empty,empty)
     editor.copy(0,0)
     random_paste_index = randint(0,0)
     editor.paste(random_paste_index)
     self.assertEqual(editor.document, ropes.Rope("") )