Hone logo
Hone
Problems

A/B Testing Framework in Go

A/B testing is a crucial technique for optimizing products and features by comparing different versions against each other. This challenge asks you to implement a basic A/B testing framework in Go, allowing you to track impressions and conversions for different variations and determine a winner based on a simple metric. This framework will provide a foundation for making data-driven decisions about your application.

Problem Description

You are tasked with building a simple A/B testing framework in Go. The framework should allow you to define different variations (e.g., "control", "variation_1", "variation_2") and track the number of impressions and conversions for each variation. The framework should provide a method to record an impression and a method to record a conversion. Finally, it should provide a method to determine the winning variation based on a conversion rate (conversions / impressions). Handle cases where impressions are zero gracefully.

Key Requirements:

  • Variation Definition: The framework should allow you to define variations with unique names.
  • Impression Tracking: A method to record an impression for a specific variation.
  • Conversion Tracking: A method to record a conversion for a specific variation.
  • Winner Determination: A method to determine the variation with the highest conversion rate.
  • Zero Impression Handling: The framework must handle cases where a variation has zero impressions without causing a division-by-zero error. In such cases, the conversion rate should be considered 0.

Expected Behavior:

The framework should accurately track impressions and conversions for each variation. The DetermineWinner method should return the variation with the highest conversion rate. If multiple variations have the same highest conversion rate, it should return the first one encountered. If no variations have been recorded, it should return an empty string.

Edge Cases to Consider:

  • Variations with zero impressions.
  • No variations defined.
  • Multiple variations with the same highest conversion rate.
  • Invalid variation names (though this is not strictly required to be handled, consider how it might be handled in a real-world scenario).

Examples

Example 1:

Input:
  - Define variations: "control", "variation_1"
  - Record impressions: control (100), variation_1 (50)
  - Record conversions: control (10), variation_1 (15)
  - DetermineWinner()
Output: "variation_1"
Explanation: control has a conversion rate of 10/100 = 0.1, while variation_1 has a conversion rate of 15/50 = 0.3. Therefore, variation_1 is the winner.

Example 2:

Input:
  - Define variations: "A", "B", "C"
  - Record impressions: A (200), B (100), C (50)
  - Record conversions: A (20), B (10), C (5)
  - DetermineWinner()
Output: "A"
Explanation: A has a conversion rate of 20/200 = 0.1, B has a conversion rate of 10/100 = 0.1, and C has a conversion rate of 5/50 = 0.1. Since A is encountered first, it is returned as the winner.

Example 3: (Edge Case - Zero Impressions)

Input:
  - Define variations: "control", "variation_1"
  - Record impressions: control (100), variation_1 (0)
  - Record conversions: control (10), variation_1 (5)
  - DetermineWinner()
Output: "control"
Explanation: control has a conversion rate of 10/100 = 0.1, while variation_1 has a conversion rate of 5/0 = 0 (handled gracefully). Therefore, control is the winner.

Constraints

  • Variation names should be strings.
  • Impression and conversion counts should be non-negative integers.
  • The framework should be reasonably efficient for a small number of variations (up to 10). Performance is not a primary concern for this challenge.
  • Error handling for invalid input (e.g., negative counts) is not required.

Notes

Consider using a map to store the impression and conversion counts for each variation. Think about how to structure your code to make it easy to add new features to the framework in the future (e.g., different metrics, statistical significance testing). Focus on clarity and correctness first. The DetermineWinner function should return the name of the winning variation, not the variation object itself.

Loading editor...
go