VCTR icon indicating copy to clipboard operation
VCTR copied to clipboard

Add more test for assignment operator of vctr::Span

Open JanosGit opened this issue 2 years ago • 0 comments

There were some issues that were not covered by the tests. These tests failed before deleting the default assignment operator

TEST_CASE ("Span assignments")
{
    vctr::Array<int, 1> a (0);
    vctr::Array<int, 1> b (1);

    SECTION ("Attempt 1")
    {
        a.subSpan (0) = b.subSpan (0);
        REQUIRE (a[0] == b[0]); // fails locally
    }

    SECTION ("Attempt 2")
    {
        auto aSpan = vctr::Span (a.data(), a.size());
        auto bSpan = vctr::Span (b.data(), b.size());
        aSpan = bSpan;

        REQUIRE (a[0] == b[0]); // passes locally
    }

    SECTION ("Attempt 3")
    {
        auto makeSpan = [] (int* ptr, size_t size) { return vctr::Span (ptr, size); };

        makeSpan (a.data(), a.size()) = makeSpan (b.data(), b.size());

        REQUIRE (a[0] == b[0]); // fails locally
    }

    SECTION ("Attempt 4")
    {
        auto makeSpan = [] (int* ptr, size_t size) { return vctr::Span (ptr, size); };

        makeSpan (a.data(), a.size())[0] = makeSpan (b.data(), b.size())[0];

        REQUIRE (a[0] == b[0]); // passes locally
    }
}

Equivalent test cases should be added to the vctr unit tests

JanosGit avatar Apr 17 '23 09:04 JanosGit