Esempio n. 1
0
def test_against_SPRITE(npart, m, sd, m_prec, sd_prec, min_val, max_val,
                        method):
    """
    Validate that pysprite and the original SPRITE library come to the same conclusion.
    """
    s = Sprite(npart, m, sd, m_prec, sd_prec, min_val, max_val)
    answer_pysprite = (s.find_possible_distribution(
        init_method=method)[0] == "Success")
    answer_psprite = (SPRITE(m, m_prec, sd, sd_prec, npart, min_val,
                             max_val)[0] == "solution")
    assert (answer_psprite == answer_pysprite)
Esempio n. 2
0
def test_exclusions(npart, m, sd, m_prec, sd_prec, min_val, max_val,
                    restrictions):
    """
    Validate that pysprite can find distributions with must-exclude restrictions.
    """
    s = Sprite(npart, m, sd, m_prec, sd_prec, min_val, max_val, restrictions)
    values = s.find_possible_distribution()[1]
    dict_values = {
        k: v
        for k, v in zip(*np.unique(values, return_counts=True))
    }
    match = [dict_values.get(k, 0) == v for k, v in restrictions.items()]
    assert all(match)
Esempio n. 3
0
def test_threeitems(npart, m, sd, m_prec, sd_prec, min_val, max_val, n_items,
                    method):
    """
    Validate that pysprite can find a solution for three-items scales.
    """
    s = Sprite(npart,
               m,
               sd,
               m_prec,
               sd_prec,
               min_val,
               max_val,
               n_items=n_items)
    assert (s.find_possible_distribution(init_method=method)[0] == "Success")
Esempio n. 4
0
def test_GRIMfail(npart, m, sd, m_prec, sd_prec, min_val, max_val):
    """
    Validate that pysprite will fail initialization when the parameters are incorrect.
    """
    with pytest.raises(ValueError):
        Sprite(npart, m, sd, m_prec, sd_prec, min_val, max_val)
Esempio n. 5
0
def test_success(npart, m, sd, m_prec, sd_prec, min_val, max_val, method):
    """
    Validate that pysprite can find a solution when a solution exists
    """
    s = Sprite(npart, m, sd, m_prec, sd_prec, min_val, max_val)
    assert (s.find_possible_distribution(init_method=method)[0] == "Success")