Livt packages
Livt.Collections
Version 1.4.5
Fixed-capacity FIFOs, queues, stacks, circular buffers, lists, and bit sets for Livt hardware.
Published files (69)
tests/GenericCollectionsTest.lvt
namespace Livt.Collections.Tests
using Livt.Collections.Circular
using Livt.Collections.List
using Livt.Collections.Stack
/**
* Verifies typed, non-power-of-two generic collections and their interfaces.
*/
@Test
component GenericCollectionsTest
{
// Interface-owned implementations prove contracts remain independent of capacity.
stackContract: IStack<int>
listContract: IList<bool>
bufferContract: ICircularBuffer<int>
iterator: ListIterator<bool>
// Single-entry implementations cover the minimum supported capacity.
singleStack: IStack<byte>
singleList: IList<byte>
singleBuffer: ICircularBuffer<byte>
/**
* Creates one instance per family and exposes each through its generic contract.
*/
new()
{
stackContract = new Livt.Collections.Stack.Stack<int, 3>()
listContract = new Livt.Collections.List.List<bool, 3>()
bufferContract = new CircularBuffer<int, 3>()
iterator = new ListIterator<bool>(listContract)
singleStack = new Livt.Collections.Stack.Stack<byte, 1>()
singleList = new Livt.Collections.List.List<byte, 1>()
singleBuffer = new CircularBuffer<byte, 1>()
}
/**
* Verifies that the minimum capacity uses valid counters and ring wrapping.
*/
@Test
fn TestSingleEntryCollections()
{
singleStack.Clear()
singleStack.Push(7)
singleStack.Push(8)
assert singleStack.IsFull()
assert singleStack.Pop() == 7
assert singleStack.Pop() == 0
singleList.Clear()
singleList.Add(9)
singleList.Add(10)
assert singleList.IsFull()
assert singleList.Get(0) == 9
assert singleList.RemoveLast()
singleBuffer.Clear()
singleBuffer.Write(11)
singleBuffer.Write(12)
assert singleBuffer.IsFull()
assert singleBuffer.Read() == 12
assert singleBuffer.Read() == 0
}
/**
* Verifies typed LIFO ordering, full rejection, and empty zero values.
*/
@Test
fn TestGenericStackContract()
{
stackContract.Clear()
stackContract.Push(11)
stackContract.Push(22)
stackContract.Push(33)
stackContract.Push(44)
assert stackContract.IsFull()
assert stackContract.GetSize() == 3
assert stackContract.Pop() == 33
assert stackContract.Pop() == 22
assert stackContract.Pop() == 11
assert stackContract.Pop() == 0
}
/**
* Verifies typed indexed access, bounds handling, and logical clearing.
*/
@Test
fn TestGenericListContract()
{
listContract.Clear()
listContract.Add(true)
listContract.Add(false)
listContract.Set(1, true)
assert listContract.Get(0)
assert listContract.Get(1)
assert listContract.Get(2) == false
assert listContract.RemoveLast()
assert listContract.GetSize() == 1
iterator.Reset()
assert iterator.HasNext()
assert iterator.Next()
assert iterator.HasNext() == false
}
/**
* Verifies typed FIFO ordering and overwrite behavior after ring wrapping.
*/
@Test
fn TestGenericCircularBufferContract()
{
bufferContract.Clear()
bufferContract.Write(10)
bufferContract.Write(20)
bufferContract.Write(30)
bufferContract.Write(40)
assert bufferContract.IsFull()
assert bufferContract.Read() == 20
assert bufferContract.Read() == 30
assert bufferContract.Read() == 40
assert bufferContract.Read() == 0
}
}