/**
 * Copyright (C) 2012 Brookhaven National Laboratory
 * All rights reserved. Use is subject to license terms.
 */
package org.epics.util.array;

import org.junit.Test;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.*;

/**
 *
 * @author carcassi
 */
public class ListNumbersTest {
    
    @Test
    public void sortedView1() {
        ArrayDouble values = new ArrayDouble(5,3,1,4,2,0);
        SortedListView sortedView = ListNumbers.sortedView(values);
        assertThat(values, equalTo(new ArrayDouble(5,3,1,4,2,0)));
        assertThat(sortedView, equalTo((ListNumber) new ArrayDouble(0,1,2,3,4,5)));
        assertThat(sortedView.getIndexes(), equalTo((ListInt) new ArrayInt(5,2,4,1,3,0)));
    }
    
    @Test
    public void sortedView2() {
        ArrayDouble values = new ArrayDouble(5,3,1,4,2,0);
        ArrayInt indexes = new ArrayInt(0,3,1,4,2,5);
        SortedListView sortedView = ListNumbers.sortedView(values, indexes);
        assertThat(values, equalTo(new ArrayDouble(5,3,1,4,2,0)));
        assertThat(sortedView, equalTo((ListNumber) new ArrayDouble(5,4,3,2,1,0)));
        assertThat(sortedView.getIndexes(), equalTo((ListInt) new ArrayInt(0,3,1,4,2,5)));
    }
    
    @Test
    public void sortedView3() {
        ArrayDouble values = new ArrayDouble(-1.7178013239620846, 0.5200744839822301, 0.638091980352644, 0.093683130487196, -1.2967630810250952, 0.7040257444802407, -0.4166241363846508, 2.9610862677876244, 0.03636268292097817, -0.35530274977371445);
        SortedListView sortedView = ListNumbers.sortedView(values);
        assertThat(sortedView, equalTo((ListNumber) new ArrayDouble(-1.7178013239620846, -1.2967630810250952, -0.4166241363846508, -0.35530274977371445, 0.03636268292097817, 0.093683130487196, 0.5200744839822301, 0.638091980352644, 0.7040257444802407, 2.9610862677876244)));
    }
    
    @Test
    public void binarySearchValueOrLower1() {
        ListNumber values = new ArrayDouble(1,2,3,3,4,5,5,6,7,8,10);
        assertThat(ListNumbers.binarySearchValueOrLower(values, 1), equalTo(0));
        assertThat(ListNumbers.binarySearchValueOrLower(values, 10), equalTo(10));
        assertThat(ListNumbers.binarySearchValueOrLower(values, 2), equalTo(1));
        assertThat(ListNumbers.binarySearchValueOrLower(values, 3), equalTo(2));
        assertThat(ListNumbers.binarySearchValueOrLower(values, 5), equalTo(5));
        assertThat(ListNumbers.binarySearchValueOrLower(values, 9), equalTo(9));
        assertThat(ListNumbers.binarySearchValueOrLower(values, 2.5), equalTo(1));
        assertThat(ListNumbers.binarySearchValueOrLower(values, 0.5), equalTo(0));
        assertThat(ListNumbers.binarySearchValueOrLower(values, 10), equalTo(10));
    }
    
    @Test
    public void binarySearchValueOrLower2() {
        ListNumber values = new ArrayDouble(1,2,2,2,2,2,2,2,2,2,3);
        assertThat(ListNumbers.binarySearchValueOrLower(values, 2), equalTo(1));
   }
    
    @Test
    public void binarySearchValueOrHigher1() {
        ListNumber values = new ArrayDouble(1,2,3,3,4,5,5,6,7,8,10);
        assertThat(ListNumbers.binarySearchValueOrHigher(values, 1), equalTo(0));
        assertThat(ListNumbers.binarySearchValueOrHigher(values, 10), equalTo(10));
        assertThat(ListNumbers.binarySearchValueOrHigher(values, 2), equalTo(1));
        assertThat(ListNumbers.binarySearchValueOrHigher(values, 3), equalTo(3));
        assertThat(ListNumbers.binarySearchValueOrHigher(values, 5), equalTo(6));
        assertThat(ListNumbers.binarySearchValueOrHigher(values, 9), equalTo(10));
        assertThat(ListNumbers.binarySearchValueOrHigher(values, 2.5), equalTo(2));
    }
    
    @Test
    public void binarySearchValueOrHigher2() {
        ListNumber values = new ArrayDouble(1,2,2,2,2,2,2,2,2,2,3);
        assertThat(ListNumbers.binarySearchValueOrHigher(values, 2), equalTo(9));
   }
}

@@ -1904,32 +1904,463 @@
    %0D%0A    @Test%0D%0A
+    public void sortedView4() %7B%0D%0A        ArrayDouble values = new ArrayDouble(0,1,2,4,3,5);%0D%0A        SortedListView sortedView = ListNumbers.sortedView(values);%0D%0A        assertThat(values, equalTo(new ArrayDouble(0,1,2,4,3,5)));%0D%0A        assertThat(sortedView, equalTo((ListNumber) new ArrayDouble(0,1,2,3,4,5)));%0D%0A        assertThat(sortedView.getIndexes(), equalTo((ListInt) new ArrayInt(0,1,2,4,3,5)));%0D%0A    %7D%0D%0A    %0D%0A    @Test%0D%0A
     public void 

add another sort test