Skip to content

Instantly share code, notes, and snippets.

@jcasimir
Created October 17, 2023 20:25
Show Gist options
  • Save jcasimir/778a0603b87ead4ee63c28661ef84194 to your computer and use it in GitHub Desktop.
Save jcasimir/778a0603b87ead4ee63c28661ef84194 to your computer and use it in GitHub Desktop.

Revisions

  1. jcasimir created this gist Oct 17, 2023.
    138 changes: 138 additions & 0 deletions tests.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,138 @@
    ## L1. Append Multiple Nodes and Count

    def test_(self):

    import list
    list = list.List()
    self.assertEquals(list.count(), 0)
    list.append("one")
    list.append("two")
    list.append("three")
    list.append("four")
    list.append("five")
    self.assertEquals(list.count(), 5)

    ## L2. Find Index Of

    def test_(self):
    import list
    list = list.List()
    list.append("one")
    list.append("two")
    list.append("three")
    list.append("four")
    list.append("five")
    self.assertEquals(list.find_index_of("four"), 3)

    ## L2. Attempt to Find Things That Don't Exist

    def test_(self):

    import list
    list = list.List()
    self.assertEquals(list.find_value_at(4), None)
    self.assertEquals(list.find_index_of("four"), None)
    list.append("one")
    list.append("two")
    list.append("three")
    self.assertEquals(list.find_value_at(3), None)
    self.assertEquals(list.find_index_of("four"), None)

    ## L2. Find the Value at a Position

    def test_(self):

    import list
    list = list.List()
    list.append("one")
    list.append("two")
    list.append("three")
    list.append("four")
    list.append("five")
    self.assertEquals(list.find_value_at(4), "five")

    ## L3. Insert at a Position

    def test_(self):
    import list
    list = list.List()
    list.append("A")
    list.append("C")
    list.insert_at_position(1, "B")
    self.assertEqual(list.find_index_of("B"), 1)
    list.insert_at_position(3, "D")
    self.assertEqual(list.find_index_of("D"), 3)
    list.insert_at_position(0, "Z")
    self.assertEqual(list.find_index_of("Z"), 0)

    ## L4. Delete by Position To Clear a List

    def test_(self):
    import list
    list = list.List()
    list.append("A")
    list.append("B")
    self.assertEqual(list.count(), 2)
    list.delete_at_position(1)
    list.delete_at_position(0)
    self.assertEqual(list.count(), 0)

    ## L4. Delete by Position Complex Sequence

    def test_(self):
    import list
    list = list.List()
    list.append("A")
    list.append("B")
    list.append("C")
    list.append("D")
    list.append("E")
    list.delete_at_position(0)
    self.assertEqual(list.find_index_of("B"), 0)
    list.delete_at_position(1)
    self.assertEqual(list.find_index_of("B"), 0)
    self.assertEqual(list.find_index_of("C"), None)
    self.assertEqual(list.find_index_of("D"), 1)
    list.delete_at_position(1)
    self.assertEqual(list.find_index_of("B"), 0)
    self.assertEqual(list.find_index_of("E"), 1)
    self.assertEqual(list.count(), 2)
    list.delete_at_position(1)
    list.delete_at_position(0)
    self.assertEqual(list.count(), 0)

    ## L4. Delete by Value Sequence

    def test_(self):
    import list
    list = list.List()
    list.append("A")
    list.append("B")
    list.append("C")
    list.append("D")
    list.append("E")
    list.delete_value("C")
    self.assertEqual(list.find_index_of("D"), 2)
    list.delete_value("A")
    self.assertEqual(list.find_index_of("B"), 0)
    list.delete_value("E")
    self.assertEqual(list.count(), 2)
    list.delete_value("B")
    list.delete_value("D")
    self.assertEqual(list.count(), 0)

    ## L4. Delete by Value Edge Cases

    def test_(self):
    import list
    list = list.List()
    list.delete_value("A")
    list.append("A")
    list.append("B")
    list.append("A")
    self.assertEqual(list.count(), 3)
    list.delete_value("A")
    self.assertEqual(list.count(), 2)
    list.delete_value("C")
    self.assertEqual(list.count(), 2)