Skip to content
Permalink
131edc2245
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
84 lines (72 sloc) 2.59 KB
import unittest
from Exercises1_and_2 import *
from exercises_3_4_5 import *
class Tests(unittest.TestCase):
def test_BTSdelete(self):
result= BinTreeNode.deletion("loves")
result2= BinTreeNode.deletion("kid")
result3= BinTreeNode.deletion("goal")
self.assertIn(result,BinTreeNode(object))
self.assertIn(result2,BinTreeNode(object))
self.assertIn(result3,BinTreeNode(object))
def test_BTSsearch(self):
result="kid"
result2="loves"
result3="goal"
self.assertTrue(BinTreeNode.search(result))
self.assertTrue(BinTreeNode.search(result2))
self.assertTrue(BinTreeNode.search(result3))
def test_BTSinsert(self):
word="now"
word2="blue"
word3="sky"
result=BinTreeNode.insertValue(word)
result=BinTreeNode.insertValue(word2)
result=BinTreeNode.insertValue(word3)
self.assertIn(word,BinTreeNode(object))
self.assertIn(word2,BinTreeNode(object))
self.assertIn(word3,BinTreeNode(object))
def test_GraphAddVertice(self):
newVertice=10
newVertice2=8
newVertice3=6
result=graph.addVertice(newVertice)
result2=graph.addVertice(newVertice2)
result3=graph.addVertice(newVertice3)
self.assertIn(newVertice,graph.vertices())
self.assertIn(newVertice2,graph.vertices())
self.assertIn(newVertice3,graph.vertices())
def test_GraphAddEdge(self):
newEdge={5,1}
newEdge2={3,4}
newEdge3={5,4}
result=graph.addEdge(newEdge)
result=graph.addEdge(newEdge2)
result=graph.addEdge(newEdge3)
self.assertIn(newEdge,graph.getEdges())
self.assertIn(newEdge2,graph.getEdges())
self.assertIn(newEdge3,graph.getEdges())
def test_GraphConnected(self):
result=graph.isConnected(3)
result2=graph.isConnected(5)
self.assertFalse(result)
self.assertFalse(result2)
def test_GraphIsPath(self):
node1=1
node2=3
result=graph.isPath(node1,node2)
self.assertTrue(result)
node1=1
node=5
result2=graph.isPath(node1,node2)
self.assertFalse(result2)
def test_GraphBFS(self):
list3=[3, 0, 1, 2, 4]
result=graph.dfs(3)
self.assertIs(result,list3)
def test_GraphDFS(self):
list4=[4, 0, 2, 1, 3]
result=graph.bfs(4)
self.assertIs(result,list4)
if __name__ == '__main__':
unittest.main()