<s> import unittest <EOL> from pelita . datamodel import maze_components <EOL> from pelita . layout import * <EOL> class TestLayoutModule ( unittest . TestCase ) : <EOL> def test_load_layout ( self ) : <EOL> layout_name = "<STR_LIT>" <EOL> layout_file = "<STR_LIT>" <EOL> self . assertRaises ( ValueError , load_layout , <EOL> layout_name = layout_name , <EOL> layout_file = layout_file ) <EOL> self . assertRaises ( ValueError , load_layout , layout_name = "<STR_LIT>" ) <EOL> self . assertRaises ( IOError , load_layout , layout_file = "<STR_LIT>" ) <EOL> self . assertEqual ( "<STR_LIT>" , load_layout ( layout_name = layout_name ) [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( "<STR_LIT>" , load_layout ( layout_file = layout_file ) [ <NUM_LIT:0> ] ) <EOL> def test_get_available_layouts ( self ) : <EOL> available = get_available_layouts ( ) <EOL> self . assertEqual ( <NUM_LIT> , len ( available ) ) <EOL> available = get_available_layouts ( filter = '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT:100> , len ( available ) ) <EOL> def test_get_layout_by_name ( self ) : <EOL> with open ( '<STR_LIT>' , '<STR_LIT>' ) as file : <EOL> target_layout = file . read ( ) <EOL> loaded = get_layout_by_name ( '<STR_LIT>' ) <EOL> self . assertEqual ( target_layout , loaded ) <EOL> def test_get_random_layout ( self ) : <EOL> available = get_available_layouts ( ) <EOL> random1 = get_random_layout ( ) <EOL> random2 = get_random_layout ( ) <EOL> self . assertNotEqual ( random1 , random2 , <EOL> '<STR_LIT>' ) <EOL> def test_get_random_layout_returns_correct_layout ( self ) : <EOL> name , layout = get_random_layout ( ) <EOL> layout2 = get_layout_by_name ( name ) <EOL> self . assertEqual ( layout , layout2 ) <EOL> class TestLayoutChecks ( unittest . TestCase ) : <EOL> layout_chars = maze_components <EOL> def test_strip_layout ( self ) : <EOL> test_layout = ( <EOL> """<STR_LIT>""" ) <EOL> stripped = [ c for c in Layout . strip_layout ( test_layout ) ] <EOL> target = [ '<STR_LIT:#>' , '<STR_LIT:#>' , '<STR_LIT:#>' , '<STR_LIT:#>' , '<STR_LIT:#>' , '<STR_LIT:#>' , '<STR_LIT:#>' , '<STR_LIT:\n>' , <EOL> '<STR_LIT:#>' , '<STR_LIT:c>' , '<STR_LIT:U+0020>' , '<STR_LIT:U+0020>' , '<STR_LIT:U+0020>' , '<STR_LIT:U+0020>' , '<STR_LIT:#>' , '<STR_LIT:\n>' , <EOL> '<STR_LIT:#>' , '<STR_LIT:U+0020>' , '<STR_LIT:U+0020>' , '<STR_LIT:.>' , '<STR_LIT:U+0020>' , '<STR_LIT:U+0020>' , '<STR_LIT:#>' , '<STR_LIT:\n>' , <EOL> '<STR_LIT:#>' , '<STR_LIT:U+0020>' , '<STR_LIT:U+0020>' , '<STR_LIT:U+0020>' , '<STR_LIT:U+0020>' , '<STR_LIT:o>' , '<STR_LIT:#>' , '<STR_LIT:\n>' , <EOL> '<STR_LIT:#>' , '<STR_LIT:#>' , '<STR_LIT:#>' , '<STR_LIT:#>' , '<STR_LIT:#>' , '<STR_LIT:#>' , '<STR_LIT:#>' ] <EOL> self . assertEqual ( stripped , target ) <EOL> def test_illegal_character ( self ) : <EOL> illegal_layout = ( <EOL> """<STR_LIT>""" ) <EOL> self . assertRaises ( LayoutEncodingException , Layout . check_layout , <EOL> Layout . strip_layout ( illegal_layout ) , <EOL> TestLayoutChecks . layout_chars , <NUM_LIT:0> ) <EOL> def test_not_enough_bots ( self ) : <EOL> not_enough_bots = ( <EOL> """<STR_LIT>""" ) <EOL> self . assertRaises ( LayoutEncodingException , Layout . check_layout , <EOL> Layout . strip_layout ( not_enough_bots ) , <EOL> TestLayoutChecks . layout_chars , <NUM_LIT:5> ) <EOL> def test_too_many_bots ( self ) : <EOL> too_many_bots = ( <EOL> """<STR_LIT>""" ) <EOL> self . assertRaises ( LayoutEncodingException , Layout . check_layout , <EOL> Layout . strip_layout ( too_many_bots ) , <EOL> TestLayoutChecks . layout_chars , <NUM_LIT:3> ) <EOL> def test_wrong_shape ( self ) : <EOL> wrong_shape = ( <EOL> """<STR_LIT>""" ) <EOL> self . assertRaises ( LayoutEncodingException , Layout . check_layout , <EOL> Layout . strip_layout ( wrong_shape ) , <EOL> TestLayoutChecks . layout_chars , <NUM_LIT:0> ) <EOL> def test_layout_shape ( self ) : <EOL> small_shape = ( <EOL> """<STR_LIT>""" ) <EOL> self . assertEqual ( Layout . layout_shape ( Layout . strip_layout ( small_shape ) ) , ( <NUM_LIT:3> , <NUM_LIT:3> ) ) <EOL> large_shape = ( <EOL> """<STR_LIT>""" ) <EOL> self . assertEqual ( Layout . layout_shape ( Layout . strip_layout ( large_shape ) ) , ( <NUM_LIT:7> , <NUM_LIT:5> ) ) <EOL> def test_wrong_bot_order ( self ) : <EOL> unordered = ( <EOL> """<STR_LIT>""" ) <EOL> l = Layout ( unordered , <EOL> TestLayoutChecks . layout_chars , <NUM_LIT:4> ) <EOL> def test_str ( self ) : <EOL> simple_layout = ( <EOL> """<STR_LIT>""" ) <EOL> layout = Layout ( simple_layout , TestLayoutChecks . layout_chars , <NUM_LIT:0> ) <EOL> target = '<STR_LIT>' + '<STR_LIT>' + '<STR_LIT>' <EOL> self . assertEqual ( target , str ( layout ) ) <EOL> def test_eq ( self ) : <EOL> eq_test = ( <EOL> """<STR_LIT>""" ) <EOL> layout = Layout ( eq_test , TestLayoutChecks . layout_chars , <NUM_LIT:4> ) <EOL> layout2 = Layout ( eq_test , TestLayoutChecks . layout_chars , <NUM_LIT:4> ) <EOL> self . assertEqual ( layout , layout2 ) <EOL> neq_test = ( <EOL> """<STR_LIT>""" ) <EOL> layout3 = Layout ( neq_test , TestLayoutChecks . layout_chars , <NUM_LIT:2> ) <EOL> self . assertNotEqual ( layout , layout3 ) <EOL> def test_repr ( self ) : <EOL> repr_test = ( <EOL> """<STR_LIT>""" ) <EOL> layout = Layout ( repr_test , TestLayoutChecks . layout_chars , <NUM_LIT:4> ) <EOL> layout2 = eval ( repr ( layout ) ) <EOL> self . assertEqual ( layout , layout2 ) <EOL> def test_as_mesh ( self ) : <EOL> simple_layout = ( <EOL> """<STR_LIT>""" ) <EOL> layout = Layout ( simple_layout , TestLayoutChecks . layout_chars , <NUM_LIT:0> ) <EOL> mesh = layout . as_mesh ( ) <EOL> target = Mesh ( <NUM_LIT:4> , <NUM_LIT:3> , data = list ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( target , mesh ) <EOL> def test_mesh_shape ( self ) : <EOL> simple_layout = ( <EOL> """<STR_LIT>""" ) <EOL> layout = Layout ( simple_layout , TestLayoutChecks . layout_chars , <NUM_LIT:0> ) <EOL> mesh = layout . as_mesh ( ) <EOL> self . assertEqual ( mesh . shape , ( <NUM_LIT:4> , <NUM_LIT:3> ) ) <EOL> def test_empty_lines ( self ) : <EOL> simple_layout_1 = ( <EOL> """<STR_LIT>""" ) <EOL> simple_layout_2 = ( <EOL> """<STR_LIT>""" ) <EOL> self . assertEqual ( Layout ( simple_layout_1 , TestLayoutChecks . layout_chars , <NUM_LIT:0> ) , <EOL> Layout ( simple_layout_2 , TestLayoutChecks . layout_chars , <NUM_LIT:0> ) ) <EOL> def test_from_file ( self ) : <EOL> test_l = ( <EOL> """<STR_LIT>""" ) <EOL> layout = Layout . from_file ( "<STR_LIT>" , TestLayoutChecks . layout_chars , <NUM_LIT:2> ) <EOL> self . assertEqual ( layout , Layout ( test_l , TestLayoutChecks . layout_chars , <NUM_LIT:2> ) ) </s>
