Skip to content

Commit a536080

Browse files
committed
fix setequal bug
1 parent 9f3c8d4 commit a536080

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2015-01-02 Kevin Ushey <[email protected]>
2+
3+
* inst/include/Rcpp/sugar/functions/setdiff.h: fix for setequals
4+
* inst/unitTests/cpp/sugar.cpp: unit tests
5+
* inst/unitTests/runit.sugar.R: unit tests
6+
17
2015-01-01 Dirk Eddelbuettel <[email protected]>
28

39
* inst/include/Rcpp/sugar/functions/mean.h: Return type is double, not

inst/include/Rcpp/sugar/functions/setdiff.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ namespace sugar{
7676
lhs_set( get_const_begin(lhs), get_const_end(lhs) ),
7777
rhs_set( get_const_begin(rhs), get_const_end(rhs) )
7878
{
79-
80-
std::for_each( rhs_set.begin(), rhs_set.end(), RemoveFromSet<SET>(lhs_set) ) ;
8179
}
8280

8381
bool get() const {

inst/unitTests/cpp/sugar.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,10 +592,22 @@ LogicalVector runit_duplicated( CharacterVector x){
592592
IntegerVector runit_union( IntegerVector x, IntegerVector y){
593593
return union_( x, y) ;
594594
}
595+
595596
// [[Rcpp::export]]
596597
IntegerVector runit_setdiff( IntegerVector x, IntegerVector y){
597598
return setdiff( x, y) ;
598599
}
600+
601+
// [[Rcpp::export]]
602+
bool runit_setequal_integer(IntegerVector x, IntegerVector y) {
603+
return setequal(x, y);
604+
}
605+
606+
// [[Rcpp::export]]
607+
bool runit_setequal_character(CharacterVector x, CharacterVector y) {
608+
return setequal(x, y);
609+
}
610+
599611
// [[Rcpp::export]]
600612
IntegerVector runit_intersect( IntegerVector x, IntegerVector y){
601613
return intersect( x, y ) ;

inst/unitTests/runit.sugar.R

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,12 @@ if (.runThisTest) {
634634
checkEquals(sort(runit_setdiff( 1:10, 1:5 )), sort(setdiff( 1:10, 1:5)))
635635
}
636636

637+
test.setequal <- function() {
638+
checkTrue(runit_setequal_integer(1:10, 10:1))
639+
checkTrue(runit_setequal_character(c("a", "b", "c"), c("c", "b", "a")))
640+
checkTrue(!runit_setequal_character(c("a", "b"), c("c")))
641+
}
642+
637643
test.union <- function(){
638644
checkEquals(sort(runit_union( 1:10, 1:5 )), sort(union( 1:10, 1:5 )))
639645
}
@@ -676,22 +682,22 @@ if (.runThisTest) {
676682
}
677683

678684
## Additions made 1 Jan 2015
679-
685+
680686
test.mean.integer <- function() {
681687
v1 <- seq(-100L, 100L)
682688
v2 <- c(v1, NA)
683689
checkEquals(mean(v1), meanInteger(v1), "mean of integer vector")
684690
checkEquals(mean(v2), meanInteger(v2), "mean of integer vector with NA")
685691
}
686-
692+
687693
test.mean.numeric <- function() {
688694
v1 <- seq(-100, 100)
689695
v2 <- c(v1, NA)
690696
v3 <- c(v1, Inf)
691697
checkEquals(mean(v1), meanNumeric(v1), "mean of numeric vector")
692698
checkEquals(mean(v2), meanNumeric(v2), "mean of numeric vector with NA")
693699
checkEquals(mean(v3), meanNumeric(v3), "mean of numeric vector with Inf")
694-
}
700+
}
695701

696702
test.mean.complex <- function() {
697703
v1 <- seq(-100, 100) + 1.0i
@@ -708,5 +714,5 @@ if (.runThisTest) {
708714
checkEquals(mean(v1), meanLogical(v1), "mean of logical vector")
709715
checkEquals(mean(v2), meanLogical(v2), "mean of logical vector with NA")
710716
}
711-
717+
712718
}

0 commit comments

Comments
 (0)