Skip to content

Fix Issue #15#28

Open
DylanFrese wants to merge 8 commits intovikram7:masterfrom
DylanFrese:master
Open

Fix Issue #15#28
DylanFrese wants to merge 8 commits intovikram7:masterfrom
DylanFrese:master

Conversation

@DylanFrese
Copy link

This fixes issue #15, where users could input the target answer and be marked correct. This solution tests the user's solution against various data structures for which it should fail, such as empty arrays, nil, and the provided data structure with all instances of the target answer removed. If the user's solution does not fail for each of these tests, it almost certainly means the user's answer is not a function of the provided data structure.

Personally, I think this is a design problem rather than a technical problem. Trying to pull a single piece of known data from a known set of data is not a very engaging task; it would be more interesting and 'like-coding' to have the user map 'every name to their phone number' or 'find the sum of any array', without knowing the exact data before hand.

Game#run_test is a method that takes in the current data structure, the
routine given by the player, and the target answer, and returns whether
the target answer matches the output from the routine, or false if there
was an exception.
Game#tests creates an array of values for which any answer given by the
player should fail. These include nil, a newly created array, and a new
random data structure.
deep_delete deletes a target element from a data structure, even if that
element is nested inside multiple data structures.

Perhaps this should be moved, as it is not really a game-related method;
but I am not sure to where.
Added a test that uses deep_delete on the given data structure and
target. Users' input should not remain correct when the target is
removed from the given data structure.
4-wide indentations were retabbed to be 2-wide, to match the rest of the
file (sorry!).
run_test now takes the user input, and creates the proc in its method
body, so the resulting closure encloses the correct values.
test_answer tests the given user input against tests generated by
Game#tests. The tests generated by Game#tests are data structures that
no user input should return the target for (empty arrays, nil, etc.).
test_answer returns true only if the user input fails for each of the
tests.
Game#play_round will now call Game#cheater if test_answer fails. The
cheater method prints out a short message about accessing the data
structure.
Copy link
Collaborator

Choose a reason for hiding this comment

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

The use of eval is a serious security risk.

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.

2 participants