def test_single_type(self): N = 10 test_vector = np.arange(N) for tested_type in ExtremumTypes: extrema = LocalExtrema(test_vector, [tested_type] * N) assert len(extrema) == N for current_type in ExtremumTypes: retrieved = extrema.get_type(current_type) if current_type is tested_type: assert len(retrieved) == N assert np.all(retrieved == test_vector) else: assert len(retrieved) == 0
def test_mixed_types(self): N = 10 test_vector = np.arange(10) test_types = np.ones(N) * ExtremumTypes.MIN test_types[0:10:2] = ExtremumTypes.MAX extrema = LocalExtrema(test_vector, test_types) assert len(extrema) == N retrieved_min = extrema.get_type(ExtremumTypes.MIN) assert np.all(retrieved_min == test_vector[1:10:2]) retrieved_max = extrema.get_type(ExtremumTypes.MAX) assert np.all(retrieved_max == test_vector[0:10:2]) # Should not find any other types for current_type in ExtremumTypes: if (current_type is not ExtremumTypes.MIN and current_type is not ExtremumTypes.MAX): assert len(extrema.get_type(current_type)) == 0
def test_empty(self): extrema = LocalExtrema([], []) assert len(extrema) == 0 assert len(extrema.get_type(ExtremumTypes.MIN)) == 0 # FIXME
def test_inconsistent_inputs(self): with pytest.raises(IndexError): extrema = LocalExtrema([], [1]) with pytest.raises(IndexError): extrema = LocalExtrema(np.arange(10), [1])