#include <stdio.h>

#include "sparse.hpp"

void show(const char *what, const SparseArray<bool>& c)
{
    printf("%-18s %d %d %d %d   (stored: %d)\n", what, c[0], c[1], c[5],
           c[1000000], c.NonzeroCount());
}

void test_default_false()
{
    SparseArray<bool> b(false);
    show("empty:", b);
    b[5] = true;
    b[1000000] = true;
    b[1] = 25;                          /* any nonzero number is true */
    show("three set:", b);
    b[1] = false;
    show("b[1] = false:", b);
    b[0] = b[5];
    show("b[0] = b[5]:", b);
    b[5] = true;                        /* already there: no duplicate */
    show("b[5] = true again:", b);
}

void test_default_true()
{
    SparseArray<bool> t(true);
    t[5] = false;
    show("default true:", t);
}

void test_growth()
{
    SparseArray<bool> b(false);
    int i, count = 0;
    for (i = 0; i < 1000; i++)
        b[3 * i] = true;
    for (i = 0; i < 3000; i++)
        if (b[i])
            count++;
    printf("%-18s %d of 3000   (stored: %d)\n", "every third:", count,
           b.NonzeroCount());
}

int main()
{
    SparseArray<int> a(0);              /* the general template still works */
    test_default_false();
    test_default_true();
    test_growth();
    a[7] = 42;
    printf("%-18s %d\n", "SparseArray<int>:", (int) a[7]);
    return 0;
}
