Livt packages
Livt.Collections
Version 1.4.2
Fixed-capacity FIFOs, queues, stacks, circular buffers, lists, and bit sets for Livt hardware.
Published files (62)
tests/queue/Queue8Test.lvt
namespace Livt.Collections.Tests.Queue
using Livt.Collections
/**
* Verifies inherited construction, capacity and the transaction API.
*/
@Test
component Queue8Test
{
// Shared fixture instances, signals, and observation state.
queue: Queue8
/**
* Creates the fixed-capacity specialization.
*/
new()
{
this.queue = new Queue8()
}
/**
* Checks the capacity and wrap around case.
*/
@Test
fn TestCapacityAndWrapAround()
{
this.queue.Clear()
var value: byte = 0xFF
assert this.queue.TryDequeue(value) == false
assert value == 0x00
for (var round = 0; round < 3; round++) {
assert this.queue.GetSpace() == 8
for (var index = 0; index < 8; index++) {
assert this.queue.TryEnqueue(index as byte) == true
}
assert this.queue.GetCount() == 8
assert this.queue.GetSpace() == 0
assert this.queue.TryEnqueue(0xFF) == false
for (var index = 0; index < 8; index++) {
assert this.queue.TryDequeue(value) == true
assert value == index as byte
}
assert this.queue.GetCount() == 0
}
}
/**
* Checks that clearing the queue permits another enqueue/dequeue sequence.
*/
@Test
fn TestClearAndReuse()
{
this.queue.Clear()
assert this.queue.TryEnqueue(0xA5) == true
this.queue.Clear()
assert this.queue.GetCount() == 0
assert this.queue.GetSpace() == 8
var value: byte = 0xFF
assert this.queue.TryDequeue(value) == false
assert value == 0x00
assert this.queue.TryEnqueue(0x00) == true
assert this.queue.TryDequeue(value) == true
assert value == 0x00
}
}