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

Update Unit Tests in PolarizationEffiency Cor #38458

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

yusufjimoh
Copy link
Contributor

Description of work

  • wrote unit tests to check that wildes method perform well when spinstates is added
  • wrote unit tests to check that fredrik method throws exception when tested with wildes-only properties spinstates and flippers
  • wrote unit tests to check that fredrikze method can take AddSpinStateToLog property
  • refactored unit tests for maintainability

Fixes #38287

To test:

  • review unit tests
  • ensure all unit tests pass

This does not require release notes because it involves updating the unit tests

- wrote unit tests to check that wildes method perform well when spinstates is added
- wrote unit tests to check that fredrik method throws exception when tested with wildes-only properties spinstates and flippers
- wrote unit tests to check that fredrikze method can take AddSpinStateToLog property
- refactored unit tests for maintainability
@yusufjimoh yusufjimoh linked an issue Nov 28, 2024 that may be closed by this pull request
2 tasks
@yusufjimoh yusufjimoh marked this pull request as ready for review December 4, 2024 09:14
@yusufjimoh yusufjimoh added ISIS Team: LSS Issue and pull requests managed by the LSS subteam at ISIS Maintenance Unassigned issues to be addressed in the next maintenance period. Reflectometry Issues and pull requests related to reflectometry labels Dec 4, 2024
@yusufjimoh yusufjimoh added this to the Release 6.12 milestone Dec 4, 2024
@rbauststfc rbauststfc assigned rbauststfc and unassigned rbauststfc Dec 5, 2024
Copy link
Contributor

@rbauststfc rbauststfc left a comment

Choose a reason for hiding this comment

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

The reduction in code duplication is already looking really good. I have a few suggestions for ways that we might be able to continue to build on this. It would also be really good to try and make more use of constants where we can too.

alg->setPropertyValue("SpinStatesOutWildes", "+, -");

try {
alg->execute();
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a really good idea to check the specific error message here. Looking at some examples in other tests, this syntax might be a nice way of simplifying this a bit:

TS_ASSERT_THROWS_EQUALS(alg->execute(), const std::invalid_argument &e,
                            std::string(e.what()), "Property SpinStatesOutWildes cannot be used with the Fredrikze method.");

try {
alg->execute();
} catch (const std::invalid_argument &e) {
TSM_ASSERT_EQUALS("Incorrect exception message.", std::string(e.what()),
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we make use of TS_ASSERT_THROWS_EQUALS here?

try {
alg->execute();
} catch (const std::invalid_argument &e) {
TSM_ASSERT_EQUALS("Incorrect exception message.", std::string(e.what()),
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we make use of TS_ASSERT_THROWS_EQUALS here?

alg.execute();
setAlgorithmProperties(alg, "points", "Wildes");
alg->setProperty("InputWorkspaces", inputs);
alg->execute();
WorkspaceGroup_sptr out = AnalysisDataService::Instance().retrieveWS<WorkspaceGroup>("out");
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we use the new checkWorkspaceGroupSize method here too?

alg.execute();
setAlgorithmProperties(alg, "points-short", "Wildes");
alg->setProperty("InputWorkspaces", inputs);
alg->execute();
WorkspaceGroup_sptr out = AnalysisDataService::Instance().retrieveWS<WorkspaceGroup>("out");
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we use the new checkWorkspaceGroupSize method here too?

void setAlgorithmProperties(const std::shared_ptr<PolarizationEfficiencyCor> &alg,
const std::string &efficiencyMethod, const std::string &method = "",
const std::string &analysisMethod = "") {
alg->setProperty("OutputWorkspace", "out");
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like we set the output workspace and efficiencies in every test, so instead of having this separate setAlgorithmProperties method, could we just move all the logic that is here into createAlgorithm?

}
}

void checkWorkspaceGroupSize(size_t expectedSize) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This method is checking the size of a specific workspace group (i.e. the one called "out"). Would it be worth renaming it so that it's called checkOutputWorkspaceGroupSize to make that clearer?

}

void checkWorkspaceGroupSize(size_t expectedSize) {
WorkspaceGroup_sptr out = AnalysisDataService::Instance().retrieveWS<WorkspaceGroup>("out");
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we define "out" as a constant i.e. const std::string OUTPUT_GRP_NAME{"out"};. We use the value in a couple of places, so it would be nice to have it defined in just one place if we can.

MatrixWorkspace_sptr createEfficiencies(std::string const &kind) {
static std::map<std::string, std::vector<std::string>> const labels = {{"Wildes", {"P1", "P2", "F1", "F2"}},
{"Fredrikze", {"Pp", "Ap", "Rho", "Alpha"}}};
if (kind == "Wildes" || kind == "Fredrikze") {
if (kind == WILDES_METHOD || kind == FREDRIKZE_METHOD) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It's really great for maintainability that we're using the constants here. There are quite a few places in these tests where we're using "Wildes" and "Fredrikze", so could we go through and replace all of those that we can with the constants?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ISIS Team: LSS Issue and pull requests managed by the LSS subteam at ISIS Maintenance Unassigned issues to be addressed in the next maintenance period. Reflectometry Issues and pull requests related to reflectometry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Maintenance tasks for PolarizationEfficiencyCor
2 participants