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 tests to check missionsCompleted7Days value is in required range #31

Closed
10 tasks
cg-cnu opened this issue Aug 23, 2017 · 22 comments
Closed
10 tasks

add tests to check missionsCompleted7Days value is in required range #31

cg-cnu opened this issue Aug 23, 2017 · 22 comments

Comments

@cg-cnu
Copy link
Contributor

cg-cnu commented Aug 23, 2017

first-timers-only

This issue is tagged :octocat: first-timers-only. It is only for people who have never contributed to open source before, and are looking for an easy way take their first steps.

Consider this your chance to dip your toe into the world of open-source, and get some bragging rights for writing code that makes drones fly, lets cars find charging stations, helps people and goods get from place to place, and more.

Find more first-timers-only issues here:

Thank you for your help ❤️

What is this project?

DAV (Decentralized Autonomous Vehicles) is a new foundation working to build an open-source infrastructure for autonomous vehicles (cars, drones, trucks, robots, and all the service providers around them) to communicate and transact with each other over blockchain.

As an organization that believes in building a large community of open-source contributors, we often create issues like this one to help people take their first few steps into the world of open source.

Mission Control

The DAV project you are looking at is Mission Control. It is the brain in charge of orchestrating missions between DAV users and autonomous vehicles.

How you can help

Background

To help developers building on top of DAV technologies, Mission Control can start in a simulation environment. In a simulation environment, there are always a few simulated drones flying around the user, ready to take on missions. This makes it easy for developers to start building and testing without investing in hardware.

The Issue

As a project that relies on a large community of contributors, it is very important for us to have good tests to make sure changes don't break anything.

One of the functions that need testing is randomMissionsCompleted() inside /server/simulation/random.js that creates random number of missionsCompleted and missionsCompleted7Days.

The task for this issue is to test the functions return value.

  • missionsCompleted7Days should be a positive integer that is less than or equal to the value of missionsCompleted

Edit test/specs/simulation.random.spec.js, adding a describe block for randomMissionsCompleted() if it does not exists and within it one test that verify the condition mentioned above.

To run your tests, run npm test from the project's root directory. All tests should pass.

tests

