Skip to content

Commit

Permalink
Added new test which tests for bad frequency input from the user.
Browse files Browse the repository at this point in the history
  • Loading branch information
berndporr committed Jan 9, 2021
1 parent 8ef23b0 commit 6397a8a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
4 changes: 4 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ add_test(TestChebyshev2 test_chebyshev2)
add_executable (test_rbj rbj.cpp)
target_link_libraries(test_rbj iir_static)
add_test(TestRBJ test_rbj)

add_executable (test_badparam badparam.cpp)
target_link_libraries(test_badparam iir_static)
add_test(TestBadParam test_badparam)
46 changes: 46 additions & 0 deletions test/badparam.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "Iir.h"

#include <stdio.h>

#include "assert_print.h"

int main (int,char**)
{
// dummy filter parameters
const float samplingrate = 1000;
const float bw = 5;

try {
Iir::Butterworth::LowPass<3> f;
f.setup (samplingrate, samplingrate / 2);
assert_print(0,"No exception thrown by LowPass.");
} catch ( const std::invalid_argument& e ) {
fprintf(stderr,"Correct lowpass exception thrown for fc = fs/2: %s\n",e.what());
}

try {
Iir::Butterworth::HighPass<3> f;
f.setup (samplingrate, samplingrate / 2);
assert_print(0,"No exception thrown by HighPass.");
} catch ( const std::invalid_argument& e ) {
fprintf(stderr,"Correct highpass exception thrown for fc = fs/2: %s\n",e.what());
}

try {
Iir::Butterworth::BandStop<3> f;
f.setup (samplingrate, samplingrate / 2, bw);
assert_print(0,"No exception thrown by BandStop.");
} catch ( const std::invalid_argument& e ) {
fprintf(stderr,"Correct bandstop exception thrown for fc = fs/2: %s\n",e.what());
}

try {
Iir::Butterworth::BandPass<3> f;
f.setup (samplingrate, samplingrate / 2, bw);
assert_print(0,"No exception thrown by BandPass.");
} catch ( const std::invalid_argument& e ) {
fprintf(stderr,"Correct bandpass exception thrown for fc = fs/2: %s\n",e.what());
}

return 0;
}

0 comments on commit 6397a8a

Please sign in to comment.