Пример #1
0
def test_get_term_sum_when_zero_is_not_in_available_terms():
    available_terms = [16, 32]

    assert [] == \
           BaseSensorChannel._get_sum_terms(available_terms,
                                            3)

    # Note that `_get_sum_terms` expects '0' to be in the available_terms,
    # hence for this particular case it will still return a list with '0' in
    # it although that '0' is not part of the available_terms
    assert [0] == \
           BaseSensorChannel._get_sum_terms(available_terms,
                                            0)
Пример #2
0
def test_get_term_sum_with_some_powers_of_2_omitted():
    available_terms = [0, 16, 32]

    assert [32, 16] == \
           BaseSensorChannel._get_sum_terms(available_terms,
                                            16 + 32)

    assert [32] == \
           BaseSensorChannel._get_sum_terms(available_terms,
                                            32)

    assert [0] == \
           BaseSensorChannel._get_sum_terms(available_terms,
                                            0)
Пример #3
0
def test_get_term_sum():
    available_terms = [0, 1, 2, 4, 8, 16, 32]

    assert [32, 8, 2, 1] == \
           BaseSensorChannel._get_sum_terms(available_terms,
                                            1 + 2 + 8 + 32)

    assert [32] == \
           BaseSensorChannel._get_sum_terms(available_terms,
                                            32)

    assert [16, 4, 1] == \
           BaseSensorChannel._get_sum_terms(available_terms,
                                            1 + 4 + 16)

    assert [0] == \
           BaseSensorChannel._get_sum_terms(available_terms,
                                            0)
Пример #4
0
def test_get_term_sum_returns_empty_list():
    available_terms = [0, 16, 32]

    assert [] == \
           BaseSensorChannel._get_sum_terms(available_terms,
                                            15)