import java.nio.ByteBuffer;
import net.quasardb.qdb.*;
import org.junit.*;

public class QdbDequeGetTest {
    @Test
    public void returnsItems_afterCallingPushBack() {
        QdbDeque deque = Helpers.createEmptyDeque();
        ByteBuffer content1 = Helpers.createSampleData();
        ByteBuffer content2 = Helpers.createSampleData();

        deque.pushBack(content1);
        deque.pushBack(content2);
        ByteBuffer result1 = deque.get(0);
        ByteBuffer result2 = deque.get(1);

        Assert.assertEquals(content1, result1);
        Assert.assertEquals(content2, result2);
    }

    @Test
    public void returnsItems_afterCallingPushFront() {
        QdbDeque deque = Helpers.createEmptyDeque();
        ByteBuffer content1 = Helpers.createSampleData();
        ByteBuffer content2 = Helpers.createSampleData();

        deque.pushFront(content1);
        deque.pushFront(content2);
        ByteBuffer result1 = deque.get(0);
        ByteBuffer result2 = deque.get(1);

        Assert.assertEquals(content2, result1);
        Assert.assertEquals(content1, result2);
    }

    @Test(expected = QdbOutOfBoundsException.class)
    public void throwsOutOfBounds_whenIndexIsNegative() {
        QdbDeque deque = Helpers.createEmptyDeque();
        ByteBuffer content = Helpers.createSampleData();

        deque.pushBack(content);
        deque.get(-1); // <- throws
    }

    @Test(expected = QdbOutOfBoundsException.class)
    public void throwsOutOfBounds_whenIndexIsGreaterThanSize() {
        QdbDeque deque = Helpers.createEmptyDeque();
        ByteBuffer content = Helpers.createSampleData();

        deque.pushBack(content);
        deque.get(1); // <- throws
    }

    @Test(expected = QdbAliasNotFoundException.class)
    public void throwsAliasNotFound() {
        QdbDeque deque = Helpers.createEmptyDeque();

        deque.get(0); // <- throws
    }

    @Test(expected = QdbIncompatibleTypeException.class)
    public void throwsIncompatibleTypeFound_afterCallingIntegerPut() {
        String alias = Helpers.createUniqueAlias();
        QdbInteger integer = Helpers.getInteger(alias);
        QdbDeque deque = Helpers.getDeque(alias);

        integer.put(666);
        deque.get(0); // <- throws
    }

    @Test(expected = QdbReservedAliasException.class)
    public void throwsReservedAlias() {
        QdbDeque deque = Helpers.getDeque("qdb");
        deque.get(0); // <- throws
    }
}

@@ -142,29 +142,35 @@
 tems
-_afterCallingPushBack
+InOrder_whenIndexIsPositive
 () %7B
@@ -640,30 +640,42 @@
 tems
-_afterCallingPushFront
+InReverseOrder_whenIndexIsNegative
 () %7B
@@ -855,37 +855,36 @@
       deque.push
-Front
+Back
 (content1);%0A    
@@ -901,13 +901,12 @@
 push
-Front
+Back
 (con
@@ -944,33 +944,34 @@
 lt1 = deque.get(
-0
+-1
 );%0A        ByteB
@@ -988,33 +988,34 @@
 lt2 = deque.get(
-1
+-2
 );%0A%0A        Asse
@@ -1194,39 +1194,46 @@
 unds_whenIndexIs
-Negativ
+GreaterThanSiz
 e() %7B%0A        Qd
@@ -1384,17 +1384,16 @@
 que.get(
--
 1); // %3C
@@ -1501,35 +1501,40 @@
 _whenIndexIs
-Great
+Low
 erThan
+Negated
 Size() %7B%0A   
@@ -1684,33 +1684,34 @@
       deque.get(
-1
+-2
 ); // %3C- throws%0A

allow index to be negative