def test_bi_direction_out(): uid1 = ROWS[0][2] # these users are not connected to uid1 uid6 = 'crap' user.enroll(uid6,uid6,uid6,uid6) uid7 = 'crap2' user.enroll(uid7,uid7,uid7,uid7) connect.outta_my_face(uid6,uid7) assert_true(actions.is_outta_my_face(uid6, uid7)) assert_true(actions.is_in_my_face(uid7, uid6)) # inverse test assert_false(actions.is_outta_my_face(uid7, uid6)) assert_false(actions.is_in_my_face(uid6, uid7)) # finally, test to make sure these users aren't connected to uid1 assert_false(actions.is_outta_my_face(uid1, uid6)) assert_false(actions.is_outta_my_face(uid1, uid7)) assert_false(actions.is_in_my_face(uid1, uid6)) assert_false(actions.is_in_my_face(uid1, uid7))
def test_flat_list(): u1 = 'uid1' u2 = 'uid2' u3 = 'uid3' u4 = 'uid4' mr_popular = 'uid5' connect.outta_my_face(u1, u2) connect.outta_my_face(u3, u4) connect.outta_my_face(u2, mr_popular) connect.outta_my_face(u4, mr_popular) users_set1 = actions._all_connections(u1) users_set1_flat = actions._flatten_connections(users_set1) print users_set1_flat users_set2 = actions._all_connections(u3) users_set2_flat = actions._flatten_connections(users_set2) print users_set2_flat # first connection is always the user we started searching at assert_equal(users_set1[0][1].keys(), [(u1,)] ) assert_equal(users_set2[0][1].keys(), [(u3,)] ) # our user_set data should be a list of users, with order assert_equal(users_set1_flat, [(u1,), (u2,), (mr_popular,)] ) assert_equal(users_set2_flat, [(u3,), (u4,), (mr_popular,)] ) intersect = {(mr_popular,)} print actions.face_space(u1, u3) #mr_popular should be connected to everyone assert_equal(actions.face_space(u1, u3), intersect) assert_equal(actions.face_space(u3, u1), intersect) assert_equal(actions.face_space(u2, u4), intersect) assert_equal(actions.face_space(u4, u2), intersect)
def test_second_connection(): """ test connected, not connected users """ # these users are connected to uid1 uid1 = ROWS[0][2] uid2 = ROWS[1][2] uid3 = ROWS[2][2] uid4 = ROWS[3][2] assert_true(actions.is_outta_my_face(uid1, uid1)) connect.outta_my_face(uid1, uid2) assert_true(actions.is_outta_my_face(uid1, uid2)) connect.outta_my_face(uid2, uid3) assert_true(actions.is_outta_my_face(uid2, uid3)) assert_true(actions.is_outta_my_face(uid1, uid3)) connect.outta_my_face(uid3, uid4) assert_true(actions.is_outta_my_face(uid3, uid4)) assert_true(actions.is_outta_my_face(uid2, uid4)) assert_true(actions.is_outta_my_face(uid1, uid4))
def test_direct_connection(): uid1 = ROWS[0][2] uid2 = ROWS[1][2] connect.outta_my_face(uid1, uid2) assert_true(actions.is_outta_my_face(uid1, uid2))
def test_face_path(): u1 = 'uid1' u2 = 'uid2' u3 = 'uid3' u4 = 'uid4' mr_popular = 'uid5' connect.outta_my_face(u1, u2) connect.outta_my_face(u3, u4) connect.outta_my_face(u2, mr_popular) # basic path test assert_equal(actions.find_path(u1, mr_popular), [(u2,), (mr_popular,)]) # if find_path can't find a connection, it should return False assert_false(actions.find_path(mr_popular, u1)) assert_false(actions.find_path(u1, u4)) # test some cycles connect.outta_my_face(mr_popular, u3) connect.outta_my_face(u1, u3) connect.outta_my_face(u4, mr_popular) # test the new path, with cycles, return shortest assert_equal(actions.find_path(u1, mr_popular), [(u3,), (u4,), (mr_popular,)]) # do the same thing, but find the shortest path assert_equal(actions.find_path(u1, mr_popular, find_shortest=True), [(u2,), (mr_popular,)])