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/list/ListTest.lvt
namespace Livt.Collections.Tests.List
using Livt.Collections.List
/**
* Exercises List with a shared fixture instance. Each scenario establishes the inputs and
* state it needs.
*/
@Test
component ListTest
{
// Shared fixture instances, signals, and observation state.
list8: List8
// Shared fixture instances, signals, and observation state.
list16: List16
// Shared fixture instances, signals, and observation state.
list32: List32
// Shared fixture instances, signals, and observation state.
list64: List64
/**
* Creates the shared fixture instances (List8, List16, List32, List64). Tests initialize
* the state required by their scenario.
*/
new()
{
this.list8 = new List8()
this.list16 = new List16()
this.list32 = new List32()
this.list64 = new List64()
}
/**
* Checks the list8 indexed operations case.
*/
@Test
fn TestList8IndexedOperations()
{
this.list8.Clear()
this.list8.Add(0b0000_0001)
this.list8.Add(0b0000_0010)
this.list8.Add(0b0000_0011)
assert this.list8.GetSize() == 3
assert this.list8.Get(0) == 0b0000_0001
assert this.list8.Get(1) == 0b0000_0010
this.list8.Set(1, 0b0000_0100)
assert this.list8.Get(1) == 0b0000_0100
assert this.list8.RemoveLast() == 0b0000_0011
assert this.list8.GetSize() == 2
}
/**
* Checks the list16 rejects add when full case.
*/
@Test
fn TestList16RejectsAddWhenFull()
{
this.list16.Clear()
for (var i = 0; i < 16; i++) {
this.list16.Add(0b0000_0001)
}
this.list16.Add(0b0000_0010)
assert this.list16.IsFull() == true
assert this.list16.GetSize() == 16
assert this.list16.RemoveLast() == 0b0000_0001
}
/**
* Checks the list32 bounds case.
*/
@Test
fn TestList32Bounds()
{
this.list32.Clear()
this.list32.Add(0b0000_0001)
this.list32.Set(-1, 0b0000_0010)
this.list32.Set(1, 0b0000_0010)
assert this.list32.Get(-1) == 0b0000_0000
assert this.list32.Get(1) == 0b0000_0000
assert this.list32.Get(0) == 0b0000_0001
assert this.list32.GetSize() == 1
}
/**
* Checks the list64 capacity and order case.
*/
@Test
fn TestList64CapacityAndOrder()
{
this.list64.Clear()
this.list64.Add(0b0000_0010)
for (var i = 1; i < 64; i++) {
this.list64.Add(0b0000_0001)
}
assert this.list64.IsFull() == true
assert this.list64.GetSize() == 64
assert this.list64.Get(0) == 0b0000_0010
assert this.list64.Get(63) == 0b0000_0001
}
/**
* Checks the empty remove and clear case.
*/
@Test
fn TestEmptyRemoveAndClear()
{
this.list8.Clear()
assert this.list8.IsEmpty() == true
assert this.list8.RemoveLast() == 0b0000_0000
this.list8.Add(0b0000_0001)
this.list8.Clear()
assert this.list8.GetSize() == 0
assert this.list8.Get(0) == 0b0000_0000
}
/**
* Checks that Add preserves values written by set.
*/
@Test
fn TestAddPreservesValuesWrittenBySet()
{
this.list8.Clear()
this.list8.Add(0b0000_0001)
this.list8.Add(0b0000_0010)
this.list8.Set(0, 0b0000_0011)
this.list8.Add(0b0000_0100)
assert this.list8.GetSize() == 3
assert this.list8.Get(0) == 0b0000_0011
assert this.list8.Get(1) == 0b0000_0010
assert this.list8.Get(2) == 0b0000_0100
}
}