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

Refactor cmontecarlo tests for exercising parametrization. #530

Merged
merged 10 commits into from Apr 11, 2016

Conversation

kdexd
Copy link

@kdexd kdexd commented Mar 27, 2016

Current design procedure of tests:

  • CMontecarlo methods are compiled into montecarlo.so (shared object)
  • Corresponding tests are compiled into test_montecarlo.so.
  • For testing these using pytest framework, test_montecarlo.so is wrapped and C tests are exposed to test_cmontecarlo.py using Python ctypes library.

This PR refactors the current tests such that:

  • They directly wrap montecarlo.so and expose the C methods and struct parameters to Python instead of C tests.
  • Pytest's parametrization can be used to test the methods extensively.
  • Parameters of each Python test method are the ones which are used by the corresponding C method.
  • RPacket and StorageModel structs are defined inside the test every time, using those parameters.

@kdexd
Copy link
Author

kdexd commented Mar 27, 2016

Related Issues: #249 #408

@kdexd kdexd force-pushed the test-cmontecarlo branch 4 times, most recently from d78b547 to 0a0c9a1 Compare March 30, 2016 03:07
tests = CDLL(test_path)

cmontecarlo_filepath = os.path.join(path[0], 'montecarlo', 'montecarlo.so')
cmontecarlo_methods = CDLL(cmontecarlo_filepath)
Copy link
Contributor

Choose a reason for hiding this comment

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

The loading of the CDLL is something specific to the tests, this shouldn't be in struct.py, only the definition of RPacket and StorageModel

Copy link
Author

Choose a reason for hiding this comment

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

Okay, I will move it to test_cmontecarlo.py

@kdexd kdexd force-pushed the test-cmontecarlo branch 2 times, most recently from d47d35a to b01ce9d Compare March 31, 2016 09:27
@kdexd
Copy link
Author

kdexd commented Mar 31, 2016

Rebasing upon merge of #514 caused failing of tests. Tests have to be rectified.

({'virtual_packet': 1}, {'cont_status': 0}, {'chi_cont': 6.652486e-16, 'd_cont': 1e+99}),
({'virtual_packet': 1}, {'cont_status': 1}, {'chi_cont': 6.652486e-16, 'd_cont': 1e+99})]
)
def test_compute_distance2continuum(packet_params, model_params, expected_params, packet, model):
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for writing a test for that method. Currently continuum interaction is a feature in development. I'd say it is safe for now to only test cont_status=0. @chvogl Is there any reason to test cont_status=1 in the current master?

Copy link
Author

Choose a reason for hiding this comment

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

Okay, I will remove the two test cases having cont_status=1

Copy link
Contributor

Choose a reason for hiding this comment

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

@yeganer There is no reason to test cont_status=1 in the current master.

@kdexd kdexd force-pushed the test-cmontecarlo branch 10 times, most recently from d705e2e to 17a06a8 Compare April 3, 2016 11:36
# TODO: Add scientifically sound test cases.
[({'virtual_packet': 1, 'tau_event': 2.9e13, 'last_line': 0},
{'tau_event': 2.9e13, 'next_line_id': 2}),

Copy link
Author

Choose a reason for hiding this comment

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

@yeganer I am just dealing with numbers.

@kdexd kdexd force-pushed the test-cmontecarlo branch 6 times, most recently from 68bb193 to 0c1b2a4 Compare April 5, 2016 17:21
karandesai-96 added 8 commits April 7, 2016 13:41
- C structs in rpacket.h, storage.h and rk_mt.h
  have been replicated in struct.py as per the
  design technique while using C types. These
  structs will now be used to pass in wrapped C
  methods.
- Three fixtures, each for rpacket, storage model
  and mt_state were added in test_cmontecarlo.py

- These fixtures have the same declaration as it
  was in init methods of corresponding C tests.
- These methods were refactored as per design
  procedure of test_distance2boundary:
    - test_distance2line
    - test_distance2continuum
@kdexd kdexd changed the title Refactor unit tests for cmontecarlo for exercising parametrization. Refactor cmontecarlo tests for exercising parametrization. Apr 10, 2016
@wkerzendorf
Copy link
Member

@yeganer - how is this PR review coming along?

'status': 0,
'id': 0
}
return RPacket(**packet_default)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer writing RPacket({ ...}) and removing the variable packet_defaul. That would look cleaner to me.

Copy link
Author

Choose a reason for hiding this comment

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

  • Done.

@wkerzendorf
Copy link
Member

@karandesai-96 nice work on adding some documentation to the beginning of the file.
@yeganer I'm signing off - if you're happy merge away.

doppler_factor = 0.9998556693818854
tests.test_rpacket_doppler_factor.restype = c_double
assert_almost_equal(tests.test_rpacket_doppler_factor(),
doppler_factor)

@pytest.mark.skipif(True, reason='Bad test design')
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd move this function blow the new tests. That way we have new & old nicely grouped together.

Copy link
Author

Choose a reason for hiding this comment

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

  • Done.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was talking about test_move_packet. Sorry for not being clear.

Copy link
Author

Choose a reason for hiding this comment

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

Ah, I misunderstood it as "Move test_rpacket_doppler_factor below to group old and new tests nicely in diffs" 😄

  • Done.

- Declare kwargs in fixtures directly instead of
  passing a dict as kwargs.

- Move test_move_packet to group new/ old tests.
@yeganer yeganer merged commit 5ddca21 into tardis-sn:master Apr 11, 2016
@kdexd kdexd deleted the test-cmontecarlo branch April 12, 2016 06:48
unoebauer added a commit that referenced this pull request May 10, 2016
Continue cmontecarlo tests refactor. Extend #530.
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.

None yet

4 participants