Testing Probabilistic Business Interfaces with Variable Winning Probability

This article explains how to test a probabilistic lottery API where the winning chance increases with consecutive losses, outlines the required interfaces, discusses two large‑scale testing approaches, and highlights the challenges of ensuring correctness without consecutive wins.

FunTester
FunTester
FunTester
Testing Probabilistic Business Interfaces with Variable Winning Probability

Following the previous discussion on testing probabilistic business interfaces, a new requirement introduces a non‑fixed probability algorithm where the user’s winning probability is calculated as P = p(1+0.1*N). Here, p is the original winning probability, N is the number of consecutive losses (capped at 5), users cannot win consecutively, and each gift’s probability is rounded to the nearest 1%.

The system provides three APIs: a lottery draw interface, an activity configuration interface (including gift settings), and a personal activity detail interface (user info, draw count, win history).

The testing tool is implemented in Java, wrapping the three APIs into methods that are repeatedly invoked to gather data and compute statistics; the test runs for one day.

The core testing difficulty lies in verifying the correct implementation of the formula P = p(1+0.1*N) under the constraints of no consecutive wins and variable probability.

Solution 1: Compute the theoretical overall winning probability for various p values through mathematical analysis, then perform massive lottery simulations and compare the observed results with the theoretical expectations, using the same standards as the previous probabilistic interface test.

Solution 2: Conduct a large‑scale simulation (e.g., 10,000 draws), record each draw as 1 (win) or 0 (loss), build a table of P versus N for a specific p, and count occurrences of patterns such as "1000" and "1001" to derive the empirical probability after two consecutive losses; compare this empirical probability with the theoretical Pn, again using the prior test standards.

Both approaches involve substantial test volume and time consumption; because the probability is evaluated per user, multithreaded testing must bind each thread to a distinct virtual user.

The article concludes that such requirements are best addressed with white‑box testing techniques.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

BackendjavaautomationAPIprobability
FunTester
Written by

FunTester

10k followers, 1k articles | completely useless

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.