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/bitset/BitSet8Test.lvt

namespace Livt.Collections.Tests.BitSet

using Livt.Collections.BitSet

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

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

	/**
	 * Checks that Set clear and value.
	 */
	@Test
	fn TestSetClearAndValue()
	{
		this.bits.Reset()
		this.bits.Set(0)
		this.bits.Set(2)
		this.bits.Set(7)
		assert this.bits.IsSet(0) == true
		assert this.bits.IsSet(2) == true
		assert this.bits.IsSet(7) == true
		assert this.bits.GetValue() == 133
		this.bits.Clear(2)
		assert this.bits.GetValue() == 129
	}

	/**
	 * Checks the toggle case.
	 */
	@Test
	fn TestToggle()
	{
		this.bits.Reset()
		this.bits.Toggle(3)
		assert this.bits.IsSet(3) == true
		this.bits.Toggle(3)
		assert this.bits.IsSet(3) == false
	}

	/**
	 * Checks that Any none and reset.
	 */
	@Test
	fn TestAnyNoneAndReset()
	{
		this.bits.Reset()
		assert this.bits.None() == true
		assert this.bits.Any() == false
		this.bits.Set(5)
		assert this.bits.Any() == true
		assert this.bits.None() == false
		this.bits.Reset()
		assert this.bits.None() == true
	}

	/**
	 * Checks the bounds and capacity case.
	 */
	@Test
	fn TestBoundsAndCapacity()
	{
		this.bits.Reset()
		this.bits.Set(-1)
		this.bits.Set(8)
		this.bits.Toggle(9)
		this.bits.Clear(-1)
		this.bits.Clear(8)
		assert this.bits.GetValue() == 0
		assert this.bits.IsSet(-1) == false
		assert this.bits.IsSet(8) == false
		assert this.bits.GetCapacity() == 8
	}
}