Beispiel #1
0
	completed_tests += 1
	if (expected != received):
		failed_tests += 1
		print('Mismatch in test ' + str(completed_tests))
		print('Expected:')
		print(expected)
		print('Got:')
		print(received)

	print('Failed ' + str(failed_tests) + ' out of ' + str(completed_tests) + ' total tests')

# Node unit tests
node = Node('A')
assert_equal('A', node.value)
node2 = Node('T')
node.add_neighbour(node2)
node.add_neighbour(node2)
assert_equal(1, len(node.neighbours))

# Graph unit tests
graph = Graph('test', 'ACTGGCTAGAAGCGCGCT')
assert_equal('test', graph.name)
assert_equal('ACTGGCTAGAAGCGCGCT', get_linear_sequence(graph))
assert_equal(1, len(get_all_sequences(graph)))
assert_equal('ACTGGCTAGAAGCGCGCT', get_all_sequences(graph)[0])

node1 = graph.head.neighbours[0]
node2 = node1.neighbours[0]
node3 = node2.neighbours[0]
node4 = node3.neighbours[0]
def draw_graph(graph):
	win = GraphWin(graph.name, WIDTH, HEIGHT)
	draw_graph_rec(win, graph.head, START_X, START_Y)
	win.getMouse()

def draw_graph_rec(win, curr, x, y):
	draw_node(win, curr, x, y)
	i = 0
	for neighbour in curr.neighbours:
		draw_graph_rec(win, neighbour, x + SPACING, y + (SPACING * i))
		draw_edge(win, x, y, x + SPACING, y + (SPACING * i))
		i += 1

def draw_node(win, node, x, y):
	pt = Point(x, y)
	circle = Circle(pt, RADIUS)
	circle.draw(win)
	text = Text(pt, node.value)
	text.draw(win)

def draw_edge(win, start_x, start_y, end_x, end_y):
	edge = Line(Point(start_x + RADIUS, start_y), Point(end_x - RADIUS, end_y))
	edge.draw(win)

if __name__ == '__main__':
	graph = Graph('Test', 'ACTGGTCATTAGGGATC')
	node2 = Node('T')
	graph.head.neighbours[0].add_neighbour(node2)
	node2.add_neighbour(graph.head.neighbours[0].neighbours[0].neighbours[0])
	draw_graph(graph)