package net.ranides.assira.collection.maps;

import net.ranides.test.ContractTesters;
import net.ranides.test.data.TMap;
import net.ranides.test.data.TMaps;
import net.ranides.test.data.TPoint;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;

public class WBTreeMapTest {

    private final TMap<TPoint, Integer> $map = TMaps.MAP_PI;

    @Test
    public void testSuite() {
        ContractTesters.runner()
            .param("map!", $map)
            .function(new int[0], array -> $map.list(array).into(new WBTreeMap<>($map.comparator())))
            .run();
    }

    @Test
    public void basic() {
        WBTreeMap<Integer, String> tree = new WBTreeMap<>();

        tree.put(5, "five");
        tree.put(3, "three");
        tree.put(1, "one");
        tree.put(6, "six");
        tree.put(2, "two");
        tree.put(4, "four");

//        List<Map.Entry<Integer, String>> values = new ArrayList<>();
        List<Integer> values = new ArrayList<>();
        tree.forEach((k,v) -> values.add(k));

        assertEquals(Arrays.asList(1,2,3,4,5,6), values);

        tree.remove(3);
        tree.remove(6);

        List<Integer> values2 = new ArrayList<>();
        tree.forEach((k,v) -> values2.add(k));
        assertEquals(Arrays.asList(1,2,4,5), values2);

        assertEquals(2, tree.entryIterator(2).next().getKey().intValue());

        assertArrayEquals(new Integer[]{1,2,4,5}, tree.keySet().toArray(new Integer[0]));
    }
}