Contributing to Mission Control

  • Fork the repository from the Mission Control GitHub page.
  • Clone a copy to your local machine with $ git clone git@github.com:YOUR-GITHUB-USER-NAME/missioncontrol.git
  • Make sure you have node.js and npm installed on your machine. You can use this guide for help.
  • Install all of the project's dependencies with npm. $ cd missioncontrol; npm install
  • Run npm test to run linting checks and all the automated tests and see that they pass.
  • Code! code! code!
  • Before committing your code, run npm test one last time and make sure no errors (including linting errors) are thrown.
  • Once you've made sure all your changes work correctly and committed all your changes, push your local changes back to github with $ git push -u origin master
  • Visit your fork on GitHub.com (https://github.com/YOUR-USER-NAME/missioncontrol) and create a pull request for your changes.
  • Make sure your pull request describes exactly what you changed and references this issue (include the issue number in the title like this: #30)
@TalAter
Copy link
Member

TalAter commented Aug 23, 2017

This issue is still available for first-time contributors

The commits listed above and just below this message are for a different issue

malltshik pushed a commit to malltshik/missioncontrol that referenced this issue Aug 24, 2017
…(testing randomMissionsCompleted function)
@sblasa
Copy link

sblasa commented Sep 1, 2017

@TalAter @cg-cnu Hi, I would like to try help with this one if that's okay.

@TalAter
Copy link
Member

TalAter commented Sep 1, 2017

Go for it @sblasa!

Thank you 🙇

@sblasa
Copy link

sblasa commented Sep 3, 2017

@TalAter Thanks! 😄

@TalAter
Copy link
Member

TalAter commented Sep 12, 2017

Hey @sblasa, how is it going with this one? Do you need any help with it?

@sblasa
Copy link

sblasa commented Sep 13, 2017

@TalAter Hi! Sorry, got busy with work. Starting on it today. Thanks for the reminder! :)

@sblasa
Copy link

sblasa commented Sep 13, 2017

@TalAter I'm getting this error when I run the npm test. I followed directions noted above description.

C:\Users\stbla\code_school\opensource\missioncontrol [master ≡ +0 ~2 -0 !]> npm test

missioncontrol@0.0.1 test C:\Users\stbla\code_school\opensource\missioncontrol
gulp jest

[08:12:49] Using gulpfile ~\code_school\opensource\missioncontrol\gulpfile.js
[08:12:49] Starting 'jest'...
C:\Users\stbla\code_school\opensource\missioncontrol\node_modules\jest-haste-map\build\crawlers\node.js:36
names.forEach(file => {
^

TypeError: Cannot read property 'forEach' of undefined
at fs.readdir (C:\Users\stbla\code_school\opensource\missioncontrol\node_modules\jest-haste-map\build\crawlers\node.js:36:12)
at go$readdir$cb (C:\Users\stbla\code_school\opensource\missioncontrol\node_modules\jest-cli\node_modules\graceful-fs\graceful-fs.js:149:14)
at FSReqWrap.oncomplete (fs.js:135:15)
npm ERR! Test failed. See above for more details.

@TalAter
Copy link
Member

TalAter commented Sep 13, 2017

Hmmm. I cannot reproduce this on my machine and there is nothing specific about Mission Control code in the error.

My guess would be it has something to do with the script trying to access the filesystem in an environment that isn't unix-like.

Are you using the standard/old school command shell of Windows? If you are using Windows 10, I would try using the new bash-like shell they offer. If you are in an older version I know I used to use cygwin back in my Windows days, but there may be better solutions these days.

I know this may seem like a lot of hoops to jump for just to send a PR for this project, but I think it is worth it because this has far reaching consequences for most open source projects you'll work with.

@sblasa
Copy link

sblasa commented Sep 14, 2017

@TalAter Hi, yes, I tried using Git Bash, and that didn't work as well. I'm going to redo the repo on my machine and run it again. I will keep trying! :) Thanks!

@sblasa
Copy link

sblasa commented Sep 16, 2017

@TalAter Hi, I figured out that I needed to do a pull from the original repo and merge it with my project. I had noticed that there were some file changes in the original missioncontrol that I didn't have. It's working now. Moving on to fix the issue at hand. :)

@sblasa
Copy link

sblasa commented Sep 25, 2017

@TalAter , so I'm looking at the est/specs/simulation.random.spec.js . There is a describe block in there already, but I needed some help. I added the test in bold below and it passed. However, I need to add a test to see if the missionsCompleted7Days is a positive integer. Could you tell me how I could add that to the test?

Thanks!

describe('randomMissionsCompleted()', () => {

test('returns an object', () => {
expect(
typeof randomMissionsCompleted()
).toBe('object');
});

test('returns an object containing missionsCompleted7Days which is less than or equal to missionsCompleted', () => {
expect(
randomMissionsCompleted().missionsCompleted7Days
).toBeLessThanOrEqual(randomMissionsCompleted().missionsCompleted);
});

test('returns an object containing missionsCompleted which is an integer between 4 and 90', () => {
expect(
Number.isInteger(randomMissionsCompleted().missionsCompleted)
).toBeTruthy();
expect(
randomMissionsCompleted().missionsCompleted
).toBeLessThanOrEqual(90);
expect(
randomMissionsCompleted().missionsCompleted
).toBeGreaterThanOrEqual(4);
});

});

@Rob-Rychs
Copy link
Contributor

Hey @sblasa,
Maybe try something like .toBeGreaterThan(0) ?
That will at least check to make sure it's a positive number, if not a whole number which I'm not sure is necessary to test for
https://facebook.github.io/jest/docs/en/expect.html#tobegreaterthannumber
Just my thoughts...
😃

@TalAter
Copy link
Member

TalAter commented Sep 25, 2017

Thanks @Rob-Rychs

@sblasa does that answer your question?

GitHub Pro Tip #3704: When entering code in these GitHub issues, it is best to use markdown to make it easier to read... You even get syntax highlighting for free with it:

Just surround your code with some backticks like so:

describe('randomMissionsCompleted()', () => {

  test('returns an object', () => {
    expect(
      typeof randomMissionsCompleted()
    ).toBe('object');
  });

});

add_tests_to_check_missionscompleted7days_value_is_in_required_range_ _issue__31_ _davfoundation_missioncontrol

@sblasa
Copy link

sblasa commented Sep 25, 2017

@TalAter Ah, thanks for the tip! I was wondering how I would do that. 👍 I'm going to try out the code that Rob-Rychs mentioned.
@Rob-Rychs thank you for your help! I will try that and see if it works. 👍

@sblasa
Copy link

sblasa commented Sep 27, 2017

@TalAter The code passed when I ran the test. I added this code

test('returns an object containing missionsCompleted7Days which is less than or equal to missionsCompleted', () => {
      expect(
        randomMissionsCompleted().missionsCompleted7Days
      ).toBeLessThanOrEqual(randomMissionsCompleted().missionsCompleted);
  
  });

  test('returns an object containing missionsCompleted7Days which is an integer', () => {      
      expect(
        Number.isInteger(randomMissionsCompleted().missionsCompleted7Days)
      ).toBeTruthy();     
  
  });

  test('returns an object containing missionsCompleted7Days which is a positive number', () => {     
      expect(
        randomMissionsCompleted().missionsCompleted7Days
      ).toBeGreaterThan(0);

  });

What do you think? Thanks for your help!

@TalAter
Copy link
Member

TalAter commented Sep 27, 2017

  • The following is just a stylistic choice, but I think we should stick to the same format of test someone has already written for missionsCompleted (https://github.com/DAVFoundation/missioncontrol/blob/master/test/specs/simulation.random.spec.js#L43), which is to include all of them in one test that asserts that "missionsCompleted7Days should be a positive integer that is less than or equal to the value of missionsCompleted".

  • I would replace the condition toBeTruthy() with a more strict toBe(true). toBeTruthy would pass on anything that is truthy (e.g. true, 17.3, "Esmarelda Villalobos"). This shouldn't be a problem here, since Number.isInteger always returns a boolean... but why not be more strict when we can? 😃

  • Your first test might fail from time to time because you are calling randomMissionsCompleted() twice. We want to verify that each time we call it, it will contain a missionsCompleted7Days that is smaller than the missionsCompleted it returned this time. But since you call it twice, you might get {missionsCompleted7Days: 2, missionsCompleted: 4} the first time you call it, and {missionsCompleted7Days: 10, missionsCompleted: 100} the second time which would fail your test (10 < 4) even though it satisfied the requirement we want to test (10 < 100)

@Rob-Rychs
Copy link
Contributor

Good stuff @sblasa @TalAter
If we store the original call to missionsCompleted() and then run the test using the properties from the stored call that might help prevent the issue with it failing from time to time...
something like...

test('returns an object containing missionsCompleted7Days which is less than or equal to missionsCompleted', () => {
   const prop = randomMissionsCompleted();
   expect(
     prop.missionsCompleted7Days
   ).toBeLessThanOrEqual(prop.missionsCompleted);

 }); `

@sblasa
Copy link

sblasa commented Sep 28, 2017

@TalAter thanks! Those are good points. I will change the format of that and change the conditions. @Rob-Rychs, that sounds like a good idea. I will try that too. Thank you you both for being very supportive. :) I will implement this tonight.

JordanShaak added a commit to JordanShaak/missioncontrol that referenced this issue Oct 4, 2017
…less than or

equal to missionsCompleted test
@TalAter
Copy link
Member

TalAter commented Oct 8, 2017

@sblasa Are you still interested in working on this issue? We have received another pull request for it by @JordanShaak

@sblasa
Copy link

sblasa commented Oct 8, 2017

@TalAter @Rob-Rychs Yes, I finished the update yesterday, and I was just going back through steps on Pull Request. I am submitting the pull request. Thanks! :)

TalAter added a commit that referenced this issue Oct 9, 2017
Issue #31 add tests to check missionsCompleted7Days value is in required range Issue
@TalAter
Copy link
Member

TalAter commented Oct 9, 2017

🎊 Just merged it. Awesome!

Congratulations on being an open sourcerer, and thank you so much for taking the time to help build the project!

@TalAter TalAter closed this as completed Oct 9, 2017
@sblasa
Copy link

sblasa commented Oct 9, 2017

@TalAter @Rob-Rychs Thanks for all your help! I'll keep an eye out for any other issues that I can help with. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants