def test_red(): interval = randint(1, 1000) value = interval color = calculate_color(value, interval) assert color == "#ff0000"
def get_mutual_friends(): user_id = int(request.args.get("userId")) friends, mutual_ids = mutual_friends.get_mutual_friends(user_id) graph = UsersGraph(friends, mutual_ids) connections_counts = [ len([ connection for connection in graph.connections if user.id in connection ]) for user in friends ] interval_start, interval_end = min(connections_counts), max( connections_counts) interval_length = interval_end - interval_start for user, connections_count in zip(graph.users, connections_counts): user.color = temperature_map.calculate_color( connections_count - interval_start, interval_length) response = Response(Status.OK, graph.to_json()) return jsonify(response)
def test_blue(): value = randint(1, 1000) interval = value * 4 color = calculate_color(value, interval) assert color == "#00ffff"
def test_green(): value = randint(1, 1000) interval = value * 2 color = calculate_color(value, interval) assert color == "#00ff00"
def test_yellow(): interval = randint(1, 1000) * 4 value = interval * 3 / 4 color = calculate_color(value, interval) assert color == "#ffff00"
def test_empty_interval(): value = randint(1, 1000) color = calculate_color(value, 0) assert color == "#ff0000"
def test_dark_blue(): interval = randint(1, 1000) color = calculate_color(0, interval) assert color == "#0000ff"