-
-
Notifications
You must be signed in to change notification settings - Fork 59
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
refactor: allow random to be mocked #93
Conversation
Signed-off-by: xlanor <contact@jingk.ai>
Signed-off-by: xlanor <contact@jingk.ai>
Signed-off-by: xlanor <contact@jingk.ai>
… rand.Int and rand.Intn Signed-off-by: xlanor <contact@jingk.ai>
Codecov Report
@@ Coverage Diff @@
## master #93 +/- ##
==========================================
- Coverage 96.31% 95.85% -0.47%
==========================================
Files 36 36
Lines 1085 1085
==========================================
- Hits 1045 1040 -5
- Misses 34 36 +2
- Partials 6 9 +3
Continue to review full report at Codecov.
|
I merged your previous PR @xlanor, can you rebase this one to resolve the conflicts? |
Will work on it by tonight, at work right now. Does the implementation look good so far? |
resolved conflicts. |
@jaswdr sending a ping here :) |
@xlanor sorry for the delay, there is a drop in coverage, can you check the "Files changes" tab to see the lines not covered? |
Will do this weekend, been a busy month for me. Cheers |
Signed-off-by: xlanor <contact@jingk.ai>
@jaswdr coverage increased, rerun ci with merge. Have a look at the test file to see how this can be used to essentially avoid the issue of decreasing coverage by mocking random (branch) logic. There may be a slight drop ocassionally - need to refactor the code further in branching logics to allow for all branching to be fully tested, but that's a little hard due to the dependency on generating alnums and Intn both relying on the seed generator. I suspect this is actually the case for dropping coverage across the board - it now reports a drop in coverage in I'll have a sleep on it and think about how to get it done. With regards to the test failing here, this is actually in an unrelated file to mine and appears to be flaking.
This tests expects a non-0 number We can see that it calls
This will flake because currencies Numbers contains a 0 which will randomly appear Im not exactly sure whats the purpose of that test, could you look at it please? |
Looking, those tests are clearly wrong, I'll fix them in another PR. |
Description
This uses an interface of
GeneratorInterface
type that implementsIntn
andInt
(previously used directly from therand
package.By doing this, we can now reliably mock
rand
by inserting expected values to test certain logic flows which may not have been fully covered.This includes changes that are in the existing ethereum PR (#91) as I wrote the sample test code based on a method that was renamed in that PR.
If this style is approved I will push somemore commits to explicitly test the logic flow for RandomBitcoin
Are you trying to fix an existing issue?
#92
Go Version
Go Tests