Skip to content

Commit

Permalink
Mod Matrix Row knows hasDefaultValues; add test
Browse files Browse the repository at this point in the history
  • Loading branch information
baconpaul committed Aug 16, 2024
1 parent 351196f commit 62fbf82
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
16 changes: 14 additions & 2 deletions include/sst/basic-blocks/mod-matrix/ModMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,21 @@ struct RoutingTable : details::CheckModMatrixConstraints<ModMatrixTraits>
std::optional<typename TR::TargetIdentifier> target{std::nullopt};
std::optional<typename TR::CurveIdentifier> curve{std::nullopt};

float depth{0};
float depth{0.f};

std::optional<typename TR::RoutingExtraPayload> extraPayload;
std::optional<typename TR::RoutingExtraPayload> extraPayload{std::nullopt};

bool hasDefaultValues() const
{
auto res = active;
res = res && (depth == 0.f);
res = res && (!source.has_value());
res = res && (!sourceVia.has_value());
res = res && (!target.has_value());
res = res && (!curve.has_value());
res = res && (!extraPayload.has_value());
return res;
}
};
};

Expand Down
41 changes: 41 additions & 0 deletions tests/mod_matrix_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,47 @@ template <> struct std::hash<Config::TargetIdentifier>
}
};

TEST_CASE("Default Values Check Works", "[mod-matrix]")
{
FixedMatrix<Config> m;
FixedMatrix<Config>::RoutingTable rt;
for (const auto &r : rt.routes)
{
assert(r.hasDefaultValues());
}

auto barS = Config::SourceIdentifier{Config::SourceIdentifier::SI::BAR, 2, 3};
auto fooS = Config::SourceIdentifier{Config::SourceIdentifier::SI::FOO};

auto tg3T = Config::TargetIdentifier{3};
auto tg3PT = Config::TargetIdentifier{3, 'facd'};

float barSVal{1.1}, fooSVal{2.3};
m.bindSourceValue(barS, barSVal);
m.bindSourceValue(fooS, fooSVal);

float t3V{0.2}, t3PV{0.3};
m.bindTargetBaseValue(tg3T, t3V);
m.bindTargetBaseValue(tg3PT, t3PV);

rt.updateRoutingAt(3, barS, tg3T, 0.5);
rt.updateRoutingAt(1, fooS, tg3PT, -0.5);

int idx{0};
for (const auto &r : rt.routes)
{
if (idx == 3 || idx == 1)
{
assert(!r.hasDefaultValues());
}
else
{
assert(r.hasDefaultValues());
}
idx++;
}
}

TEST_CASE("Configure and Bind", "[mod-matrix]")
{
FixedMatrix<Config> m;
Expand Down

0 comments on commit 62fbf82

Please sign in to comment.