sonible / VCTR

A powerful C++ 20 wrapper around your favorite standard library containers
https://sonible.github.io/VCTR/
Other
25 stars 1 forks source link

Add more test for assignment operator of vctr::Span #90

Open JanosGit opened 1 year ago

JanosGit commented 1 year ago

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