def test_proportion_normalization(): # extremes should give the whole set, as well # as if 0 is inserted eq(_normalize_split(0.), [0.0, 0.0, 1.0]) eq(_normalize_split(1.), [0.0, 1.0, 1.0]) eq(_normalize_split(2.), [0.0, 1.0, 1.0]) # negative values should raise ValueError assert_raises(ValueError, _normalize_split, -1) assert_raises(ValueError, _normalize_split, [1., -1]) assert_raises(ValueError, _normalize_split, [1., -1, 0.]) # if everything is zero it will complain assert_raises(ValueError, _normalize_split, [0.]) assert_raises(ValueError, _normalize_split, [0., 0.]) # one-element array should return the whole interval eq(_normalize_split([0.5]), [0.0, 1.0]) eq(_normalize_split([1.]), [0.0, 1.0]) eq(_normalize_split([2.]), [0.0, 1.0]) # simple division should give two pieces for x in [0.3, 0.5, 0.9]: eq(_normalize_split(x), [0., x, 1.0]) # multiple division should split as the sum of the components for x, y in [(0.25, 0.5), (0.1, 0.8), (10., 30.)]: eq(_normalize_split([x, y]), [0., x / (x + y), 1.0]) for x, y, z in [(1., 1., 1.), (0.1, 0.5, 0.7), (10., 30., 40)]: eq(_normalize_split([x, y, z]), [0., x / (x + y + z), (x + y) / (x + y + z), 1.0])
def test_proportion_normalization(): # extremes should give the whole set, as well # as if 0 is inserted eq(_normalize_split(0.), [0.0, 0.0, 1.0]) eq(_normalize_split(1.), [0.0, 1.0, 1.0]) eq(_normalize_split(2.), [0.0, 1.0, 1.0]) # negative values should raise ValueError assert_raises(ValueError, _normalize_split, -1) assert_raises(ValueError, _normalize_split, [1., -1]) assert_raises(ValueError, _normalize_split, [1., -1, 0.]) # if everything is zero it will complain assert_raises(ValueError, _normalize_split, [0.]) assert_raises(ValueError, _normalize_split, [0., 0.]) # one-element array should return the whole interval eq(_normalize_split([0.5]), [0.0, 1.0]) eq(_normalize_split([1.]), [0.0, 1.0]) eq(_normalize_split([2.]), [0.0, 1.0]) # simple division should give two pieces for x in [0.3, 0.5, 0.9]: eq(_normalize_split(x), [0., x, 1.0]) # multiple division should split as the sum of the components for x, y in [(0.25, 0.5), (0.1, 0.8), (10., 30.)]: eq(_normalize_split([x, y]), [0., x / (x + y), 1.0]) for x, y, z in [(1., 1., 1.), (0.1, 0.5, 0.7), (10., 30., 40)]: eq(_normalize_split( [x, y, z]), [0., x / (x + y + z), (x + y) / (x + y + z), 1.0])