Skip to main content

bytelist_test.go

bytelist_test.go - Overview

This file contains unit tests for the byteList data structure, ensuring its functionality for appending, prepending, deleting, and deep copying operations.

Detailed Documentation

newNode

Purpose: Creates a new byteListNode and appends the given byte to its buffer.

Parameters:

  • bl (*byteList): The byte list to which the new node belongs.
  • b (byte): The byte to append to the new node's buffer.

Returns:

  • *byteListNode: The newly created byte list node.

toByteArray

Purpose: Converts a byteList to a byte array by iterating through the list and extracting the first byte from each node's buffer.

Parameters:

  • bl (*byteList): The byte list to convert.

Returns:

  • []byte: A byte array containing the first byte of each node in the list.

getNode

Purpose: Retrieves a node from the byte list whose first byte in the buffer matches the given byte.

Parameters:

  • bl (*byteList): The byte list to search.
  • b (byte): The byte to search for in the nodes' buffers.

Returns:

  • *byteListNode: The node containing the specified byte, or nil if not found.

tcase

type tcase struct {
op string
val []byte
}

Purpose: tcase is a struct used to define test cases for TestByteList. It contains an operation string (op) and the expected byte array value (val) after the operation.

TestByteList

Purpose: Tests the byteList functionality by performing a series of append, prepend, and delete operations and verifying the resulting byte array.

Parameters:

  • t (*testing.T): The testing object.

Returns:

  • None.

TestByteListDeepCopy

Purpose: Tests the DeepCopy method of the byteList to ensure that a true deep copy is created, where modifications to the original or the copy do not affect each other.

Parameters:

  • t (*testing.T): The testing object.

Returns:

  • None.

Getting Started Relevance