-
Notifications
You must be signed in to change notification settings - Fork 169
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
Added Distance unit tests #585
Conversation
} | ||
|
||
|
||
TEST(DistanceTests, MetersConstructor) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure if using parameters would make things nicer here. My only idea would be to use a Qlist of QLists where each QList element is made up of Distance::<unit_type> and every value the original distance gets converted to in all units. Each test has the conversions in different orders, so each test would need a different ordered list.
isis/tests/DistanceTests.cpp
Outdated
} | ||
|
||
|
||
//should we do all units? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we have checked above that we can convert other units to miles, and each "mathy" test converts all units into miles before calculating, is it safe to say that we don't need to test every combination of units in the tests below? I just used meters for everything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems okay to me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There are two helper methods, distance() and setDistance(), that are used in the constructor and the getters. I skipped testing these, but there are exceptions that can be thrown if we actually call either one of these methods directly. Is it worth testing these methods? |
isis/tests/DistanceTests.cpp
Outdated
TEST(DistanceTests, LessThanNull) { | ||
try { | ||
bool value = Distance() < Distance(); | ||
ASSERT_TRUE(value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this ASSERT_TRUE for if the comparison in the above line is supposed to throw an exception?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, this should be removed. We shouldn't be testing what that expression outputs because it throws an exception. If we are throwing an exception we should not also be honoring a specific return value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot to make a comment about that when writing the test. The only reason why I instantiate a bool and use ASSERT_TRUE is so we do not get a build warning saying that it is unused. I would not have put it in otherwise. Would it be better to take it out and have the build warning?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can just remove the assignment and throw away the result of the comparison.
try {
Distance() < Distance();
FAIL() << "Failure Message";
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is what I did at first and I get an "unused comparison" warning. We could turn this type of warning off.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh! This is fine then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kdl222 If you want to test the exceptions thrown by setDistance()
, you could call the Distance::Distance(double distance, Units distanceUnit)
constructor with some kind of invalid units. It looks to me like you are already testing the "negative distance" case. I don't think there's a need to test setDistance()
more directly, given how it is used. I don't think you need to test distance()
any more unless you'd like to add an exception test, as it is already being tested via other functions.
One more comment -- since the values used are doubles, could you use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think better numbers for the test can result in a better test. There is also a weird inconsistency between using EXPECT and ASSERT. You also should be using EXPECT_DOUBLE_EQ instead of EXPECT_FLOAT_EQ.
isis/tests/DistanceTests.cpp
Outdated
Distance dist(1500500, Distance::Meters); | ||
EXPECT_EQ(dist.meters(), 1500500); | ||
EXPECT_FLOAT_EQ(dist.kilometers(), 1500.5); | ||
EXPECT_FLOAT_EQ(dist.solarRadii(), 0.002155922); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use EXPECT_DBL_EQ for these comparisons. For the solar radii test, use the actual calculation for the comparison 1500500 / 6.9599e8
. Whenever comparing double values, try to avoid comparing against literals that are not 100% exact.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my other comment and use 1 solar radii = 6.9599e8 meters = 6.9599e5 km = 6.9599e8 pixels (with 1m per pixel) because all of the math will work out exactly.
isis/tests/DistanceTests.cpp
Outdated
Distance dist(1500.5, Distance::Kilometers); | ||
EXPECT_FLOAT_EQ(dist.kilometers(), 1500.5); | ||
EXPECT_EQ(dist.meters(), 1500500); | ||
EXPECT_FLOAT_EQ(dist.solarRadii(), 0.002155922); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, use the exact value to compare against.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my other comment and use 1 solar radii = 6.9599e8 meters = 6.9599e5 km = 6.9599e8 pixels (with 1m per pixel) because all of the math will work out exactly.
isis/tests/DistanceTests.cpp
Outdated
EXPECT_FLOAT_EQ(dist.solarRadii(), 0.002155922); | ||
EXPECT_FLOAT_EQ(dist.meters(), 1.5005e+06); | ||
EXPECT_FLOAT_EQ(dist.kilometers(), 1500.5); | ||
EXPECT_FLOAT_EQ(dist.pixels(1), 1.5005e+06); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this, you should use something simple like 1 solar radii. That will make all of the numbers exact. 1 solar radii = 6.9599e8 meters = 6.9599e5 km = 6.9599e8 pixels (with 1m per pixel).
EXPECT_EQ(dist.meters(), 1500500); | ||
EXPECT_FLOAT_EQ(dist.kilometers(), 1500.5); | ||
EXPECT_FLOAT_EQ(dist.solarRadii(), 0.002155922); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my other comment and use 1 solar radii = 6.9599e8 meters = 6.9599e5 km = 6.9599e8 pixels (with 1m per pixel) because all of the math will work out exactly.
isis/tests/DistanceTests.cpp
Outdated
EXPECT_EQ(dist.pixels(2), 1500500); | ||
EXPECT_EQ(dist.meters(), 750250); | ||
EXPECT_FLOAT_EQ(dist.kilometers(), 750.25); | ||
EXPECT_FLOAT_EQ(dist.solarRadii(), 0.0010779609); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my other comment and use 1 solar radii = 6.9599e8 meters = 6.9599e5 km = 1.39198e9 pixels (with 2m per pixel) because all of the math will work out exactly.
isis/tests/DistanceTests.cpp
Outdated
TEST(DistanceTests, CopyConstructor) { | ||
Distance origDist(1500.5, Distance::Meters); | ||
Distance copiedDist(origDist); | ||
ASSERT_FLOAT_EQ(copiedDist.meters(), 1500.5); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be ASSERT_EQ or EXPECT_EQ
isis/tests/DistanceTests.cpp
Outdated
// TEST(DistanceTests, ToString) { | ||
// Distance dist(1500500, Distance::Meters); | ||
// ASSERT_EQ(dist.toString(), "1500500 meters"); | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this untested?
isis/tests/DistanceTests.cpp
Outdated
} | ||
|
||
|
||
//should we do all units? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
isis/tests/DistanceTests.cpp
Outdated
TEST(DistanceTests, LessThanNull) { | ||
try { | ||
bool value = Distance() < Distance(); | ||
ASSERT_TRUE(value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, this should be removed. We shouldn't be testing what that expression outputs because it throws an exception. If we are throwing an exception we should not also be honoring a specific return value.
* Updated the cmake version to 3.10 * Adding configurations for gtest * Tweaking things for gtest * Got gtest working and made a small example test * Updated the cmake version to be 3.10 or greater * Added initial Angle test refactor to use gtest * Add IException and QDebug tests * Added the rest of the IException tests * Added test file discovery support and seperated the main into another file * Added more tests for FileName * Updated with the new testing guidelines and added new tests. * Added Spectel unittest for gtest environment * Added gmock * Forgot to save a file * PixelTest (#536) * initial Pixel test * Add more test cases for Pixel * testing parameterization in Pixel test * testing function parameterization * parameterize static vs object methods * basic PixelTests implementation * clean up and more static tests * update PixelTests with float/dbl expects * Added Endian unit test. * Angle test refactor to use gtest (#529) * Added initial Angle test refactor to use gtest * Add IException and QDebug tests * Added the rest of the IException tests * Update Angle to make private methods public and add tests * Made changes for review comments * Cleanup and addition of streaming the actual errors thrown to the EXPECT_TRUE macro * FileName gtest conversion (#568) * Made two methods private as they are only used within FileName * Added more tests * Added more tests * Update FileNameTests.cpp * BundleSettings unit test (#538) * added build to git ignore * Fixed duplicate main in FileNameTests * Added parameterized test example * Added more tests * Mored BundleSettings tests * Even more tests * Added mocked targetbody settings for BundleSettings test * Added BundleSettings save tests * Fixed BundleSetting save tests to just use a QString * Added default and copy constructor tests and asignment * Update FileName test and merge dev into testing (#598) * Update CMakeLists.txt with version 3.6.0 (patch 1) * Update cmake/CMakeLists.txt library version * Updated the Installation instructions based on user feedback. Also fixed a problem with the isis3VarInit.py script. * Updates made in accordance with requests made on this PR by other developers. * Fix tgo cassis unit test correctly * Fix tgo cassis unit test correctly (#544) * Fixed two bug with AutoReg. One occurs with one dimensional pattern cubes and the other causes the revious registration sample/line to be returned on sub-pixel registration failure. * Fix tgo cassis camera truth again (#554) * Update docsys Makefile to support wwwdoc (#559) The documentation is installed under `docs`, not `doc`, so this file has been updated. `setisis isis3.6.0` and running `make wwwdoc` in `$ISISROOT/../isis/src/docsys` will properly sync the documentation to our web server. * Update isis3VarInit.py Unnecessary 'touch'ing, the '>' redirect will create the file if it doesn't exist. Also, the first redirect should be the single '>'. Otherwise, multiple runs of this program will continue appending to these files. They still work, its just a lot of setting and unsetting for no good reason. * Fixed isis3Startup scripts * Removed unneeded LineEquation include * Make this program more pythonic (#589) * Updated documentation, user interaction, and made the file and directory handling more 'pythonic'. * Correcting for PR comments. * Fixed broken links in the Installation instructions due to the hyperlinks to our GitHub wiki changing. * Removed unused Parabola class * Removed old license, added new unlicense (#594) * Tweaked FileName test to use ISISROOT variable * App to callable function conversion rough draft (#530) * adjusted Process to support lambdas with captures, updated crop app * now compiling with colocated funcs and apps and duplicated symbols accross apps removed * removed debug prints in cmake scripts * changes as requested from review * hapke comment * Added Distance unit tests (#585) * Added Distance unit tests. * Changed EXPECT_FLOAT_EQ to EXPECT_DOUBLE_EQ and changed Solar Radii test to use one solar radii. * Changed unneeded EXPECT_DOUBLE_EQ to EXPECT_EQ. * Fixed toString test. * Adding gtests for Color and Matrix (#532) * Adding gtests for Color and Matrix * Updating gtest for Matrix * More work to ColorTests.cpp and MatrixTests.cpp * Added test for constructor making use of TNT:Array2D in MatrixTests * Update isis/tests/MatrixTests.cpp Co-Authored-By: SgStapleton <[email protected]> * Update isis/tests/MatrixTests.cpp Co-Authored-By: SgStapleton <[email protected]> * Making recommended changes * Fixing odd GitHub behavior... There were suggested changes made in PR that were not playing nicely. Could not push correct version for whatever reason. * Add Utilities, clean up testing (#604) * Update CMakeLists.txt with version 3.6.0 (patch 1) * Update cmake/CMakeLists.txt library version * Updated the Installation instructions based on user feedback. Also fixed a problem with the isis3VarInit.py script. * Updates made in accordance with requests made on this PR by other developers. * Fix tgo cassis unit test correctly * Fix tgo cassis unit test correctly (#544) * Fixed two bug with AutoReg. One occurs with one dimensional pattern cubes and the other causes the revious registration sample/line to be returned on sub-pixel registration failure. * Fix tgo cassis camera truth again (#554) * Update docsys Makefile to support wwwdoc (#559) The documentation is installed under `docs`, not `doc`, so this file has been updated. `setisis isis3.6.0` and running `make wwwdoc` in `$ISISROOT/../isis/src/docsys` will properly sync the documentation to our web server. * Update isis3VarInit.py Unnecessary 'touch'ing, the '>' redirect will create the file if it doesn't exist. Also, the first redirect should be the single '>'. Otherwise, multiple runs of this program will continue appending to these files. They still work, its just a lot of setting and unsetting for no good reason. * Fixed isis3Startup scripts * Removed unneeded LineEquation include * Make this program more pythonic (#589) * Updated documentation, user interaction, and made the file and directory handling more 'pythonic'. * Correcting for PR comments. * Fixed broken links in the Installation instructions due to the hyperlinks to our GitHub wiki changing. * Removed unused Parabola class * Removed old license, added new unlicense (#594) * Fixed issue with the License change (#599) * Removed old license, added new unlicense * Fixed cmake looking for license in the wrong place * Added TestUtilities and used in Color tests * Fixed an issue where app xmls were not being copied * Tweaked IException test failure messages * Updating TestUtilities.h and associated files to account for AssertIException to be broken into AssertIExceptionMessage and AssertIExceptionError
I will be refactoring this test since there are areas where I can use parameters. I also made some comments about some questions I had.