def test_do_group_invalid_scheme(): """Check we error out and not segfault if the name is unknown.""" with pytest.raises(ValueError) as ve: do_group([1, 2, 3], [1, 1, 1], 'foo') assert str(ve.value) == 'unsupported group function: foo'
def test_do_group_check_lengths(): """Check we error out if lengths do not match.""" with pytest.raises(TypeError) as te: do_group([1, 2, 3], [1, 1], 'sum') assert str( te.value) == 'input array sizes do not match, data: 3 vs group: 2'
def test_do_group_nothing_group(): """Special case: no grouping The _make_groups uses the first element in the input as the starting term, adding 1 to each element. """ ans = do_group([6, 4, 2, 1, -1, 3], [1, 1, 1, 1, 1, 1], "_make_groups") assert ans == pytest.approx([6, 7, 8, 9, 10, 11])
def test_do_group_single_group(func, expected): """There's only one group.""" ans = do_group([6, 4, 2, 1, -1, 3], [1, -1, -1, -1, -1, -1], func) assert ans == pytest.approx([expected])
def test_do_group_nothing_sumsq(): """Special case: no grouping""" ans = do_group([6, 4, 2, 1, -1, 3], [1, 1, 1, 1, 1, 1], "_sum_sq") assert ans == pytest.approx([6, 4, 2, 1, 1, 3])
def test_do_group_nothing_func(func): """Special case: no grouping""" ans = do_group([6, 4, 2, 1, -1, 3], [1, 1, 1, 1, 1, 1], func) assert ans == pytest.approx([6, 4, 2, 1, -1, 3])
def test_do_group_check_func(func, expected): """Test grouping functions on simple input.""" ans = do_group([1, 2, 3, 4, 5, 6], [1, -1, 1, -1, -1, 1], func) assert ans == pytest.approx(expected)