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/stack/Stack32Test.lvt

namespace Livt.Collections.Tests.Stack

using Livt.Collections.Stack

/**
 * Exercises Stack32 with a shared fixture instance. Each scenario establishes the inputs
 * and state it needs.
 */
@Test
component Stack32Test
{
	// Shared fixture instances, signals, and observation state.
	stack: Stack32

	/**
	 * Creates the shared fixture instances (Stack32). Tests initialize the state required by
	 * their scenario.
	 */
	new()
	{
		stack = new Stack32()
	}

	/**
	 * Checks the lifo order and peek case.
	 */
	@Test
	fn TestLifoOrderAndPeek()
	{
		stack.Clear()
		stack.Push(0b0000_0001)
		stack.Push(0b0000_0010)
		stack.Push(0b0000_0011)
		assert stack.Peek() == 0b0000_0011
		assert stack.GetSize() == 3
		assert stack.Pop() == 0b0000_0011
		assert stack.Pop() == 0b0000_0010
		assert stack.Pop() == 0b0000_0001
		assert stack.IsEmpty() == true
	}

	/**
	 * Checks the full stack rejects additional element case.
	 */
	@Test
	fn TestFullStackRejectsAdditionalElement()
	{
		stack.Clear()

		for (var i = 0; i < 32; i++) {
			stack.Push(0b0000_0001)
		}

		stack.Push(0b0000_0010)
		assert stack.IsFull() == true
		assert stack.GetSize() == 32

		for (var i = 0; i < 32; i++) {
			assert stack.Pop() == 0b0000_0001
		}
	}

	/**
	 * Checks that Clear allows reuse.
	 */
	@Test
	fn TestClearAllowsReuse()
	{
		stack.Clear()
		stack.Push(0b0000_0001)
		stack.Clear()
		stack.Push(0b0000_0010)
		assert stack.GetSize() == 1
		assert stack.Pop() == 0b0000_0010
	}
}