Skip to main content

zcount_test.go

File Name: zcount_test.go

1. Overview

This file contains tests for the ZCOUNT command in the Ironhawk database. It tests various scenarios, including valid ranges, non-existent keys, invalid arguments, and different score types.

2. Detailed Documentation

TestZCOUNT Function

Purpose: Tests the functionality of the ZCOUNT command.

Parameters:

  • t (*testing.T): A testing object, providing methods for reporting test failures and successes.

Returns:

  • None

The function defines a set of test cases, each containing:

  • name (string): A descriptive name for the test case.
  • commands ([]string): A slice of strings, representing the commands to be executed. The first command usually adds data, the second is the ZCOUNT command being tested.
  • expected ([]interface{}): A slice of interfaces, representing the expected results of the commands.

It iterates through the test cases, executing the commands and comparing the results with the expected values using the runTestcases function (not defined in this file).

Each test case covers a specific scenario for the ZCOUNT command, such as:

  • Counting members within a valid score range.
  • Counting members when no members are within the range.
  • Counting on a non-existent key.
  • Handling different types of errors (wrong number of arguments, invalid number format, wrong type operation).
  • Working with negative and decimal scores.
  • Handling cases where min is greater than max.
  • Testing single value ranges.
  • Handling duplicate scores.
  • Using score 0.
  • Scenarios where the range is outside the scores.

3. Code Examples

None.

4. Getting Started Relevance