def test_map(): start = Room("Start", "You can go west and down a hole.") west = Room("Trees", "There are trees here, you can go east.") down = Room("Dungeon", "It's dark down here, you can go up.") start.add_paths({'west': west, 'down': down}) west.add_paths({'east': start}) down.add_paths({'up': start}) assert_equal(start.go('west'), west) assert_equal(start.go('west').go('east'), start) assert_equal(start.go('down').go('up'), start)
def test_room_paths(): # Creates 3 instances of Room, no paths center = Room("Center", "Test room in the center.") north = Room("North", "Test room in the north.") south = Room("South", "Test room in the south.") # Add paths to the center room (K/V in paths) center.add_paths({'north':north,'south':south}) # Tests these links assert_equal(center.go('north'),north) assert_equal(center.go('south'),south)
def test_map(): start = Room("Start", "Вы можете идти на запад и провалиться в яму.") west = Room("Trees", "Здесь есть деревья и вы можете отправиться на восток.") down = Room("Dungeon", "Здесь темно и вы можете подняться вверх.") start.add_paths({'west': west, 'down': down}) west.add_paths({'east': start}) down.add_paths({'up': start}) assert_equal(start.go('west'), west) assert_equal(start.go('west').go('east'), start) assert_equal(start.go('down').go('up'), start)
def test_room_paths(): # 调用类创建实例,三个参数初始化实例内容 center = Room("Center", "Test room in the center.") north = Room("North", "Test room in the north.") south = Room("South", "Test room in the south.") # From center get the add_paths attributr, and set it 字典 center.add_paths({'north': north, 'south': south}) assert_equal( center.go('north'), north ) # 断言判断两个值,值一:center.go('north')为None;值二:north为<__main__.Room object at 0x02F79950> assert_equal(center.go('south'), south)
def test_room_paths():#测试对room类的add_paths和go操作是否正确 center = Room("Center","Test room in the center.") north = Room("North","Test room in the north.") south = Room("South","Test room in the south.") #创建三个房间 center.add_paths({'north':north,'south':south}) #将north和south房间加入到paths中,一个字符对应一种实例 assert_equal(center.go('north'),north) #检测center实例执行go('north')后,会不会返回north实例 assert_equal(center.go('south'),south)
def test_map(): print "test_map" start = Room("Start", "") west = Room("Trees", "") down = Room("Dungeon", "") start.add_paths({'west': west, 'down': down}) west.add_paths({'east': start}) down.add_paths({'up': start}) assert_equal(start.go('west'), west) assert_equal(start.go('west').go('east'), start) assert_equal(start.go('down').go('up'), start)
def test_map(): start = Room("start", "You can go west and down a hole") west = Room("west", "There are trees and you can go east.") down = Room("dungeon", "It's dark down here, you can go up") start.add_paths({"west": west, "down": down}) west.add_paths({'east': start}) down.add_paths({'up': start}) assert_equal(start.go('west'), west) assert_equal(start.go('down').go('up'), start) assert_equal(start.go('west').go('east'), start)
def test_room_paths(): center = Room("Center", "Test room in the center.") north = Room("North", "Test room in the north.") south = Room("South", "Test room in the south.") center.add_paths({'north': north, 'south': south}) assert_equal(center.go('north'), north) assert_equal(center.go('south'), south)
def test_map(): start = Room("Start", "You can go west and down a hole.") west = Room("Trees", "There are trees here, you can go east.") down = Room("Dungeon", "It's dark down here, you can go up.") # These are all instances of the Room class and each one with have a different dict start.add_paths({'west': west, 'down': down}) west.add_paths({'east': start}) down.add_paths({'up': start}) assert_equal(start.go('west'), west) assert_equal(start.go('west').go('east'), start) assert_equal(start.go('down').go('up'), start)
def test_map(): start = Room("Start", "You can go west and down a hole.") west = Room("Trees", "There are trees here, you can go east.") down = Room("Dungeon", "It's dark down here, yo can go up.") start.add_paths({'west': west, 'down': down}) west.add_paths({'east': start}) down.add_paths({'up': start}) assert_equal(start.go('west'), west) assert_equal(start.go('west').go('east'), start) assert_equal(start.go('down').go('up'), start) print("-" * 30) print('start paths 里面有:%r' % start.paths.keys()) print('west paths 里面有:%r' % west.paths.keys()) print('down paths 里面有:%r' % down.paths.keys()) print("-" * 30) east = west.paths.get('east') # 其实没有实际声明过这个Room()类的实例east,east就是start。 print(east) print(start) print("-" * 30) print('east paths 的Key值:%r' % west.paths.get('east').name) print('east paths 里面有:%r' % west.paths.get('east').paths.keys()) print("-" * 30) def values_west(): # 创建一个生成器 for value in west.paths.keys(): yield west.paths.get(value).name yield west.paths.get(value).paths.keys() for i in values_west(): # 遍历这个生成器 print i print("-" * 30) def values_start(): # 创建一个生成器 for value in start.paths.keys(): yield start.paths.get(value).name yield start.paths.get(value).paths.keys() for i in values_start(): # 遍历这个生成器 print i
def test_hallway(): k_0 = Room("k_0", "0th room") k_1 = Room("k_1", "1st room") k_2 = Room("k_2", "2nd room") k_3 = Room("k_3", "3rd room") k_4 = Room("k_4", "4th room") # fwd, bk k_0.add_paths({'fwd': k_1}) k_1.add_paths({'bk': k_0, 'fwd': k_2}) k_2.add_paths({'bk': k_1, 'fwd': k_3}) k_3.add_paths({'bk': k_2, 'fwd': k_4}) k_4.add_paths({'bk': k_3}) assert_equal(k_0.go('fwd').go('fwd').go('fwd').go('fwd'), k_4)
def test_weapon(): weapon1 = Room('fight_soldiers', 'you have to fight the soldiers here.') weapon1.add_weapon(["knife", "gun", "sword"]) assert_equal(weapon1.acquire_weapon(0), "KNIFE") assert_equal(weapon1.acquire_weapon(1), "gun") assert_equal(weapon1.acquire_weapon(2), "sword")
def test_map(): start = Room("Start", "You are in a hall you can go through a north door") north = Room("Kitchen", "You mum's kitchen nice! you can go West") west = Room("Dungeon", "It dark here almost like a dungeon you can go South" ) south = Room("GoldRoom", "Oh yeah found my neXt box let's play a game") start.add_paths({'north': north, 'south': start}) north.add_paths({'west': west, 'east': north}) west.add_paths({'south': south, 'east': west}) assert_equal(start.go('north'), north) assert_equal(start.go('south'), start) # do not understand this principle assert_equal(north.go('west'), west) assert_equal(north.go('east'), north) assert_equal(west.go('south'), south)
def test_room(): gold = Room( 'GoldRoom', '''This room has gold in it you can grab. There's a door to the north''' ) nt.assert_equal(gold.name, 'GoldRoom') nt.assert_equal(gold.paths, {})
def test_room(): gold = Room( "GoldRoom", ''' This room has gold in it to grab...there's a door to the north! ''') assert_equal(gold.name, 'GoldRoom') assert_equal(gold.paths, {})
def test_map(): start = Room("Stert", "You can go west, north, or down a hole.") west = Room("Trees", "There are trees here, you can go east.") north = Room("Mountain", "There is a huge mountain here, you can go south.") down = Room("Dungeon", "It's dark down here, you can go up.") start.add_paths({'west': west, 'north': north, 'down': down}) west.add_paths({'east': start}) north.add_paths({'south': start}) down.add_paths({'up': start}) assert_equal(start.go('west'), west) assert_equal(start.go('west').go('east'), start) assert_equal(start.go('north').go('south'), start) assert_equal(start.go('down').go('up'), start)
def test_room(): # Create an instance of Room(name, description, empty paths) gold = Room("GoldRoom", """This room has gold in it you can grab. There's a door to the north.""") assert_equal(gold.name, "GoldRoom") assert_equal(gold.paths, {})
def test_map(): # Creates 3 instances of Room, no paths start = Room("Start", "You can go west and down a hole.") west = Room("Trees","There are trees here, you can go east.") down = Room("Dungeon", "It's dark down here, you can go up.") # Add paths to all rooms start.add_paths({"west": west, "down": down}) west.add_paths({"east": start}) down.add_paths({'up' : start}) # Tests these links, and their chaining assert_equal(start.go("west"), west) assert_equal(start.go("west").go('east'), start) assert_equal(start.go("down").go("up"), start)
def test_room(): gold = Room("GoldRoom", """This room has gold in it you can grab. There's a door to the north.""") assert_equal(gold.name, "GoldRoom") assert_equal(gold.paths, {}) def test_room_paths(): center = Room("Center", "Test room in the center.") north = Room("North", "Test room in the north.") south = Room("South", "Test room in the south.") center.add_paths({'north': north, 'south': south}) assert_equal(center.go('north'), north) assert_equal(center.go('south'), south) def test_map(): start = Room("Start", "You can go west and down a hole.") west = Room("Trees", "There are trees here, you can go east.") down = Room("Dungeon", "It's dark down here, you can go up.") start.add_paths({'west': west, 'down': down}) west.add_paths({'east': start}) down.add_paths({'up': start}) assert_equal(start.go('west'), west) assert_equal(start.go('west').go('east'), start) assert_equal(start.go('down').go('up'), start)
def test_room(): gold = Room( "GoldRoom", """This room has gold in it it you can grab. There's a door to the north.""" ) assert_equal(gold.name, "GoldRoom") assert_equal(gold.paths, {})
def test_room(): gold = Room( "GoldRoom", """W tym pokoju jest złoto, które możesz zabrać. Na północy są drzwi.""") assert_equal(gold.name, "GoldRoom") assert_equal(gold.paths, {})
def test_room(): gold = Room("goldroom", """ this room has gold in it you can grab as much u like, there is door to the north. """) assert_equal(gold.name, "goldroom") assert_equal(gold.path,{})
def test_room(): """docstring for setup""" gold = Room( "GoldRoom", """This room has gold in it you can grab. There`s a door to the north.""") assert_equal(gold.name, "GoldRoom") assert_equal(gold.paths, {})
def test_room(): gold = Room( "GoldRoom", """This room has gold in it you can grab. There's a door to the north.""") #这里的assert_equal函数是测试的关键,可以看出它也使用了断言机制 #用以判断中间变量或结果是否与想象的一致 assert_equal(gold.name, "GoldRoom") assert_equal(gold.paths, {})
def test_room(): gold = Room( "GoldRoom", """This room has gold in it you can grab. There's a door to the north.""") # The first tests ensures that the name of the instance of the class is GoldRoom (pretty silly as # That is obvious by just reading the code. The next one checks that paths is empty assert_equal(gold.name, 'GoldRoom') assert_equal(gold.paths, {})
def test_room(): gold = Room("GoldRoom", """This room has gold in it you can grab. There's a door to the north.""") assert_equal(gold.name, "GoldRoom") assert_equal(gold.paths, {}) descr = gold.look() assert_equal(descr.split(' ')[1], "room") assert_equal(descr.split(' ')[3], "gold")
def test_room(): gold = Room("GoldRoom", """ This room has gold in it you can grab. There's a door to the north """) # function comes from nosetools assert_equal(gold.name, "GoldRoom") assert_equal(gold.paths, {})
def test_room(): gold = Room( "GoldRoom", """This room has gold in it you can grab.There's a door to the north.""") assert_equal( gold.name, "GoldRoom" ) #assert_equal(a,b),if a is equal to b,return normal,else return abnormal assert_equal(gold.paths, {})
def test_room(): gold = Room("GoldRoom", """This room has gold in it you can grab. There's a door to the north.""") # assert_equal 保证自己设置的变量以及自己在Room里设置的路径与你的期望相符 # 如果得到错误的结果, nosetests将会打印一条出错的信息 assert_equal(gold.name,"GoldRoom") assert_equal(gold.paths,{})
def test_room_paths(): center = Room("Center", "Test room in the center.") north = Room("North", "Test room in the north.") south = Room("South", "Test room in the south.") center.add_paths({'north': north, 'south': south}) assert_equal(center.go('north'), north) assert_equal(center.go('south'), south) def test_map(): start = Room("Start", "You can go west and down a hole.") west = Room("Trees", "There are trees here, you can go east." down = Room("Dungeon", "It's dark down here, you can go up." start.add_paths({'west': west, 'down': down}) west.add_paths({'east': start}) down.add_paths({'up': start}) assert_equal(start.go('west'), west) assert_equal(start.go('west').go('east'), start) assert_equal(start.go('down').go('up'), start)