def test_empty(): with pytest.raises(Exception): median_of_dict({})
def test_multiple2(): d = {0: 22, 3: 56} assert np.median([i for sl in [[k]*v for k, v in d.items()] for i in sl]) == median_of_dict(d) == 3
def test_multiple5(): d = {0.0: 1, 5.0: 1, 2.0: 1, 34.0: 1} assert np.median([i for sl in [[k]*v for k, v in d.items()] for i in sl]) == median_of_dict(d) == 3.5
def test_single2(): d = {0: 22} assert np.median([i for sl in [[k]*v for k, v in d.items()] for i in sl]) == median_of_dict(d) == 0