from graph import *
import sys


def test1():
    gr = \
    """a: b, c
    b: c, d
    c: b
    d: c
    """
    print "Test #1:"
    print gr

    al = adjlist(gr)
    am = adjmatrix(al)
    nl = ['a','b','c','d']
    reach = {}
    for n in nl:
        reach[n] = nodes(al, n)

    #print al
    assert set(al['a']) == {'b','c'}
    assert set(al['b']) == {'c','d'}
    assert set(al['c']) == {'b'}
    assert set(al['d']) == {'c'}
    #print am
    assert str(am), "[[0, 1, 1, 0], [0, 0, 1, 1], [0, 1, 0, 0], [0, 0, 1, 0]]"

    #print reach
    # use a set to check equality to ignore order
    assert set(reach['a']) == {'a','b','c','d'}
    assert set(reach['b']) == {'b','c','d'}
    assert set(reach['c']) == {'b','c','d'}
    assert set(reach['d']) == {'b','c','d'}

def test2():
    gr = \
    """Paul: Jenny
    Jenny: Marcelo
    Marcelo: Chris, Eileen, Pamela
    Chris: Terence
    Eileen: Paul
    Pamela: Paul
    Terence: Paul

    """

    print "Test #2:"
    print gr

    al = adjlist(gr)
    am = adjmatrix(al)
    nl = ['Paul', 'Jenny', 'Marcelo', 'Chris', 'Eileen', 'Pamela', 'Terence']
    reach = {}
    for n in nl:
        reach[n] = nodes(al, n)

    #print al
    assert set(al['Paul']) == {'Jenny'}
    assert set(al['Jenny']) == {'Marcelo'}
    assert set(al['Marcelo']) == {'Chris', 'Eileen', 'Pamela'}
    assert set(al['Eileen']) == {'Paul'}
    assert set(al['Pamela']) == {'Paul'}
    assert set(al['Terence']) == {'Paul'}
    
    #print am
    assert str(am), "[[0, 1, 0, 0, 0, 0, 0],"+\
                          " [0, 0, 1, 0, 0, 0, 0],"+\
                          " [0, 0, 0, 1, 1, 1, 0],"+\
                          " [0, 0, 0, 0, 0, 0, 1],"+\
                          " [1, 0, 0, 0, 0, 0, 0],"+\
                          " [1, 0, 0, 0, 0, 0, 0],"+\
                          " [1, 0, 0, 0, 0, 0, 0]]"

    #print reach
    # use a set to check equality to ignore order
    assert set(reach['Paul']) == {'Paul', 'Jenny', 'Marcelo', 'Chris', 'Eileen', 'Pamela', 'Terence'}
    assert set(reach['Jenny']) == {'Paul', 'Jenny', 'Marcelo', 'Chris', 'Eileen', 'Pamela', 'Terence'}
    assert set(reach['Marcelo']) == {'Paul', 'Jenny', 'Marcelo', 'Chris', 'Eileen', 'Pamela', 'Terence'}
    assert set(reach['Eileen']) == {'Paul', 'Jenny', 'Marcelo', 'Chris', 'Eileen', 'Pamela', 'Terence'}
    assert set(reach['Pamela']) == {'Paul', 'Jenny', 'Marcelo', 'Chris', 'Eileen', 'Pamela', 'Terence'}
    assert set(reach['Terence']) == {'Paul', 'Jenny', 'Marcelo', 'Chris', 'Eileen', 'Pamela', 'Terence'}

@@ -50,20 +50,16 @@
  gr = %5C%0A
-    
 %22%22%22a: b,
@@ -65,20 +65,16 @@
 , c%0A
-    
 b: c, d%0A
     
@@ -73,68 +73,21 @@
 , d%0A
-    
 c: b%0A
-    
 d: c%0A
-    %22%22%22%0A    print %22Test #1:%22%0A    print gr%0A
+%22%22%22
 %0A   
@@ -739,20 +739,16 @@
  gr = %5C%0A
-    
 %22%22%22Paul:
@@ -754,20 +754,16 @@
 : Jenny%0A
-    
 Jenny: M
@@ -769,20 +769,16 @@
 Marcelo%0A
-    
 Marcelo:
@@ -800,20 +800,16 @@
  Pamela%0A
-    
 Chris: T
@@ -815,20 +815,16 @@
 Terence%0A
-    
 Eileen: 
@@ -828,20 +828,16 @@
 n: Paul%0A
-    
 Pamela: 
@@ -841,20 +841,16 @@
 a: Paul%0A
-    
 Terence:
@@ -859,51 +859,11 @@
 aul%0A
-%0A    %22%22%22%0A%0A    print %22Test #2:%22%0A    print gr
+%22%22%22
 %0A%0A  
@@ -1043,38 +1043,24 @@
 des(al, n)%0A%0A
-    #print al%0A
     assert s
@@ -1322,30 +1322,16 @@
 '%7D%0A    %0A
-    #print am%0A
     asse
@@ -1370,36 +1370,18 @@
  0%5D,%22+%5C%0A
-                    
+%09%09
       %22 
@@ -1406,36 +1406,18 @@
  0%5D,%22+%5C%0A
-                    
+%09%09
       %22 
@@ -1442,36 +1442,18 @@
  0%5D,%22+%5C%0A
-                    
+%09%09
       %22 
@@ -1478,36 +1478,18 @@
  1%5D,%22+%5C%0A
-                    
+%09%09
       %22 
@@ -1514,36 +1514,18 @@
  0%5D,%22+%5C%0A
-                    
+%09%09
       %22 
@@ -1554,34 +1554,16 @@
 %22+%5C%0A
-                   
+%09%09
       
- 
 %22 %5B1
@@ -1585,33 +1585,16 @@
 , 0%5D%5D%22%0A%0A
-    #print reach%0A
     # us

tweak new tests