-
Notifications
You must be signed in to change notification settings - Fork 169
Add generator for existing atoms #310
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1398,6 +1398,20 @@ sampleshrink_test_() -> | |
?_shrinksTo([a], Gen)}, | ||
?_test(proper_gen:sampleshrink(Gen))]}]. | ||
|
||
existing_atom_test() -> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's very unclear what these tests really test and what their underlying assumptions are. Also, it's unclear why the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right, the tests are brittle, meant as a first attempt =( Executing PropEr tests in parallel is likely to break them. In fact, anything else that may be going on in the system may break them.
The I'm at a loss about what to do about this, or rather how to test it PropErly. Thankful for advice 🤷♀️ |
||
_ = proper_gen:pick(proper_types:existing_atom()), | ||
N = erlang:system_info(atom_count), | ||
{ok, Atom} = proper_gen:pick(proper_types:existing_atom()), | ||
?assert(erlang:is_atom(Atom)), | ||
?assertEqual(N, erlang:system_info(atom_count)). | ||
|
||
default_atom_test() -> | ||
_ = proper:quickcheck(?FORALL(_, any(), true), | ||
[1, {default_atom_generator, existing_atom}]), | ||
N = erlang:system_info(atom_count), | ||
?assert(proper:quickcheck(?FORALL(_, any(), true), | ||
[{default_atom_generator, existing_atom}])), | ||
?assertEqual(N, erlang:system_info(atom_count)). | ||
|
||
%%------------------------------------------------------------------------------ | ||
%% Performance tests | ||
|
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.
These two functions, and the PR in general, should describe the main idea of the existing atom generation algorithm and the assumptions it relies on. Also its limitations.
Having written that, if I understand what the
existing_atom_gen()
does, it is in fact not an atom generator (in the sense thatproper_gen:atom_gen/1
is), but it simply returns a random atom from those (currently) loaded in the atom table, which it stores in its own map, right?Since there is a magic way (the
<<131, 75, Index:24>>
trick) to access each of these atoms given anIndex
, and the upper limit of this index is known ( it is given byerlang:system_info(atom_count)
), what is the point of first iterating through all these atoms putting them in an internal map, rather than randomly picking oneIndex
in the range and returning the corresponding atom? (Perhaps after anum_tries
if this process is unlucky to only end up in atoms starting with$
.) What I am missing?Incidentally, I do not like the magic constants 131, 75 and 24. They should be made appropriate defines and ideally obtained by the Erlang/OTP system somehow.
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.
That is correct, yes. "Find all existing atoms, (store them in the map,) pick one at random". The term "generator" is probably not the exact term to use here (I guess this is you objection?), but what is the correct term to use?
Nothing I think ;) That is a great suggestion, I'll do that. How about we use a fallback atom like
''
to return if all tries turn up atoms starting with$
? We need to return something, right?