// Las funciones hash, con vectores oficiales. El Makefile compila esta prueba con -fsigned-char
// para que un char sin convertir falle en cualquier máquina.
#include <cassert>
#include <cstddef>
#include <iostream>
#include <string>
#include <vector>

#include "chain_lengths.h"
#include "hash_map.h"

int main(int argc, char** argv) {
    std::string which = argc > 1 ? argv[1] : "";
    if (which == "" || which == "fnv1a") {
        // Vectores de la página oficial de FNV (test_fnv.c, fnv1a_64_vector).
        assert(fnv1a("") == 0xcbf29ce484222325ULL);
        assert(fnv1a("a") == 0xaf63dc4c8601ec8cULL);
        assert(fnv1a("foobar") == 0x85944171f73967e8ULL);
        assert(fnv1a(std::string("\xff\x00\x00\x01", 4)) == 0x6961196491cc682dULL);
        assert(fnv1a(std::string("\x01\x00\x00\xff", 4)) == 0xad2bb1774799dfe9ULL);
    }
    if (which == "" || which == "sum_hash") {
        assert(sum_hash("") == 0);
        assert(sum_hash("ab") == 97 + 98);
        assert(sum_hash("amor") == sum_hash("roma"));
        assert(sum_hash("á") == 0xC3 + 0xA1);
    }
    if (which == "" || which == "chain_lengths") {
        std::vector<std::string> words = {"ab", "ba", "c"};
        std::vector<std::size_t> lengths = chain_lengths(words, 5, sum_hash);
        // 97 + 98 = 195, y 195 % 5 = 0. La 'c' es 99, y 99 % 5 = 4.
        assert((lengths == std::vector<std::size_t>{2, 0, 0, 0, 1}));
        assert(chain_lengths({}, 3, sum_hash) == std::vector<std::size_t>(3, 0));
    }
    std::cout << "ok\n";
}
