forked from skent259/crapssim
-
Notifications
You must be signed in to change notification settings - Fork 0
Simplify commission handling and update tests #72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,69 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import math | ||
| from dataclasses import dataclass | ||
|
|
||
| import pytest | ||
|
|
||
| from crapssim.bet import _compute_commission | ||
|
|
||
|
|
||
| @dataclass | ||
| class _StubTable: | ||
| settings: dict | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("mode", "rounding", "floor", "bet", "expected"), | ||
| [ | ||
| ("on_bet", "ceil_dollar", 0.0, 20.0, 1.0), | ||
| ("on_win", "ceil_dollar", 0.0, 20.0, 1.0), | ||
| ("on_bet", "nearest_dollar", 1.0, 20.0, 1.0), | ||
| ("on_win", "nearest_dollar", 1.0, 25.0, 1.0), | ||
| ("on_bet", "nearest_dollar", 1.0, 5.0, 1.0), | ||
| ("on_bet", "none", 0.0, 20.0, 1.0), | ||
| ], | ||
| ) | ||
| def test_compute_commission_expected_values(mode, rounding, floor, bet, expected): | ||
| table = _StubTable( | ||
| settings={ | ||
| "commission_mode": mode, | ||
| "commission_rounding": rounding, | ||
| "commission_floor": floor, | ||
| } | ||
| ) | ||
|
|
||
| result = _compute_commission(table, gross_win=bet * 3.5, bet_amount=bet) | ||
|
|
||
| assert math.isclose(result, expected, rel_tol=0.0, abs_tol=1e-9) | ||
|
|
||
|
|
||
| from crapssim.bet import compute_commission | ||
| @pytest.mark.parametrize( | ||
| ("rounding", "floor", "bet"), | ||
| [ | ||
| ("ceil_dollar", 0.0, 20.0), | ||
| ("nearest_dollar", 1.0, 20.0), | ||
| ("nearest_dollar", 1.0, 5.0), | ||
| ("none", 0.0, 12.5), | ||
| ], | ||
| ) | ||
| def test_commission_mode_parity(rounding, floor, bet): | ||
| table_on_bet = _StubTable( | ||
| settings={ | ||
| "commission_mode": "on_bet", | ||
| "commission_rounding": rounding, | ||
| "commission_floor": floor, | ||
| } | ||
| ) | ||
| table_on_win = _StubTable( | ||
| settings={ | ||
| "commission_mode": "on_win", | ||
| "commission_rounding": rounding, | ||
| "commission_floor": floor, | ||
| } | ||
| ) | ||
|
|
||
| on_bet = _compute_commission(table_on_bet, gross_win=bet * 20, bet_amount=bet) | ||
| on_win = _compute_commission(table_on_win, gross_win=bet * 0.5, bet_amount=bet) | ||
|
|
||
| def test_compute_commission_fixed_five_percent(): | ||
| assert compute_commission(100.0) == 5.0 | ||
| assert compute_commission(40.0) == 2.0 | ||
| assert math.isclose(compute_commission(12.34), 0.617, rel_tol=1e-9) | ||
| assert on_bet == pytest.approx(on_win, abs=1e-9) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commission_modeno longer affects fee calculationThe refactor reads
commission_modebut then unconditionally computes the fee asbet_amount * 0.05, explicitly discardinggross_win. As a result, the configuration toggle that previously chose between charging 5% of the wager ("on_bet") or 5% of the gross win ("on_win") no longer changes the fee amount—both settings now cost 5% of the bet regardless of the mode. This contradicts the README’s documented behavior forcommission_mode="on_win"(fee on the win amount) and will misprice commissions for lay bets where the win is smaller than the stake. Either reintroduce the mode-sensitive base calculation or remove/deprecate the setting so callers are not misled.Useful? React with 👍 / 👎.