Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mod Matrix Row knows hasDefaultValues; add test #127

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading