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/Stack16Test.lvt

namespace Livt.Collections.Tests.Stack

using Livt.Collections.Stack

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

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

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

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

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

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

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

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