Esempio n. 1
0
def test_rescale_max():
    a = np.arange(0, 11)
    # Max & first element has no effect
    assert max(rescale_max(a, to=(0, 5))) == 5
    assert max(rescale_max(a, to=(4, 5))) == 5

    # Expanded & first elements have no effect
    assert max(rescale_max(a, to=(0, 5), _from=(0, 3))) > 5
    assert max(rescale_max(a, to=(2, 5), _from=(2, 3))) > 5

    # branches #
    assert rescale_max(2, _from=(0, 10)) == 0.2
def test_rescale_max():
    a = np.arange(0, 11)
    # Max & first element has no effect
    assert max(rescale_max(a, to=(0, 5))) == 5
    assert max(rescale_max(a, to=(4, 5))) == 5

    # Expanded & first elements have no effect
    assert max(rescale_max(a, to=(0, 5), _from=(0, 3))) > 5
    assert max(rescale_max(a, to=(2, 5), _from=(2, 3))) > 5

    # branches #
    assert rescale_max(2, _from=(0, 10)) == 0.2

    # Maintains the same index
    s = pd.Series([1, 2, 3], index=[3, 2, 1])
    result = rescale_max(s)
    assert s.index.equals(result.index)

    x = [-5, -4, -3, -2, -1, 0]
    result = rescale_max(x)
    assert result == approx([0, 0.2, 0.4, 0.6, 0.8, 1.0])

    result = rescale_max(x, to=(0, 5))
    assert result == approx([0, 1, 2, 3, 4, 5])
Esempio n. 3
0
def test_rescale_max():
    a = np.arange(0, 11)
    # Max & first element has no effect
    assert max(rescale_max(a, to=(0, 5))) == 5
    assert max(rescale_max(a, to=(4, 5))) == 5

    # Expanded & first elements have no effect
    assert max(rescale_max(a, to=(0, 5), _from=(0, 3))) > 5
    assert max(rescale_max(a, to=(2, 5), _from=(2, 3))) > 5

    # branches #
    assert rescale_max(2, _from=(0, 10)) == 0.2

    # Maintains the same index
    s = pd.Series([1, 2, 3], index=[3, 2, 1])
    result = rescale_max(s)
    assert s.index.equals(result.index)