Skip to content

Commit 4e6f328

Browse files
committed
Adapt so that functional dependency fails for every occurance of the
condition Add test file
1 parent cb1e945 commit 4e6f328

File tree

5 files changed

+16
-6
lines changed

5 files changed

+16
-6
lines changed

pkg/R/syntax.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ NULL
167167
condition <- do.call(paste, c(mget(Lvars, parent.frame()), sep="|"))
168168
consequent <- do.call(paste0, c(mget(Rvars, parent.frame()), sep="|"))
169169
cf <- .Call("R_fdcheck", condition, consequent)
170+
170171
cf == seq_along(cf)
171172
}
172173

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
d <- data.frame(a = c(1, 1), b = c(1, 2))
2+
val <- validator(a ~ b)
3+
out <- confront(d, val)
4+
expect_equal(nrow(violating(d, out)), 2)
5+
6+

pkg/inst/tinytest/test_poc.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@
147147
dat <- read.csv("pocdata/Rule_15.csv")
148148
expect_equivalent(
149149
values(confront(dat,v))
150-
, matrix(c(TRUE,TRUE,TRUE,FALSE,TRUE),nrow=5)
150+
, matrix(c(TRUE,TRUE,FALSE,FALSE,TRUE),nrow=5)
151151
)
152152

153153

pkg/inst/tinytest/test_syntax.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
,postcode = c('2495','2496','8888','2495')
3737
)
3838
cf <- confront(dat,v1)
39-
expect_equivalent(values(cf),array(c(TRUE,FALSE,TRUE,TRUE),dim=c(4,1)))
39+
expect_equivalent(values(cf),array(c(FALSE,FALSE,TRUE,FALSE),dim=c(4,1)))
4040

4141

4242
## group_expansion ----

pkg/src/R_fdep.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
/*
2626
* Check functional dependencies x -> y
2727
*
28-
* The FD x -> y is two be interpreted as if two
28+
* The FD x -> y is to be interpreted as if two
2929
* elements of x have the same value, they shall have the
3030
* same value for y. In the comments below we refer to 'x'
3131
* as the condition and to 'y' as the consequent.
@@ -35,7 +35,7 @@
3535
*
3636
* If all pairs in (x,y) obey x->y then the output is seq_along(x).
3737
* suppose that for some i < j we have x[i] == x[j] but y[i] != y[j].
38-
* The j'th value of the output is then equal to i.
38+
* The i'th and j'th value of the output is then equal to 0.
3939
*
4040
*/
4141

@@ -79,11 +79,14 @@ SEXP R_fdcheck(SEXP x, SEXP y){
7979
a = SuperFastHash((const char *) &a, 4);
8080
goto rehash;
8181
}
82-
if (H[j] == b && strcmp( CHAR(STRING_ELT(y,E[j])), CHAR(STRING_ELT(y,i)) ) == 0 ){
82+
if (INTEGER(out)[E[j]] == 0){
83+
(*I) = 0;
84+
} else if (H[j] == b && strcmp( CHAR(STRING_ELT(y,E[j])), CHAR(STRING_ELT(y,i)) ) == 0 ){
8385
// conseqent also similar, all good.
8486
(*I) = i + 1;
8587
} else { // consequent different, store conflicting index.
86-
(*I) = E[j] + 1;
88+
(*I) = 0;
89+
INTEGER(out)[E[j]] = 0;
8790
}
8891
}
8992
}

0 commit comments

Comments
 (0)