1+ #define CATCH_CONFIG_MAIN
2+ #include < catch2/catch_all.hpp>
3+ #include < flucoma/algorithms/util/RTPGHI.hpp>
4+ #include < flucoma/data/FluidMemory.hpp>
5+ #include < flucoma/data/FluidTensor.hpp>
6+ #include < complex>
7+ #include < vector>
8+
9+ namespace fluid {
10+
11+
12+ TEST_CASE (" RTPGHI is repeatable with manually set random seed" )
13+ {
14+ using Tensor = fluid::FluidTensor<double , 1 >;
15+ using ComplexTensor = fluid::FluidTensor<std::complex <double >, 1 >;
16+ using fluid::algorithm::RTPGHI;
17+
18+ index win = 64 ;
19+ index fft = 64 ;
20+ index hop = 64 ;
21+ index bins = fft / 2 + 1 ;
22+
23+ double mag = 1.0 ;
24+ // to stop algo converging, bypass loop by setting massive tolerence
25+ double tol = 2.0 * mag;
26+
27+ RTPGHI algo (fft, FluidDefaultAllocator ());
28+
29+ Tensor input (bins);
30+ input[index (bins / 2 )] = mag;
31+ std::vector results (3 , ComplexTensor (bins));
32+
33+ // algo has memory, so re-init after each call to test repeatability, and call
34+ // twice to actually generate some action
35+ auto runit = [&](size_t run, index seed) {
36+ algo.init (fft);
37+ algo.processFrame (input, results[run], win, fft, hop, tol, seed,
38+ FluidDefaultAllocator ());
39+ algo.processFrame (input, results[run], win, fft, hop, 2.0 , seed,
40+ FluidDefaultAllocator ());
41+ };
42+
43+ for (size_t run = 0 ; run < results.size (); ++run)
44+ runit (run, run < 2 ? 42 : 8347 );
45+
46+ using Catch::Matchers::RangeEquals;
47+
48+ REQUIRE_THAT (results[0 ], RangeEquals (results[1 ]));
49+ REQUIRE_THAT (results[0 ], !RangeEquals (results[2 ]));
50+ }
51+ } // namespace fluid
0 commit comments