/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * Copyright 2019 Danny Robson <danny@nerdcruft.net>
 */

#include "coord/comparator.hpp"
#include "job/dispatch.hpp"
#include "tap.hpp"

#include <vector>


///////////////////////////////////////////////////////////////////////////////
struct value {
    template <typename T>
    void operator= (T &&) { }
};


//-----------------------------------------------------------------------------
struct data_t {
    cruft::extent2i extent (void) const { return { 4, 4 }; }
    auto operator[] (cruft::point2i) { return value {};};
};


//-----------------------------------------------------------------------------
void test_dispatch_uniqueness (cruft::TAP::logger &tap)
{
    std::vector<cruft::point2i> points;
    data_t data;

    cruft::job::queue q (1, 512  * 512 + 1);
    cruft::job::dispatch (
        q, data,
        cruft::extent2i {2},
        [&] (cruft::point2i p)
    {
        points.push_back (p);
        return 0;
    });

    cruft::coord::ordering<cruft::point2i> comp {};
    std::sort (points.begin (), points.end (), comp);
    auto const pos = std::adjacent_find (points.begin (), points.end ());
    tap.expect (pos == points.end (), "job::queue indices are unique");
}


///////////////////////////////////////////////////////////////////////////////
int main ()
{
    cruft::TAP::logger tap;
    test_dispatch_uniqueness (tap);
    return tap.status ();
}