Skip to content
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

Add setting for randomization. #336

Merged
merged 14 commits into from Oct 29, 2019

Conversation

@ksaaskil
Copy link
Contributor

ksaaskil commented Oct 28, 2019

  • Currently Unmock always sets the seed to a fixed value when generating a mock. For proper pseudo-random behaviour, add a randomize setting to not set the seed everytime.
  • Switching randomization on: unmock.randomize.on()
  • Disable: unmock.randomize.off()

TODO:

  • Tests
  • Completely based on mutable state: having RNG based on functional immutable state (á la fp-ts/lib/state.ts) would be awesome but I don't really see that fitting to the current architecture at the moment: We would need to change CreateResponse to return the modified state.
ksaaskil added 5 commits Oct 28, 2019
@codecov-io

This comment has been minimized.

Copy link

codecov-io commented Oct 28, 2019

Codecov Report

Merging #336 into dev will increase coverage by 0.52%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##              dev     #336      +/-   ##
==========================================
+ Coverage   80.05%   80.57%   +0.52%     
==========================================
  Files          49       50       +1     
  Lines        2226     2245      +19     
  Branches      569      572       +3     
==========================================
+ Hits         1782     1809      +27     
+ Misses        444      436       -8
Impacted Files Coverage Δ
packages/unmock-core/src/index.ts 83.92% <100%> (+1.78%) ⬆️
...ackages/unmock-core/src/random-number-generator.ts 100% <100%> (ø)
packages/unmock-core/src/generator.ts 87.64% <100%> (+0.04%) ⬆️
packages/unmock-core/src/settings/boolean.ts 100% <100%> (+75%) ⬆️
packages/unmock-core/src/settings/index.ts 100% <100%> (ø) ⬆️
packages/unmock-core/src/runner/index.ts 95% <100%> (ø) ⬆️
packages/unmock-core/src/backend/index.ts 89.28% <100%> (+0.39%) ⬆️
packages/unmock-core/src/settings/utils.ts 87.5% <0%> (+12.5%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f0b8fc1...728bf59. Read the comment docs.

ksaaskil added 6 commits Oct 28, 2019
@ksaaskil ksaaskil marked this pull request as ready for review Oct 28, 2019
@ksaaskil ksaaskil requested a review from idantene Oct 28, 2019
@ksaaskil

This comment has been minimized.

Copy link
Contributor Author

ksaaskil commented Oct 28, 2019

Let me actually move rng to Backend, I think it fits much better there...

Copy link
Contributor

idantene left a comment

lgtm 👍

serviceDefLoader,
}: IBackendOptions) {
this.interceptorFactory = interceptorFactory;
this.requestResponseListeners = listeners || [];
this.serviceDefLoader = serviceDefLoader || NoopServiceDefLoader;
this.randomNumberGenerator = rng || randomNumberGenerator({ seed: 0 });

This comment has been minimized.

Copy link
@idantene

idantene Oct 28, 2019

Contributor

({ seed: runnerConfiguration.defaultSeed })?
Or, ideally, define DEFAULT_SEED = 0 and then replace every 0 seed to that? 🤔

optionalsProbability: 1.0,
minItems: 0,
reset() {
this.defaultSeed = 0;

This comment has been minimized.

Copy link
@idantene

idantene Oct 28, 2019

Contributor

If we now use defaultSeed as an immutable instance, why do we need to reset it here?

@ksaaskil

This comment has been minimized.

Copy link
Contributor Author

ksaaskil commented Oct 29, 2019

Good points, I added rng.restore() to abstract the default seed away.

@ksaaskil ksaaskil merged commit b56e9f3 into dev Oct 29, 2019
2 checks passed
2 checks passed
ci/circleci: build Your tests passed on CircleCI!
Details
ci/circleci: verify-before-publish Your tests passed on CircleCI!
Details
@ksaaskil ksaaskil deleted the randomize branch Oct 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.