Thousand Card Game: Improving code coverage #2

in #utopian-io8 years ago (edited)

image.png

What is this project about?

This contribution is made to gornanization/1k. If you would like to find more info - I strongly recommend reading this post first.

PR:

https://github.com/gornanization/1k/pull/26

Details

Lately, in "Improving code coverage #1" article we have covered process of registration player and dealing cards phase. Today I would like to present you unit test, which covers process of bidding. In order to reach bidding state, we have to walk through both registration & dealing cards phase. But, to test bidding, do we have to follow all of this steps? Nope, we don't. As I mentioned here, the project is designed in way allowing us to continue game from specific point.

But how can we prepare this "specific point"? Below you can see the whole game state object representing case, when we are in the very beginning of the bidding phase.

image.png

About settings I was writing a little bit here (for those who are interested in details). We have desired 'BIDDING_START' phase, already registered players and deck spread across players (cards) and stock (stock). createCards is an helper function, which returns specific number of random cards.

Wait, random? So there is possibility, that two players will have same card!?

That's true, but from bidding perspective we do not care what exactly cards do they have. What we have to assure is that the all players have 7 cards (+3 in stock). So let's go further...

As it's an early stage of bidding, we have bid array empty. It will be extended with a set of player's bid offerts during the BIDDING_IN_PROGRESS phase.

So what we do in our test is basically calling API methods, one by one:

thousand.pass('adam');
thousand.bid('alan', 120);
thousand.bid('adam', 130);
thousand.pass('pic');

and then we are checking what events have been emitted and what the result of this called actions is (whether they were performed or permitted). By doing so, I wan to cover the whole logic standing behind API client, starting with player registration and ending on game winner announcement.

And finally, coverage increased (+3.05%) to 90.396%.

All the best, dear players!



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

Hey @adasq I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

Sneaky Ninja Attack! You have been defended with a 5.20% vote... I was summoned by @adasq! I have done their bidding and now I will vanish...Whoosh

You got a 1.25% upvote from @upme requested by: @adasq.
Send at least 1 SBD to @upme with a post link in the memo field to receive upvote next round.
To support our activity, please vote for my master @suggeelson, as a STEEM Witness

Congratulations @adasq! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of comments received

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

By upvoting this notification, you can help all Steemit users. Learn how here!

Coin Marketplace

STEEM 0.05
TRX 0.32
JST 0.082
BTC 62816.13
ETH 1674.13
USDT 1.00
SBD 0.41