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

namespace Livt.Collections.Tests.Stack

using Livt.Collections.Stack

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

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

	/**
	 * Checks the capacity and lifo order case.
	 */
	@Test
	fn TestCapacityAndLifoOrder()
	{
		this.stack.Clear()
		this.stack.Push(0b0000_0010)

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

		assert this.stack.IsFull() == true
		assert this.stack.GetSize() == 64

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

		assert this.stack.Pop() == 0b0000_0010
		assert this.stack.IsEmpty() == true
	}

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

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

		this.stack.Push(0b0000_0010)
		assert this.stack.GetSize() == 64
		assert this.stack.Peek() == 0b0000_0001
	}
}