Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Adds cxxrandom unit test and fixes interface problems#2099

Merged
myk002 merged 13 commits into
DFHack:developfrom
cppcooper:cxxrandom
May 1, 2022
Merged

Adds cxxrandom unit test and fixes interface problems#2099
myk002 merged 13 commits into
DFHack:developfrom
cppcooper:cxxrandom

Conversation

@cppcooper

@cppcooper cppcooper commented Apr 15, 2022

Copy link
Copy Markdown
Contributor

Fixes a mistake in the bool_distribution and adds a unit test

Resolves #2098

Comment thread docs/Lua API.rst
Comment thread docs/changelog.txt Outdated
Comment thread test/plugins/cxxrandom.lua
@cppcooper

Copy link
Copy Markdown
Contributor Author

Resolves #2098

@myk002

myk002 commented Apr 19, 2022

Copy link
Copy Markdown
Member

Resolves #2098

This has to go in the description text in order for the referenced bug to get autoclosed

@cppcooper

Copy link
Copy Markdown
Contributor Author

Resolves #2098

This has to go in the description text in order for the referenced bug to get autoclosed

Oh oops. And I just closed the issue thinking this was merged. heh

@cppcooper

Copy link
Copy Markdown
Contributor Author

I added the new example in docs to the changelog, if there's anything else lmk

Comment thread plugins/lua/cxxrandom.lua Outdated
Comment thread plugins/cxxrandom.cpp Outdated
CHECK_INVALID_ARGUMENT( m_sequences.find( id ) != m_sequences.end() );
m_sequences[id].Shuffle( rng_id );
void Shuffle(uint16_t seqID, uint16_t engID ) {
uint16_t sid = seqID >= SK_ID_BASE ? seqID : engID;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fairly brittle. Since the ids are opaque to Lua, how about making them different types? Then you can figure out which is which by resolving the type sent to you from Lua.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The types are sent to lua, that's the only way lua users can get an id. I could use different integer types, but I don't see how lua would retain such information. I think I'd be better off just uptyping to 32 or 64 bits and increasing the bins for the two id types. If it is a problem that is, as is they have acess to several thousand ids which granted isn't a tonne of they just leave df open for a few months and were to regularly use RNG

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant wrap the ids in a type that has an _identity. Then you can use virtual_cast to figure out what you have

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a decent plan, no idea how to implement that though.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example:

static struct_identity _identity;

Comment thread plugins/lua/cxxrandom.lua Outdated
Comment thread plugins/cxxrandom.cpp Outdated
Comment thread plugins/lua/cxxrandom.lua
Comment thread test/plugins/cxxrandom.lua Outdated
Comment thread test/plugins/cxxrandom.lua
Comment thread test/plugins/cxxrandom.lua
Comment thread test/plugins/cxxrandom.lua
Comment thread test/plugins/cxxrandom.lua
Comment thread test/plugins/cxxrandom.lua Outdated

@myk002 myk002 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I'd still like to see the collision detection implemented for completeness, even though "it's never gonna happen". Not a deal breaker, though

Comment thread plugins/lua/cxxrandom.lua
@cppcooper

Copy link
Copy Markdown
Contributor Author

Looks good! I'd still like to see the collision detection implemented for completeness, even though "it's never gonna happen". Not a deal breaker, though

Well I wouldn't say never. Someone determined to make it happen could make it happen. But yea, practically speaking half of the 64 bit space is pretttty large

@myk002

myk002 commented Apr 30, 2022

Copy link
Copy Markdown
Member

Merge latest develop to fix the docs error - or don't : ) this will be fine once merged

@myk002 myk002 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests need unlooping, but otherwise looks good.

@cppcooper

cppcooper commented Apr 30, 2022

Copy link
Copy Markdown
Contributor Author

The tests need unlooping, but otherwise looks good.

The for loops? Why?

@myk002

myk002 commented Apr 30, 2022

Copy link
Copy Markdown
Member

The tests need unlooping, but otherwise looks good.

The for loops? Why?

The comment I left before on line 30 of the test file seems to be hidden for some reason. Let me rewrite it here:

I think it's fine to initialize the engine with a nil seed and don't loop here. Unit tests should not be looping. They should be light and fast.

Just test once. If it ever fails it will show up eventually.

@cppcooper

cppcooper commented Apr 30, 2022

Copy link
Copy Markdown
Contributor Author

Just test once. If it ever fails it will show up eventually.

How about like.. 10 times? instead of 10,000. As to shorten the "eventually"

@myk002

myk002 commented Apr 30, 2022

Copy link
Copy Markdown
Member

Just test once. If it ever fails it will show up eventually.

How about like.. 10 times? instead of 10,000. As to shorten the "eventually"

I think just once is fine, but if 10 times allows the test to pass in 1ms or less, then it's ok

@myk002

myk002 commented Apr 30, 2022

Copy link
Copy Markdown
Member

You can see how long each test takes to pass in the output for the test step in the automated GitHub-hosted builds (not the buildmaster ones)

Comment thread test/plugins/cxxrandom.lua Outdated
@myk002 myk002 merged commit fe29bff into DFHack:develop May 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unusable bool_distribution?

2 participants