Skip to main content

deque_test.go

deque_test.go - Overview

This file contains unit tests and benchmarks for the deque implementations in deque.go. It tests the encoding/decoding of deque entries, and the LRange and LInsert operations for both Deque and DequeBasic implementations.

Detailed Documentation

Variables

  • deqRandGenerator *rand.Rand: A random number generator used for generating test data.
  • deqRunes []rune: A slice of runes used for generating random strings.

Functions

  • deqTestInit(): Initializes the random number generator with a seed based on the current time.
  • deqRandStr(n int) string: Generates a random string of length n using the runes in deqRunes.
    • Parameters:
      • n int: The length of the random string to generate.
    • Returns: A random string of length n.
  • TestDeqEncodeEntryString(t *testing.T): Tests the encoding and decoding of various string and integer values using EncodeDeqEntry and DecodeDeqEntry.
    • Parameters:
      • t *testing.T: The testing object.
  • dequeRPushIntStrMany(howmany int, deq eval.DequeI): Pushes howmany integer strings onto the right side of the deque.
    • Parameters:
      • howmany int: The number of integers to push.
      • deq eval.DequeI: The deque to push the integers onto.
  • dequeLPushIntStrMany(howmany int, deq eval.DequeI): Pushes howmany integer strings onto the left side of the deque.
    • Parameters:
      • howmany int: The number of integers to push.
      • deq eval.DequeI: The deque to push the integers onto.
  • dequeLInsertIntStrMany(howMany int, beforeAfter string, deq eval.DequeI): Performs multiple LInsert operations on the deque.
    • Parameters:
      • howMany int: The number of LInsert operations to perform.
      • beforeAfter string: Specifies whether to insert before or after the pivot.
      • deq eval.DequeI: The deque to perform the LInsert operations on.
  • BenchmarkBasicDequeLInsertBefore2000(b *testing.B): Benchmarks the LInsert operation with "before" option for BasicDeque.
    • Parameters:
      • b *testing.B: The benchmark object.
  • BenchmarkBasicDequeLInsertAfter2000(b *testing.B): Benchmarks the LInsert operation with "after" option for BasicDeque.
    • Parameters:
      • b *testing.B: The benchmark object.
  • BenchmarkDequeLInsertBefore2000(b *testing.B): Benchmarks the LInsert operation with "before" option for Deque.
    • Parameters:
      • b *testing.B: The benchmark object.
  • BenchmarkDequeLInsertAfter2000(b *testing.B): Benchmarks the LInsert operation with "after" option for Deque.
    • Parameters:
      • b *testing.B: The benchmark object.
  • BenchmarkBasicDequeRPush20(b *testing.B): Benchmarks the RPush operation for BasicDeque with 20 elements.
    • Parameters:
      • b *testing.B: The benchmark object.
  • BenchmarkBasicDequeRPush200(b *testing.B): Benchmarks the RPush operation for BasicDeque with 200 elements.
    • Parameters:
      • b *testing.B: The benchmark object.
  • BenchmarkBasicDequeRPush2000(b *testing.B): Benchmarks the RPush operation for BasicDeque with 2000 elements.
    • Parameters:
      • b *testing.B: The benchmark object.
  • BenchmarkDequeRPush20(b *testing.B): Benchmarks the RPush operation for Deque with 20 elements.
    • Parameters:
      • b *testing.B: The benchmark object.
  • BenchmarkDequeRPush200(b *testing.B): Benchmarks the RPush operation for Deque with 200 elements.
    • Parameters:
      • b *testing.B: The benchmark object.
  • BenchmarkDequeRPush2000(b *testing.B): Benchmarks the RPush operation for Deque with 2000 elements.
    • Parameters:
      • b *testing.B: The benchmark object.
  • BenchmarkDequeLPush20(b *testing.B): Benchmarks the LPush operation for Deque with 20 elements.
    • Parameters:
      • b *testing.B: The benchmark object.
  • BenchmarkDequeLPush200(b *testing.B): Benchmarks the LPush operation for Deque with 200 elements.
    • Parameters:
      • b *testing.B: The benchmark object.
  • BenchmarkDequeLPush2000(b *testing.B): Benchmarks the LPush operation for Deque with 2000 elements.
    • Parameters:
      • b *testing.B: The benchmark object.
  • TestLRange(t *testing.T): Tests the LRange operation with various start and stop indices for both Deque and DequeBasic implementations.
    • Parameters:
      • t *testing.T: The testing object.
  • TestLInsertOnInvalidOperationTypeReturnsError(t *testing.T): Tests that LInsert returns an error when an invalid beforeAfter value is passed.
    • Parameters:
      • t *testing.T: The testing object.
  • TestLInsertBasicDeque(t *testing.T): Tests the LInsert operation for the BasicDeque implementation.
    • Parameters:
      • t *testing.T: The testing object.
  • DequeLInsertFixture: Struct used for setting up test fixtures for LInsert tests.
    • Fields:
      • dq *eval.Deque: The deque instance.
      • initialElements []string: Initial elements in the deque.
      • elementsToBeInserted []string: Elements to be inserted.
  • newDequeLInsertFixture() *DequeLInsertFixture: Creates a new DequeLInsertFixture with a pre-populated deque.
    • Returns: A pointer to the new fixture.
  • TestDequeLInsertBefore(t *testing.T): Tests the LInsert operation with the "before" option for the Deque implementation.
    • Parameters:
      • t *testing.T: The testing object.
  • TestLInsertAfter(t *testing.T): Tests the LInsert operation with the "after" option for the Deque implementation.
    • Parameters:
      • t *testing.T: The testing object.

Getting Started Relevance