<s> import logging <EOL> import sys <EOL> import unittest <EOL> from apgl . io . CsvGraphReader import CsvGraphReader <EOL> from apgl . util . PathDefaults import PathDefaults <EOL> import numpy <EOL> class CsvGraphReaderTest ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> logging . basicConfig ( stream = sys . stdout , level = logging . INFO ) <EOL> def testReadFromFile ( self ) : <EOL> vertex1Indices = [ <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] <EOL> vertex2Indices = [ <NUM_LIT:1> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> ] <EOL> def genderConv ( x ) : <EOL> genderDict = { '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : <NUM_LIT:1> } <EOL> return genderDict [ x ] <EOL> def orientConv ( x ) : <EOL> orientDict = { '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : <NUM_LIT:1> } <EOL> return orientDict [ x ] <EOL> converters = { <NUM_LIT:2> : genderConv , <NUM_LIT:6> : genderConv , <NUM_LIT:3> : orientConv , <NUM_LIT:7> : orientConv } <EOL> csvGraphReader = CsvGraphReader ( vertex1Indices , vertex2Indices , converters ) <EOL> dir = PathDefaults . getDataDir ( ) <EOL> fileName = dir + "<STR_LIT>" <EOL> graph = csvGraphReader . readFromFile ( fileName ) <EOL> self . assertTrue ( ( graph . getVertex ( <NUM_LIT:0> ) == numpy . array ( [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:1> ] ) ) . all ( ) ) <EOL> self . assertTrue ( ( graph . getVertex ( <NUM_LIT:1> ) == numpy . array ( [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:1> ] ) ) . all ( ) ) <EOL> self . assertTrue ( ( graph . getVertex ( <NUM_LIT:2> ) == numpy . array ( [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:2> ] ) ) . all ( ) ) <EOL> self . assertTrue ( ( graph . getVertex ( <NUM_LIT:3> ) == numpy . array ( [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:1> ] ) ) . all ( ) ) <EOL> self . assertTrue ( ( graph . getVertex ( <NUM_LIT:4> ) == numpy . array ( [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT> ] ) ) . all ( ) ) <EOL> self . assertTrue ( graph . getEdge ( <NUM_LIT:0> , <NUM_LIT:1> ) == <NUM_LIT:1> ) <EOL> self . assertTrue ( graph . getEdge ( <NUM_LIT:2> , <NUM_LIT:3> ) == <NUM_LIT:1> ) <EOL> self . assertTrue ( graph . getEdge ( <NUM_LIT:4> , <NUM_LIT:6> ) == <NUM_LIT:1> ) <EOL> self . assertTrue ( graph . getEdge ( <NUM_LIT:6> , <NUM_LIT:7> ) == <NUM_LIT:1> ) <EOL> self . assertTrue ( graph . getEdge ( <NUM_LIT:5> , <NUM_LIT:8> ) == <NUM_LIT:1> ) <EOL> self . assertEquals ( graph . getNumEdges ( ) , <NUM_LIT:5> ) <EOL> self . assertTrue ( graph . isUndirected ( ) ) <EOL> csvGraphReader = CsvGraphReader ( vertex1Indices , vertex2Indices , converters , undirected = False ) <EOL> graph = csvGraphReader . readFromFile ( fileName ) <EOL> self . assertTrue ( graph . getEdge ( <NUM_LIT:1> , <NUM_LIT:0> ) == None ) <EOL> self . assertTrue ( graph . getEdge ( <NUM_LIT:3> , <NUM_LIT:2> ) == None ) <EOL> self . assertTrue ( graph . getEdge ( <NUM_LIT:6> , <NUM_LIT:4> ) == None ) <EOL> self . assertTrue ( graph . getEdge ( <NUM_LIT:7> , <NUM_LIT:6> ) == None ) <EOL> self . assertTrue ( graph . getEdge ( <NUM_LIT:8> , <NUM_LIT:5> ) == None ) <EOL> self . assertEquals ( graph . getNumEdges ( ) , <NUM_LIT:5> ) <EOL> self . assertFalse ( graph . isUndirected ( ) ) <EOL> vertex1Indices = [ <NUM_LIT:0> ] <EOL> vertex2Indices = [ <NUM_LIT:1> ] <EOL> fileName = dir + "<STR_LIT>" <EOL> csvGraphReader = CsvGraphReader ( vertex1Indices , vertex2Indices , { } ) <EOL> graph = csvGraphReader . readFromFile ( fileName ) <EOL> self . assertTrue ( graph . getEdge ( <NUM_LIT:0> , <NUM_LIT:1> ) == <NUM_LIT:1> ) <EOL> self . assertTrue ( graph . getEdge ( <NUM_LIT:2> , <NUM_LIT:3> ) == <NUM_LIT:1> ) <EOL> self . assertTrue ( graph . getEdge ( <NUM_LIT:4> , <NUM_LIT:6> ) == <NUM_LIT:1> ) <EOL> self . assertTrue ( graph . getEdge ( <NUM_LIT:6> , <NUM_LIT:7> ) == <NUM_LIT:1> ) <EOL> self . assertTrue ( graph . getEdge ( <NUM_LIT:5> , <NUM_LIT:8> ) == <NUM_LIT:1> ) <EOL> self . assertEquals ( graph . getNumEdges ( ) , <NUM_LIT:5> ) <EOL> self . assertTrue ( graph . isUndirected ( ) ) <EOL> self . assertEquals ( graph . getVertexList ( ) . getNumFeatures ( ) , <NUM_LIT:0> ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
