package de.wwwu.awolf.presenter.util;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;

import static org.junit.Assert.*;

/**
 * Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
 *
 * @Author: Armin Wolf
 * @Email: a_wolf28@uni-muenster.de
 * @Date: 23.10.2017.
 */
public class FastElementSelectorTest {


    @Test
    public void randomizedSelect() throws Exception {
        Double[] array = {1d, 2d, 3d, 4d};
        ArrayList<Double> list = new ArrayList<>(Arrays.asList(array));
        assertEquals(FastElementSelector.randomizedSelect(list, 0), 1d, 0.00001);
        assertEquals(FastElementSelector.randomizedSelect(list, 2), 2d, 0.00001);
    }

    @Test(expected = IndexOutOfBoundsException.class)
    public void testIndexOutOfBoundsException() {
        FastElementSelector.randomizedSelect(Collections.emptyList(), 42);
    }

}