-
Notifications
You must be signed in to change notification settings - Fork 2
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
Feature enhancement#118 times unit test #192
Changes from 37 commits
fce2a94
39d3bc3
b4a65b2
9327536
ccfe28a
788f322
80364e3
75d516f
edd2201
c21121f
9ee7d98
b830b95
2ef7de7
32462ee
e6dec84
15bf7ad
4ebfd27
1dc6951
d7ef355
0d04dd6
0ae687c
81dd645
aff4117
bf7569f
cbf7124
875785c
bf5483b
20cfaf1
998601b
d750899
bcbc4b4
acc9b44
5360de4
54549fa
cf7d963
91530cb
da922e4
833cc72
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#include "gtest/gtest.h" | ||
#include <assert.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <math.h> | ||
#include "../generic.h" | ||
#include "../SW_Sky.h" | ||
#include "../filefuncs.h" | ||
#include "../myMemory.h" | ||
#include "../SW_Defines.h" | ||
#include "../SW_Files.h" | ||
#include "../SW_Model.h" | ||
#include "../SW_Site.h" | ||
#include "../SW_SoilWater.h" | ||
#include "../SW_VegProd.h" | ||
#include "../SW_Site.h" | ||
#include "../SW_Flow_lib.h" | ||
#include "../Times.h" | ||
#include "sw_testhelpers.h" | ||
|
||
namespace{ | ||
// Test the 'Times.c' function 'interpolate_monthlyValues' | ||
TEST(TimesTest, interpolateMonthlyValues){ | ||
// point to the structure that contains cloud coverage monthly values | ||
SW_SKY SW_Sky; | ||
SW_SKY *interpolate = &SW_Sky; | ||
unsigned int i; | ||
// set all monthlyValues all 10 | ||
for (i = 0; i < length(interpolate -> cloudcov); i++){ | ||
interpolate -> cloudcov[i] = 10; | ||
} | ||
interpolate -> cloudcov_daily[0] = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you have to specifically so cloudcov_daily[0] to 0 here? Should this be part of the functionality. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did that to illustrate that cloudcov_daily[0] does not change by setting it before the function call than testing that is still that value afterwords. The function does not modify this value so it is whatever it is before the call. |
||
|
||
// test various obtained values | ||
interpolate_monthlyValues(interpolate -> cloudcov, interpolate -> cloudcov_daily); | ||
// inperpolate_monthlyValues should not change index 0 because we used | ||
// base1 indices | ||
EXPECT_DOUBLE_EQ(interpolate -> cloudcov_daily[0], 0); | ||
EXPECT_DOUBLE_EQ(interpolate -> cloudcov_daily[1], 10.0); | ||
// test top conditional, day < 15 | ||
EXPECT_DOUBLE_EQ(interpolate -> cloudcov_daily[14], 10.0); | ||
// test middle conditional, day >= 15 | ||
EXPECT_DOUBLE_EQ(interpolate -> cloudcov_daily[15], 10.0); | ||
EXPECT_DOUBLE_EQ(interpolate -> cloudcov_daily[365], 10.0); | ||
// Reset to previous global states | ||
Reset_SOILWAT2_after_UnitTest(); | ||
|
||
// change first value to 20 and test the changes | ||
interpolate -> cloudcov[0] = 20; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you actually test these changes? Could you clarify your message to something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, changing cloudcov[0] translates to changing the cloud cover in January, which changes the interpolation of all the days. I test these changes underneath this initialization. |
||
|
||
interpolate_monthlyValues(interpolate -> cloudcov, interpolate -> cloudcov_daily); | ||
// calculated by hand | ||
EXPECT_DOUBLE_EQ(interpolate -> cloudcov_daily[0], 0); | ||
EXPECT_DOUBLE_EQ(interpolate -> cloudcov_daily[1], 15.483870967741936); | ||
EXPECT_DOUBLE_EQ(interpolate -> cloudcov_daily[14], 19.6774193548387); | ||
EXPECT_DOUBLE_EQ(interpolate -> cloudcov_daily[13], 19.354838709677419); | ||
EXPECT_DOUBLE_EQ(interpolate -> cloudcov_daily[31], 14.838709677419356); | ||
EXPECT_DOUBLE_EQ(interpolate -> cloudcov_daily[365], 15.161290322580644); | ||
// test last day on leap year | ||
EXPECT_DOUBLE_EQ(interpolate -> cloudcov_daily[MAX_DAYS], 15.483870967741936); | ||
// change december monthly value to ensure meaningful final interpolation | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add more enter / space around new test conditions to clarify There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean have a space for every EXPECT? Ie. EXPECT_EQ
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No - I mean when ever you change the the input conditions, add more breaks. So enter after line 61. |
||
interpolate -> cloudcov[11] = 12; | ||
interpolate_monthlyValues(interpolate -> cloudcov, interpolate -> cloudcov_daily); | ||
EXPECT_DOUBLE_EQ(interpolate -> cloudcov_daily[365], 16.129032258064516); | ||
// test last day on leap year | ||
EXPECT_DOUBLE_EQ(interpolate -> cloudcov_daily[MAX_DAYS], 16.387096774193548); | ||
// Reset to previous global states | ||
Reset_SOILWAT2_after_UnitTest(); | ||
} | ||
} |
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.
// set all monthly values to 10?
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.
Yes, since the test relies on the values here, I need to know exactly what the values are in order to test properly. Setting them all to 10 ensures this. I will add this to the comment to be more clear.