Skip to content

Commit 60f7e9c

Browse files
committed
Add unit tests
1 parent 9d5ce8b commit 60f7e9c

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
constructor
55
* inst/include/Rcpp/date_datetime/newDatetimeVector.h: Idem
66

7+
* inst/tinytest/test_date.R: Add tests
8+
* inst/tinytest/cpp/dates.cpp: Idem
9+
710
2025-05-06 Dirk Eddelbuettel <[email protected]>
811

912
* DESCRIPTION (Version, Date): Roll micro version and date

inst/tinytest/cpp/dates.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2-
//
1+
32
// dates.cpp: Rcpp R/C++ interface class library -- Date + Datetime tests
43
//
5-
// Copyright (C) 2010 - 2013 Dirk Eddelbuettel and Romain Francois
4+
// Copyright (C) 2010 - 2025 Dirk Eddelbuettel and Romain Francois
65
//
76
// This file is part of Rcpp.
87
//
@@ -245,4 +244,12 @@ bool has_na_dtv(const Rcpp::DatetimeVector d) {
245244
return Rcpp::is_true(Rcpp::any(Rcpp::is_na(d)));
246245
}
247246

247+
// [[Rcpp::export]]
248+
Rcpp::DateVector default_ctor_datevector() {
249+
return Rcpp::DateVector();
250+
}
248251

252+
// [[Rcpp::export]]
253+
Rcpp::DatetimeVector default_ctor_datetimevector() {
254+
return Rcpp::DatetimeVector();
255+
}

inst/tinytest/test_date.R

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
## Copyright (C) 2010 - 2019 Dirk Eddelbuettel and Romain Francois
2+
## Copyright (C) 2010 - 2025 Dirk Eddelbuettel and Romain Francois
33
##
44
## This file is part of Rcpp.
55
##
@@ -241,3 +241,15 @@ dvt <- Sys.time() + 0:2
241241
expect_true(has_na_dtv(dvt) == FALSE, info="DatetimeVector.NAtest.withoutNA")
242242
dvt[1] <- NA
243243
expect_true(has_na_dtv(dvt) == TRUE, info="DatetimeVector.NAtest.withNA")
244+
245+
## default ctor: date
246+
dv <- default_ctor_datevector()
247+
expect_true(inherits(dv, "Date"))
248+
expect_equal(length(dv), 0L)
249+
expect_equal(dv, as.Date(double()))
250+
251+
## default ctor: datetime
252+
dtv <- default_ctor_datetimevector()
253+
expect_true(inherits(dtv, "POSIXct"))
254+
expect_equal(length(dtv), 0L)
255+
expect_equal(dtv, as.POSIXct(double(), origin="1970-01-01")) # origin for R < 4.3.0

0 commit comments

Comments
 (0)