//
//  First
//
TEST_F( SimplexSupportDoublyLinkedList, FirstReturnsLastElementPushedToFront )
{
    MockStruct* m1 = new MockStruct();
    MockStruct* m2 = new MockStruct();
    MockStruct* m3 = new MockStruct();

    DoublyLinkedList list;

    list.PushFront(m1);

    ASSERT_EQ(list.First()->Value, (MockStruct*)m1);

    list.PushFront(m2);

    ASSERT_EQ(list.First()->Value, (MockStruct*)m2);

    list.PushFront(m3);

    ASSERT_EQ(list.First()->Value, (MockStruct*)m3);

    delete(m1);
    delete(m2);
    delete(m3);

}
TEST_F( SimplexSupportDoublyLinkedList, PushFrontSetsLastElementIfNoElementPresent )
{
    MockStruct* m = new MockStruct();
    DoublyLinkedList list;

    list.PushFront( m );

    ASSERT_EQ ( (MockStruct*)list.Last()->Value, m );

    delete(m);
}
TEST_F( SimplexSupportDoublyLinkedList, PopFrontUpdatesLastWhenListIsEmptied )
{
    MockStruct* m = new MockStruct();
    DoublyLinkedList list;

    list.PushFront( m );
    list.PopFront();

    ASSERT_EQ ( list.Last(), nullptr );
    delete(m);
}
TEST_F( SimplexSupportDoublyLinkedList, PushFrontAddsElement )
{
    MockStruct* m = new MockStruct();
    DoublyLinkedList list;

    list.PushFront( m );

    ASSERT_EQ ( (MockStruct*)list.First()->Value, m );

    delete(m);
}
TEST_F( SimplexSupportDoublyLinkedList, PopFrontReturnsObject )
{
    MockStruct* m1 = new MockStruct();

    DoublyLinkedList list;

    list.PushFront(m1);
    MockStruct*m2 = (MockStruct*) list.PopFront();

    ASSERT_EQ(m2, m1);
    delete(m1);
}
TEST_F( SimplexSupportDoublyLinkedList, PushFrontReservesMemoryToHoldOneNodeByDefault )
{
    ASSERT_EQ(mAllocator->GetAllocationCount(), 0);

    MockStruct* m = new MockStruct();
    DoublyLinkedList list;
    list.PushFront(m);

    ASSERT_EQ(mAllocator->GetAllocationCount(), 1);

    delete(m);
}
TEST_F( SimplexSupportDoublyLinkedList, PushFrontPreservesConnectionToPreviousFirst )
{
    MockStruct* m1 = new MockStruct();
    MockStruct* m2 = new MockStruct();

    DoublyLinkedList list;

    list.PushFront(m1);
    list.PushFront(m2);

    ASSERT_EQ(list.First()->Next->Value, (MockStruct*)m1);

    delete(m1);
    delete(m2);
}
TEST_F( SimplexSupportDoublyLinkedList, PushFrontSetsPreviousAndNextCorrectly )
{
    MockStruct* m1 = new MockStruct();
    MockStruct* m2 = new MockStruct();

    DoublyLinkedList list;

    list.PushFront( m1 );
    list.PushFront( m2 );

    ASSERT_EQ( list.Last()->Previous->Value, m2);
    ASSERT_EQ( list.First()->Next->Value, m1);

    delete(m1);
    delete(m2);
}
TEST_F( SimplexSupportDoublyLinkedList, PopFrontDeallocatesNode )
{
    MockStruct* m1 = new MockStruct();

    DoublyLinkedList list;

    list.PushFront(m1);

    ASSERT_EQ(mAllocator->GetAllocationCount(), 1);

    list.PopFront();

    ASSERT_EQ(mAllocator->GetAllocationCount(), 0);
    ASSERT_EQ(mAllocator->GetUsedMemory(), 0);

    delete(m1);
}