Skip to content

Commit 1663834

Browse files
committed
update tests
1 parent 3c67c70 commit 1663834

1 file changed

Lines changed: 132 additions & 0 deletions

File tree

test/source/sparsepc.cpp

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,138 @@ TEST_CASE("Sparsepc all")
287287
CHECK((validatedComponents[2].vector - v).norm() < 1e-6);
288288
}
289289
}
290+
291+
{
292+
using ContiguousFacetsFinder =
293+
Sparsepc::linearmodel::ContiguousFacetsFinder<Scalar>;
294+
constexpr auto nbComponents = 3;
295+
const std::array<Index, nbComponents> choices{6, 2, 2};
296+
std::vector<Component> validatedComponents;
297+
validatedComponents.reserve(nbComponents);
298+
for (Index j = 0; j < nbComponents; ++j)
299+
{
300+
auto candidates =
301+
ContiguousFacetsFinder::computeNextComponentCandidates(
302+
sigma, ContiguousFacetsFinder::ImplementationParam{},
303+
validatedComponents, nullptr);
304+
const auto iCandidate = choices[j];
305+
for (auto &[i, candidate] : candidates)
306+
{
307+
candidate.state = Sparsepc::ComponentState::Unvalidated;
308+
}
309+
candidates.at(iCandidate).state =
310+
Sparsepc::ComponentState::Validated;
311+
validatedComponents.push_back(std::move(candidates.at(iCandidate)));
312+
}
313+
314+
{
315+
CHECK(std::abs(validatedComponents[0].value - 2.88511) < 1e-4);
316+
Vector v(n);
317+
v << 0, 0, 0, 0, 0.165465, 0.398, 0.540816, 0.367875, 0.4003,
318+
0.475567, 0, 0, 0;
319+
CHECK((validatedComponents[0].vector - v).norm() < 1e-6);
320+
}
321+
{
322+
CHECK(std::abs(validatedComponents[1].value - 1.954) < 1e-4);
323+
Vector v(n);
324+
v << 0.707107, 0.707107, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
325+
CHECK((validatedComponents[1].vector - v).norm() < 1e-6);
326+
}
327+
{
328+
CHECK(std::abs(validatedComponents[2].value - 1.882) < 1e-4);
329+
Vector v(n);
330+
v << 0, 0, 0.707107, 0.707107, 0, 0, 0, 0, 0, 0, 0, 0, 0;
331+
CHECK((validatedComponents[2].vector - v).norm() < 1e-6);
332+
}
333+
}
334+
335+
{
336+
using MavIterativeElimination =
337+
Sparsepc::linearmodel::MavIterativeElimination<Scalar>;
338+
constexpr auto nbComponents = 3;
339+
const std::array<Index, nbComponents> choices{6, 2, 2};
340+
std::vector<Component> validatedComponents;
341+
validatedComponents.reserve(nbComponents);
342+
for (Index j = 0; j < nbComponents; ++j)
343+
{
344+
auto candidates =
345+
MavIterativeElimination::computeNextComponentCandidates(
346+
sigma, MavIterativeElimination::ImplementationParam{},
347+
validatedComponents, nullptr);
348+
const auto iCandidate = choices[j];
349+
for (auto &[i, candidate] : candidates)
350+
{
351+
candidate.state = Sparsepc::ComponentState::Unvalidated;
352+
}
353+
candidates.at(iCandidate).state =
354+
Sparsepc::ComponentState::Validated;
355+
validatedComponents.push_back(std::move(candidates.at(iCandidate)));
356+
}
357+
358+
{
359+
CHECK(std::abs(validatedComponents[0].value - 3.77096) < 1e-4);
360+
Vector v(n);
361+
v << 0.444022, 0.453036, 0, 0, 0, 0, 0.378041, 0.341986, 0.403168,
362+
0.418555, 0, 0, 0;
363+
CHECK((validatedComponents[0].vector - v).norm() < 1e-6);
364+
}
365+
{
366+
CHECK(std::abs(validatedComponents[1].value - 1.882) < 1e-4);
367+
Vector v(n);
368+
v << 0, 0, 0.707107, 0.707107, 0, 0, 0, 0, 0, 0, 0, 0, 0;
369+
CHECK((validatedComponents[1].vector - v).norm() < 1e-6);
370+
}
371+
{
372+
CHECK(std::abs(validatedComponents[2].value - 1.364) < 1e-4);
373+
Vector v(n);
374+
v << 0, 0, 0, 0, 0.707107, 0.707107, 0, 0, 0, 0, 0, 0, 0;
375+
CHECK((validatedComponents[2].vector - v).norm() < 1e-6);
376+
}
377+
}
378+
379+
{
380+
using AmvlIterativeElimination =
381+
Sparsepc::linearmodel::AmvlIterativeElimination<Scalar>;
382+
constexpr auto nbComponents = 3;
383+
const std::array<Index, nbComponents> choices{6, 2, 2};
384+
std::vector<Component> validatedComponents;
385+
validatedComponents.reserve(nbComponents);
386+
for (Index j = 0; j < nbComponents; ++j)
387+
{
388+
auto candidates =
389+
AmvlIterativeElimination::computeNextComponentCandidates(
390+
sigma, AmvlIterativeElimination::ImplementationParam{},
391+
validatedComponents, nullptr);
392+
const auto iCandidate = choices[j];
393+
for (auto &[i, candidate] : candidates)
394+
{
395+
candidate.state = Sparsepc::ComponentState::Unvalidated;
396+
}
397+
candidates.at(iCandidate).state =
398+
Sparsepc::ComponentState::Validated;
399+
validatedComponents.push_back(std::move(candidates.at(iCandidate)));
400+
}
401+
402+
{
403+
CHECK(std::abs(validatedComponents[0].value - 3.77096) < 1e-4);
404+
Vector v(n);
405+
v << 0.444022, 0.453036, 0, 0, 0, 0, 0.378041, 0.341986, 0.403168,
406+
0.418555, 0, 0, 0;
407+
CHECK((validatedComponents[0].vector - v).norm() < 1e-6);
408+
}
409+
{
410+
CHECK(std::abs(validatedComponents[1].value - 1.882) < 1e-4);
411+
Vector v(n);
412+
v << 0, 0, 0.707107, 0.707107, 0, 0, 0, 0, 0, 0, 0, 0, 0;
413+
CHECK((validatedComponents[1].vector - v).norm() < 1e-6);
414+
}
415+
{
416+
CHECK(std::abs(validatedComponents[2].value - 1.364) < 1e-4);
417+
Vector v(n);
418+
v << 0, 0, 0, 0, 0.707107, 0.707107, 0, 0, 0, 0, 0, 0, 0;
419+
CHECK((validatedComponents[2].vector - v).norm() < 1e-6);
420+
}
421+
}
290422
}
291423

292424
TEST_CASE("Sparsepc version")

0 commit comments

Comments
 (0)