Commit beb95bea by Leonardo Silvestri

fix check zts order in rbind; align fixes

parent 9512a3a5
Pipeline #7767063 passed with stage
in 31 minutes 29 seconds
......@@ -15,9 +15,7 @@
## You should have received a copy of the GNU General Public License
## along with ztsdb. If not, see <http://www.gnu.org/licenses/>.
one_second <- as.duration(1e9)
one_minute <- 60*one_second
one_hour <- 60*one_minute
one_second <- as.duration(1e9); one_minute <- 60*one_second; one_hour <- 60*one_minute
RUnit_align_idx <- function() {
a <- seq(|.2015-01-01 12:00:00 America/New_York.|,
......@@ -64,3 +62,33 @@ RUnit_align_count <- function() {
exp[|-2015-01-01 15:00:00 America/New_York -> 2015-01-02 15:00:00 America/New_York+|,] <- 0
all(a == exp)
}
RUnit_align_closest_enclosing <- function() {
idx <- seq(|.2015-01-01 12:00:00 America/New_York.|,
|.2015-01-01 15:00:00 America/New_York.|,
by=one_second)
data <- 0:10800;
z <- zts(idx, matrix(data, length(data), 1))
b <- seq(|.2015-01-01 11:00:00 America/New_York.|,
|.2015-01-01 16:00:00 America/New_York.|,
by=one_minute)
a <- align(z, b, method="closest")
exp <- rbind(zts(head(b,60), matrix(NaN, 60, 1)),
z[seq(1, 10801, 60), ],
zts(tail(b,60), matrix(NaN, 60, 1)))
all.equal(a, exp)
}
RUnit_align_count_enclosing <- function() {
idx <- seq(|.2015-01-01 12:00:00 America/New_York.|,
|.2015-01-01 14:59:59 America/New_York.|,
by=one_second)
data <- 0:10799
z <- zts(idx, matrix(data, length(data), 1))
b <- seq(|.2015-01-01 11:00:00 America/New_York.|,
|.2015-01-01 16:00:00 America/New_York.|,
by=one_minute)
a <- align(z, b, -one_minute, method="count")
exp <- rbind(zts(head(b,61), matrix(0, 61, 1)),
zts(head(tail(b,-61), -60), matrix(60, 180, 1)),
zts(tail(b,60), matrix(0, 60, 1)))
all.equal(a, exp)
}
......@@ -71,7 +71,6 @@ namespace ztsdb {
> right;
for (auto i=b; i!=e; ++i) {
std::cout << "*i: " << *i << std::endl;
if (left.size() == right.size()) {
if (!left.size() || *i < left.top()) {
left.push(*i);
......
......@@ -551,8 +551,9 @@ static void checkZtsBindInDim0(vector<val::VBuiltinG::arg_t>::const_iterator beg
}
idx_type prev_rows = zp_prev->getdim(0);
idx_type cur_rows = zp_cur->getdim(0);
if (prev_rows && cur_rows &&
zp_prev->getIndex()[prev_rows-1] >= zp_cur->getIndex()[cur_rows-1]) {
zp_prev->getIndex()[zp_prev->getIndex().size()-1] >= zp_cur->getIndex()[0]) {
throw interp::EvalException("non-ascending index for rbind", val::getLoc(*iter));
}
}
......
......@@ -82,7 +82,7 @@ namespace arr { // should be in tz? LLL
// advance until we have a point in x that is in the interval
// defined around yi:
while (ix < x.size() && x[ix] < ystart) ++ix;
while (ix <= x.size() && x[ix] < ystart) ++ix;
if (ix >= x.size() || x[ix] > yend) {
res.push_back(NANF::f());
continue;
......@@ -121,7 +121,7 @@ namespace arr { // should be in tz? LLL
// advance until we have a point in x that is in the interval
// defined around yi:
while (ix < x.size() && x[ix] < ystart) ++ix;
if (ix > x.size() || x[ix] > yend) {
if (ix >= x.size() || x[ix] > yend) {
ydata.push_back(NANF::f());
continue;
}
......@@ -158,7 +158,7 @@ namespace arr { // should be in tz? LLL
auto iter = std::lower_bound(x.begin() + ix, x.end(), ystart);
ix = iter - x.begin();
if (ix > x.size() || x[ix] >= yend) {
if (ix >= x.size() || x[ix] >= yend) {
ydata.push_back(F::f(xdata.end(), xdata.end())); // empty interval
continue;
}
......
......@@ -72,7 +72,7 @@ TEST(align_closest_double) {
(x, y, xdata, ydata, start, end);
std::cout << ydata.size() << std::endl;
for (size_t i=0; i<ydata.size(); ++i) {
std::cout << ydata[i] << std::endl;
std::cout << ydata[i] << ", " << exp[i] << std::endl;
}
ASSERT_TRUE(ydata == exp);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment