Beispiel #1
0
class TestTransitZone(TestCase):
    def setUp(self):
        self.addition1 = Addition(0, 5, "Hello", "me")
        self.addition2 = Addition(4, 3, "123", "me")
        self.addition3 = Addition(6, 5, "World", "me")
        self.addition4 = Addition(6, 5, "monde", "me")
        self.zone = TransitZone("Hello ")

    def tearDown(self):
        pass

    def test_add0(self):
        #test adding at the end
        self.zone.add(self.addition3)
        self.zone.writeModifications()
        self.assertEqual(self.zone.content, "Hello World")

    def test_add1_0(self):
        #test overlaps
        self.zone.add(self.addition1)
        self.zone.add(self.addition2)
        self.zone.writeModifications()
        self.assertEqual(self.zone.content, "HelloHell123o ")

    def test_add1_1(self):
        #write modifications in test 1_0 in reverse order
        self.zone.add(self.addition2)
        self.zone.add(self.addition1)
        self.zone.writeModifications()
        self.assertEqual(self.zone.content, "HelloHell123o ")

    def test_add2_0(self):
        #2nd modification overlaps the previous and the next
        self.zone.add(self.addition1)
        self.zone.add(self.addition2)
        self.zone.add(self.addition3)
        self.zone.writeModifications()
        self.assertEqual(self.zone.content, "HelloHell123o World")

    def test_add2_1(self):
        #reordering of 2_0
        self.zone.add(self.addition1)
        self.zone.add(self.addition3)
        self.zone.add(self.addition2)
        self.zone.writeModifications()
        self.assertEqual(self.zone.content, "HelloHell123o World")

    def test_add2_2(self):
        #reordering of 2_0
        self.zone.add(self.addition2)
        self.zone.add(self.addition1)
        self.zone.add(self.addition3)
        self.zone.writeModifications()
        self.assertEqual(self.zone.content, "HelloHell123o World")

    def test_add2_3(self):
        #reordering of 2_0
        self.zone.add(self.addition2)
        self.zone.add(self.addition3)
        self.zone.add(self.addition1)
        self.zone.writeModifications()
        self.assertEqual(self.zone.content, "HelloHell123o World")

    def test_add2_4(self):
        #reordering of 2_0
        self.zone.add(self.addition3)
        self.zone.add(self.addition2)
        self.zone.add(self.addition1)
        self.zone.writeModifications()
        self.assertEqual(self.zone.content, "HelloHell123o World")

    def test_add2_5(self):
        #reordering of 2_0
        self.zone.add(self.addition3)
        self.zone.add(self.addition1)
        self.zone.add(self.addition2)
        self.zone.writeModifications()
        self.assertEqual(self.zone.content, "HelloHell123o World")

    def test_add3_0(self):
        #write modifications at same position
        self.zone.add(self.addition3)
        self.zone.add(self.addition4)
        self.zone.writeModifications()
        self.assertEqual(self.zone.content, "Hello Worldmonde")

    def test_add3_1(self):
        #reordering of 3_0
        self.zone.add(self.addition4)
        self.zone.add(self.addition3)
        self.zone.writeModifications()
        self.assertEqual(self.zone.content, "Hello mondeWorld")
        #this is a case where the order of the modifications matters

    def test_add4_0(self):
        #The position of the next modification is after the previous's
        #(no overlaps)
        self.zone.add(self.addition1)
        self.zone.add(self.addition3)
        self.zone.writeModifications()
        self.assertEqual(self.zone.content, "HelloHello World")

    def test_add4_1(self):
        #The position of the next modification is before the previous's
        #(reordering of 4_0)
        self.zone.add(self.addition3)
        self.zone.add(self.addition1)
        self.zone.writeModifications()
        self.assertEqual(self.zone.content, "HelloHello World")
Beispiel #2
0
 def setUp(self):
     self.addition1 = Addition(0, 5, "Hello", "me")
     self.addition2 = Addition(4, 3, "123", "me")
     self.addition3 = Addition(6, 5, "World", "me")
     self.addition4 = Addition(6, 5, "monde", "me")
     self.zone = TransitZone("Hello ")
Beispiel #3
0
 def setUp(self):
   self.addition1 = Addition(6, 4, "allo", "me")
   self.removal1 = Removal(0, 11, "me")
   self.removal2 = Removal(6, 5, "me")
   self.addition2 = Addition(6, 5, "monde", "me")
   self.zone = TransitZone("Hello World")
Beispiel #4
0
class TestTransitZone(TestCase):
  def setUp(self):
    self.addition1 = Addition(6, 4, "allo", "me")
    self.removal1 = Removal(0, 11, "me")
    self.removal2 = Removal(6, 5, "me")
    self.addition2 = Addition(6, 5, "monde", "me")
    self.zone = TransitZone("Hello World")

  def tearDown(self):
    pass

  def test_add(self):
    self.zone.add(self.addition1)
    self.zone.add(Addition(0, "test", "me"))
    self.assertFalse(self.zone.isEmpty())

  def test_writeModificationsComplex(self):
    self.zone.add(self.removal1)
    self.zone.add(self.removal2)
    self.zone.add(self.addition1)
    self.zone.add(self.addition2)
    self.zone.writeModifications()
    self.assertEqual(self.zone.content, "allomonde")
    
  def test_returnedVectorWriteModifications(self):
    self.zone.add(self.removal1)
    self.zone.add(self.addition1)
    _,modifications = self.zone.writeModifications()
    self.assertEqual(len(modifications), 2)
    self.assertEqual(modifications[0], self.removal1)
    self.assertEqual(modifications[1], self.addition1)
    
  def test_returnedVectorSameModifications(self):
    additionSame = Addition(self.addition1)
    self.assertEqual(additionSame.position, self.addition1.position)
    self.zone.add(self.addition1)
    self.zone.add(additionSame)
    _,modifications = self.zone.writeModifications()
    self.assertEqual(len(modifications), 2)
    self.assertEqual(modifications[0].position, 6)
    self.assertEqual(modifications[1].position, 10)
    
  def test_writeRemovalEmptyContent(self):
    emptyFileZone = TransitZone("")
    emptyFileZone.add(self.removal1)
    self.zone.writeModifications()
    self.assertEqual(emptyFileZone.content, "")
    
  def test_writeAddAfterRemoval(self):
    self.zone.add(self.removal1)
    self.zone.add(self.addition1)
    self.zone.writeModifications()
    self.assertEqual(self.zone.content, "allo")
    
  def test_writeAddAfterRemovalSamePosition(self):
    self.zone.add(self.removal2)
    self.zone.add(self.addition2)
    self.zone.writeModifications()
    self.assertEqual(self.zone.content, "Hello monde")
      
  def test_writeRemovalAfterAddSamePosition(self):
    self.zone.add(self.addition2)
    self.zone.add(self.removal2)
    self.zone.writeModifications()
    self.assertEqual(self.zone.content, "Hello monde")
    
  def test_writeTwoAddsSamePosition(self):
    self.zone.add(self.addition1)
    self.zone.add(self.addition2)
    self.zone.writeModifications()
    self.assertEqual(self.zone.content, "Hello allomondeWorld")
    
  def test_writeModificationsFromSameBundle0(self):
    bundle = Modifications()
    add0 = Addition(11, "1", "me")
    add1 = Addition(12, "2", "me")
    add2 = Addition(13, "3", "me")
    bundle.extend([add0,add1,add2])
    self.zone.add(bundle)
    self.zone.writeModifications()
    self.assertEqual(self.zone.content, "Hello World123")
    
  def test_writeModificationsFromSameBundle1(self):
    bundle = Modifications()
    add0 = Addition(11, "1", "me")
    add1 = Addition(12, "2", "me")
    add2 = Addition(13, "3", "me")
    rem1 = Removal(13, 1, "me")
    bundle.extend([add0,add1,add2,rem1])
    self.zone.add(bundle)
    self.zone.writeModifications()
    self.assertEqual(self.zone.content, "Hello World12")
    
  def test_writeTwoBundles0(self):
    bundle = Modifications()
    add0 = Addition(11, "1", "me")
    add1 = Addition(12, "2", "me")
    add2 = Addition(13, "3", "me")
    bundle.extend([add0,add1,add2])
    self.zone.add(self.addition1)
    self.zone.add(bundle)
    self.zone.writeModifications()
    self.assertEqual(self.zone.content, "Hello alloWorld123")
    
  def test_writeTwoBundles1(self):
    bundle = Modifications()
    add0 = Addition(11, "1", "me")
    add1 = Addition(12, "2", "me")
    add2 = Addition(13, "3", "me")
    bundle.extend([add0,add1,add2])
    self.zone.add(self.removal1)
    self.zone.add(bundle)
    self.zone.writeModifications()
    self.assertEqual(self.zone.content, "123")
    
  def test_isEmpty(self):
    self.assertTrue(self.zone.isEmpty())
Beispiel #5
0
 def test_writeRemovalEmptyContent(self):
   emptyFileZone = TransitZone("")
   emptyFileZone.add(self.removal1)
   self.zone.writeModifications()
   self.assertEqual(emptyFileZone.content, "")
 def setUp(self):
     self.zone = TransitZone("Hello World")
     self.removal = Removal(6, 5, "me")
class TestTransitZone(TestCase):
    def setUp(self):
        self.zone = TransitZone("Hello World")
        self.removal = Removal(6, 5, "me")

    def tearDown(self):
        pass

    def test_deleteBeforeAdd_Overlaps0(self):
        add = Addition(7, "123", "me")
        self.zone.add(self.removal)
        self.zone.add(add)
        self.zone.writeModifications()
        self.assertEqual(self.zone.content, "Hello 123")

    def test_deletBeforeAdd_Overlaps1(self):
        add = Addition(7, "123", "me")
        self.zone.add(add)
        self.zone.add(self.removal)
        self.zone.writeModifications()
        self.assertEqual(self.zone.content, "Hello rld")
        #order is important in this case

    def test_deleteBeforeAdd_NoOverlaps0(self):
        add = Addition(11, "!", "me")
        self.zone.add(self.removal)
        self.zone.add(add)
        self.zone.writeModifications()
        self.assertEqual(self.zone.content, "Hello !")

    def test_deleteBeforeAdd_NoOverlaps1(self):
        add = Addition(11, "!", "me")
        self.zone.add(add)
        self.zone.add(self.removal)
        self.zone.writeModifications()
        self.assertEqual(self.zone.content, "Hello !")

    def test_addBeforeDelete0(self):
        add = Addition(2, "123", "me")
        self.zone.add(add)
        self.zone.add(self.removal)
        self.zone.writeModifications()
        self.assertEqual(self.zone.content, "He123llo ")

    def test_addBeforeDelete1(self):
        add = Addition(2, "123", "me")
        self.zone.add(self.removal)
        self.zone.add(add)
        self.zone.writeModifications()
        self.assertEqual(self.zone.content, "He123llo ")

    def test_addAndDeleteSamePosition0(self):
        add = Addition(6, "123", "me")
        self.zone.add(self.removal)
        self.zone.add(add)
        self.zone.writeModifications()
        self.assertEqual(self.zone.content, "Hello 123")

    def test_addAndDeleteSamePosition1(self):
        add = Addition(6, "123", "me")
        self.zone.add(add)
        self.zone.add(self.removal)
        self.zone.writeModifications()
        self.assertEqual(self.zone.content, "Hello 123")

    def test_DeleteInDelete0(self):
        removal1 = Removal(7, 3, "me")
        self.zone.add(removal1)
        self.zone.add(self.removal)
        self.zone.writeModifications()
        self.assertEqual(self.zone.content, "Hello ")

    def test_DeleteInDelete1(self):
        removal1 = Removal(7, 3, "me")
        self.zone.add(self.removal)
        self.zone.add(removal1)
        self.zone.writeModifications()
        self.assertEqual(self.zone.content, "Hello ")

    def test_DeletesOverlaps0(self):
        removal1 = Removal(5, 3, "me")
        self.zone.add(self.removal)
        self.zone.add(removal1)
        self.zone.writeModifications()
        self.assertEqual(self.zone.content, "Hello")

    def test_DeletesOverlaps1(self):
        removal1 = Removal(5, 3, "me")
        self.zone.add(removal1)
        self.zone.add(self.removal)
        self.zone.writeModifications()
        self.assertEqual(self.zone.content, "Hello")

    def test_DeletesNoOverlaps0(self):
        removal1 = Removal(0, 5, "me")
        self.zone.add(self.removal)
        self.zone.add(removal1)
        self.zone.writeModifications()
        self.assertEqual(self.zone.content, " ")

    def test_DeletesNoOverlaps1(self):
        removal1 = Removal(0, 5, "me")
        self.zone.add(removal1)
        self.zone.add(self.removal)
        self.zone.writeModifications()
        self.assertEqual(self.zone.content, " ")

    def test_DeletesSamePosition0(self):
        removal1 = Removal(6, 5, "me")
        self.zone.add(self.removal)
        self.zone.add(removal1)
        self.zone.writeModifications()
        self.assertEqual(self.zone.content, "Hello ")

    def test_DeletesSamePosition1(self):
        removal1 = Removal(6, 5, "me")
        self.zone.add(removal1)
        self.zone.add(self.removal)
        self.zone.writeModifications()
        self.assertEqual(self.zone.content, "Hello ")