|
| 1 | +#define CATCH_CONFIG_MAIN |
| 2 | +#include <catch2/catch_all.hpp> |
| 3 | +#include <flucoma/algorithms/public/NMFCross.hpp> |
| 4 | +#include <flucoma/data/FluidTensor.hpp> |
| 5 | +#include <algorithm> |
| 6 | +#include <iostream> |
| 7 | +#include <vector> |
| 8 | + |
| 9 | +TEST_CASE("NMFCross is repeatable with user-supplied random seed") |
| 10 | +{ |
| 11 | + |
| 12 | + using fluid::algorithm::NMFCross; |
| 13 | + using Tensor = fluid::FluidTensor<double, 2>; |
| 14 | + NMFCross algo(3); |
| 15 | + |
| 16 | + Tensor targetMag{{0.5, 0.4}, {0.1, 1.1}, {0.7, 0.8}, |
| 17 | + {0.3, 0.0}, {1.0, 0.9}, {0.2, 0.6}}; |
| 18 | + Tensor sourceMag{{0.0, 0.4}, {0.6, 0.7}, {0.8, 0.1}, |
| 19 | + {1.0, 0.5}, {1.1, 0.2}, {0.9, 0.3}}; |
| 20 | + |
| 21 | + std::vector Hs(3, Tensor(6, 6)); |
| 22 | + |
| 23 | + algo.process(targetMag, Hs[0], sourceMag, 3, 2, 7, 42); |
| 24 | + algo.process(targetMag, Hs[1], sourceMag, 3, 2, 7, 42); |
| 25 | + algo.process(targetMag, Hs[2], sourceMag, 3, 2, 7, 5063); |
| 26 | + |
| 27 | + using Catch::Matchers::RangeEquals; |
| 28 | + |
| 29 | + SECTION("Calls with the same seed have the same output") |
| 30 | + { |
| 31 | + REQUIRE_THAT(Hs[1], RangeEquals(Hs[0])); |
| 32 | + } |
| 33 | + SECTION("Calls with different seeds have different outputs") |
| 34 | + { |
| 35 | + REQUIRE_THAT(Hs[1], !RangeEquals(Hs[2])); |
| 36 | + } |
| 37 | +} |
0 commit comments