class DiGraphTest(unittest.TestCase):
  def setUp(self):
    self.digraph = DiGraph()
    return

  def test_add_edges_from_file_using_good_input_adds_edges(self):
    good_input = open('goodInput')
    self.digraph.add_edges_from_file(good_input)
    # we know that 'A' should be present.
    self.assertIn('A', self.digraph.out_edge_map)
    self.assertIn('B', self.digraph.in_edge_map)

  def test_add_edges_from_file_using_bad_input_throw_error(self):
    bad_input = open('badInput')
    self.assertRaises(ValueError, self.digraph.add_edges_from_file, bad_input)

  def test_remove_nodes_with_single_in_and_single_out_edges_works(self):
    self.digraph.remove_nodes_with_single_in_and_single_out_edges()
    self.assertNotIn('B', self.digraph.out_edge_map)
    self.assertNotIn('B', self.digraph.in_edge_map)
 def setUp(self):
   self.digraph = DiGraph()
   return
from walkscore.digraph import DiGraph
"""
Test script to represent graph and remove nodes with
exactly one incoming and one outgoing edge.
"""

if __name__ == '__main__':
  infile2 = open('input/2')
  infile3 = open('input/3')
  infile4 = open('input/4')
  infile5 = open('input/5')
  outfile2 = open('output/2', 'w')
  outfile3 = open('output/3', 'w')
  outfile4 = open('output/4', 'w')
  outfile5 = open('output/5', 'w')
  digraph2 = DiGraph()
  digraph2.add_edges_from_file(infile2)
  digraph2.remove_nodes_with_single_in_and_single_out_edges()
  digraph2.print_edges_to_file(outfile2)
  digraph3 = DiGraph()
  digraph3.add_edges_from_file(infile3)
  digraph3.remove_nodes_with_single_in_and_single_out_edges()
  digraph3.print_edges_to_file(outfile3)
  digraph4 = DiGraph()
  digraph4.add_edges_from_file(infile4)
  digraph4.remove_nodes_with_single_in_and_single_out_edges()
  digraph4.print_edges_to_file(outfile4)
  digraph5 = DiGraph()
  digraph5.add_edges_from_file(infile5)
  digraph5.remove_nodes_with_single_in_and_single_out_edges()
  digraph5.print_edges_to_file(outfile5)