Skip to main content

y_test.go

y_test.go - Overview

This file contains benchmark and unit tests for the PageBuffer and related functionalities. It tests the performance of PageBuffer against bytes.Buffer, and also verifies the correctness of write, truncate, and read operations, including reading at random offsets and with various chunk sizes. It also tests the ValueStruct and allocator reuse.

Detailed Documentation

BenchmarkBuffer

func BenchmarkBuffer(b *testing.B)

Purpose: Benchmarks the performance of bytes.Buffer and PageBuffer when writing data.

Parameters:

  • b (*testing.B): The benchmark testing object.

Returns: None

TestPageBuffer

func TestPageBuffer(t *testing.T)

Purpose: Tests the PageBuffer's ability to write and store data correctly by comparing its output to that of a bytes.Buffer.

Parameters:

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

Returns: None

TestBufferWrite

func TestBufferWrite(t *testing.T)

Purpose: Tests the PageBuffer's write functionality, ensuring data is written correctly and the length of the buffer matches the written data.

Parameters:

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

Returns: None

TestPagebufferTruncate

func TestPagebufferTruncate(t *testing.T)

Purpose: Tests the PageBuffer's truncate functionality, verifying that the buffer is truncated to the correct size and contains the expected data.

Parameters:

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

Returns: None

TestPagebufferReader

func TestPagebufferReader(t *testing.T)

Purpose: Tests the PageBuffer's reader functionality, ensuring data can be read correctly from the buffer using NewReaderAt and that io.EOF is returned at the end of the buffer.

Parameters:

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

Returns: None

TestPagebufferReader2

func TestPagebufferReader2(t *testing.T)

Purpose: Tests the PageBuffer's reader functionality by reading at random offsets and lengths within the buffer.

Parameters:

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

Returns: None

TestPagebufferReader3

func TestPagebufferReader3(t *testing.T)

Purpose: Tests the PageBuffer's reader by reading data in multiple small chunks, ensuring the data is read correctly and io.EOF is handled properly.

Parameters:

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

Returns: None

TestPagebufferReader4

func TestPagebufferReader4(t *testing.T)

Purpose: Tests the scenario where the read buffer is larger than the PageBuffer.

Parameters:

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

Returns: None

TestPagebufferReader5

func TestPagebufferReader5(t *testing.T)

Purpose: Tests the scenario when reading into a 0 length readBuffer.

Parameters:

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

Returns: None

TestSizeVarintForZero

func TestSizeVarintForZero(t *testing.T)

Purpose: Tests the sizeVarint function when the input is zero.

Parameters:

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

Returns: None

TestEncodedSize

func TestEncodedSize(t *testing.T)

Purpose: Tests the EncodedSize method of the ValueStruct, ensuring that the encoded size is calculated correctly.

Parameters:

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

Returns: None

TestAllocatorReuse

func TestAllocatorReuse(t *testing.T)

Purpose: Tests the reuse of the allocator.

Parameters:

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

Returns: None

Getting Started Relevance