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

namespace Livt.Collections.Tests.List

using Livt.Collections.List

/**
 * Exercises ListIterator with a shared fixture instance. Each scenario establishes the
 * inputs and state it needs.
 */
@Test
component ListIteratorTest
{
	// Shared fixture instances, signals, and observation state.
	values: IList<byte>
	first: ListIterator<byte>
	second: ListIterator<byte>

	/**
	 * Creates the shared fixture instances (List8, ListIterator). Tests initialize the state
	 * required by their scenario.
	 */
	new()
	{
		this.values = new List8()
		this.first = new ListIterator<byte>(this.values)
		this.second = new ListIterator<byte>(this.values)
	}

	/**
	 * Checks the independent cursors case.
	 */
	@Test
	fn IndependentCursors()
	{
		this.values.Clear()
		this.values.Add(0x01)
		this.values.Add(0x02)
		this.values.Add(0x03)
		this.first.Reset()
		this.second.Reset()
		var sum = 0

		while (this.first.HasNext()) {
			var value = this.first.Next()
			sum += value as int
		}

		assert sum == 6
		var next = this.second.Next()
		assert next == 0x01
		var size = this.values.GetSize()
		assert size == 3
		this.first.Reset()
		var repeated = this.first.Next()
		assert repeated == 0x01
	}
}