-
Notifications
You must be signed in to change notification settings - Fork 6
feat: HitTheZone #9
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 8 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
31a7f31
add: adding the realm HitTheZone
Nezketsu 41b4c40
add: add some test to my realm
Nezketsu bcf2234
add: add TrustFactor realm
Nezketsu 725b171
add: add TrustFactor realm
Nezketsu 478298e
fix: remove Trust factor
Nezketsu 7d8f21e
add: add TrustFactor realm
Nezketsu 4a9fa29
refactor: improve code quality per PR review feedback
Nezketsu 31e9dfb
rm: remove hitthezone realm
Nezketsu 5bb5167
Merge branch 'main' into main
leohhhn 85ea0ea
fix: fix fmt CI/CD error
Nezketsu 3281410
fix: remove std usage
Nezketsu d28e352
Merge branch 'main' into main
Nezketsu 1d8926b
fix: function name and godoc
Nezketsu 5ff6c63
Merge branch 'main' of github.com:Nezketsu/community
Nezketsu d3489df
fix: remove bad comment and fix function organization
Nezketsu 08a1ecc
fix: fix fmt
Nezketsu 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| module = "gno.land/r/greg007/hitthezone" | ||
| gno = "0.9" |
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 |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| package hitthezone | ||
|
|
||
| import ( | ||
| "std" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestCalculateMultiplier(t *testing.T) { | ||
| // Test full range (1-100) | ||
| result := CalculateMultiplier(1, 100) | ||
| expected := 1.0 | ||
| if result != expected { | ||
| t.Errorf("CalculateMultiplier(1, 100) = %f; want %f", result, expected) | ||
| } | ||
|
|
||
| // Test single number (50-50) | ||
| result = CalculateMultiplier(50, 50) | ||
| expected = 100.0 | ||
| if result != expected { | ||
| t.Errorf("CalculateMultiplier(50, 50) = %f; want %f", result, expected) | ||
| } | ||
|
|
||
| // Test invalid range (min >= max) | ||
| result = CalculateMultiplier(60, 50) | ||
| expected = 0.0 | ||
| if result != expected { | ||
| t.Errorf("CalculateMultiplier(60, 50) = %f; want %f", result, expected) | ||
| } | ||
| } | ||
|
|
||
| func TestGenerateRandom(t *testing.T) { | ||
| // Test that generateRandom produces numbers in valid range | ||
| for i := 0; i < 10; i++ { | ||
| generateRandom() | ||
| if lastRandomNumber < 1 || lastRandomNumber > 100 { | ||
| t.Errorf("generateRandom() produced %d, should be between 1-100", lastRandomNumber) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func TestPlayGame(t *testing.T) { | ||
| // Test with full range - should always win | ||
| won := playGame(1, 100) | ||
| if !won { | ||
| t.Error("playGame(1, 100) should always win") | ||
| } | ||
|
|
||
| // Test with impossible single number multiple times | ||
| wins := 0 | ||
| for i := 0; i < 20; i++ { | ||
| if playGame(50, 50) { | ||
| wins++ | ||
| } | ||
| } | ||
| // We expect some wins but not necessarily all | ||
| } | ||
|
|
||
| func TestHandlePayoutWin(t *testing.T) { | ||
| // Test win scenario logic (without actual coin transfers) | ||
| // In test environment, we can't test actual payouts due to banker restrictions | ||
| // This test verifies the handlePayout returns expected result for win condition | ||
| testAddr := std.Address("g1test") | ||
| betAmount := int64(1000) | ||
| multiplier := 2.0 | ||
|
|
||
| // Test with won=true - will attempt payout but likely fail due to no funds in test env | ||
| result, _ := handlePayout(true, betAmount, multiplier, testAddr) | ||
|
|
||
| // In test environment, this will likely return one of the error states | ||
| // due to lack of realm funds, which is expected behavior | ||
| validResults := []string{ | ||
| "Win", | ||
| "Win (Payment failed - refunded)", | ||
| "Win (Insufficient funds - refunded)", | ||
| "Win (House broke - no payout)", | ||
| } | ||
|
|
||
| found := false | ||
| for _, valid := range validResults { | ||
| if result == valid { | ||
| found = true | ||
| break | ||
| } | ||
| } | ||
|
|
||
| if !found { | ||
| t.Errorf("handlePayout(won=true) result = %s; expected one of the valid win results", result) | ||
| } | ||
| } | ||
|
|
||
| func TestHandlePayoutLose(t *testing.T) { | ||
| // Test loss scenario | ||
| testAddr := std.Address("g1test") | ||
| betAmount := int64(1000) | ||
| multiplier := 2.0 | ||
|
|
||
| result, amount := handlePayout(false, betAmount, multiplier, testAddr) | ||
|
|
||
| if result != "Lose" { | ||
| t.Errorf("handlePayout(won=false) result = %s; want 'Lose'", result) | ||
| } | ||
|
|
||
| if amount != 0 { | ||
| t.Errorf("handlePayout(won=false) amount = %d; want 0", amount) | ||
| } | ||
| } | ||
|
|
||
| func TestValidateGameInputs(t *testing.T) { | ||
| // Test min < 1 | ||
| defer func() { | ||
| if r := recover(); r == nil { | ||
| t.Error("validateGameInputs should panic when min < 1") | ||
| } | ||
| }() | ||
| validateGameInputs(0, 50) | ||
| } | ||
|
|
||
| func TestValidateGameInputsMaxTooHigh(t *testing.T) { | ||
| // Test max > 100 | ||
| defer func() { | ||
| if r := recover(); r == nil { | ||
| t.Error("validateGameInputs should panic when max > 100") | ||
| } | ||
| }() | ||
| validateGameInputs(1, 101) | ||
| } | ||
|
|
||
| func TestValidateGameInputsMinGreaterThanMax(t *testing.T) { | ||
| // Test min >= max | ||
| defer func() { | ||
| if r := recover(); r == nil { | ||
| t.Error("validateGameInputs should panic when min >= max") | ||
| } | ||
| }() | ||
| validateGameInputs(60, 50) | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.