File size: 825 Bytes
2a33798
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
def history_to_str(history):
    history_str = ""
    for d in history:
        history_str += f"state: {d['state']}, action: {d['action']}, reward: {d['reward']}\n"
    return history_str

def get_majority_vote(actions):
    return max(set(actions), key=actions.count)

def test_get_majority_vote():
    assert get_majority_vote([1, 1, 1, 2, 2]) == 1
    assert get_majority_vote([1, 1, 2, 2, 2]) == 2
    assert get_majority_vote([1, 1, 2, 2, 3]) == 1
    assert get_majority_vote([1, 2, 3, 4, 5]) == 1
    assert get_majority_vote([1, 2, 3, 4, 5, 1, 1, 1, 1, 1]) == 1
    assert get_majority_vote([1, 2, 3, 4, 5, 1, 1, 1, 1, 2]) == 1
    assert get_majority_vote([1, 2, 3, 4, 5, 1, 1, 1, 2, 2]) == 1
    assert get_majority_vote([1, 2, 3, 4, 5, 1, 1, 2, 2, 2]) == 2

if __name__ == "__main__":
    test_get_majority_vote()