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

Improvements for compare.character #274

Merged
merged 6 commits into from Sep 29, 2015

Conversation

Projects
None yet
2 participants
@krlmlr
Member

krlmlr commented Jun 25, 2015

  • bugfix: don't show more items than necessary when comparing long vectors with few differences
  • bugfix: reverse order in expectation so that output of detailed comparison matches expectation output
  • compare vectors of different length in detail
    • if one vector is shorter, hide (non-existing) value in detailed diff

Similar improvements for compare.numeric are possible but not yet implemented.

Examples:

> expect_equal(letters, c(letters[-26], "a"))
Error: letters not equal to c(letters[-26], "a")
1 string mismatches:
x[26]: "z"
y[26]: "a"
> expect_equal(letters, c("A", letters[-c(1,25,26)]))
Error: letters not equal to c("A", letters[-c(1, 25, 26)])
Lengths (26, 24) differ
3 string mismatches:
x[1]: "a"
y[1]: "A"

x[25]: "y"

x[26]: "z"

Current state:

> expect_equal(letters, c(letters[-26], "a"))
Error: letters not equal to c(letters[-26], "a")
1 string mismatches:
x[26]: "a"
y[26]: "z"

x[NA]: NA
y[NA]: NA

x[NA]: NA
y[NA]: NA

x[NA]: NA
y[NA]: NA

x[NA]: NA
y[NA]: NA
> expect_equal(letters, c("A", letters[-c(1,25,26)]))
Error: letters not equal to c("A", letters[-c(1, 25, 26)])
Lengths (24, 26) differ (string compare on first 24)
1 string mismatch
R/compare.r Outdated
ly <- length(y)
if (lx != ly) {
length(x) <- length(y) <- max(lx, ly)
length_diff = sprintf("Lengths (%s, %s) differ\n", lx, ly)

This comment has been minimized.

@hadley

hadley Sep 24, 2015

Member

Should be <- not =

NEWS.md Outdated
tweaked. Detailed output of differences for character vectors of different
length (#274, @krlmlr).
* Detailed output from `expect_equal()` doesn't confuse expected and actual

This comment has been minimized.

@hadley

hadley Sep 24, 2015

Member

Could you move these up please?

@hadley

This comment has been minimized.

Member

hadley commented Sep 24, 2015

Looks good - just a few minor suggestions.

@krlmlr

This comment has been minimized.

Member

krlmlr commented Sep 25, 2015

Done. Tests succeed, but covr seems to be hanging for the PR test...

@hadley hadley merged commit 30e3ff8 into r-lib:master Sep 29, 2015

1 of 2 checks passed

continuous-integration/travis-ci/pr The Travis CI build could not complete due to an error
Details
continuous-integration/appveyor AppVeyor build succeeded
Details
@hadley

This comment has been minimized.

Member

hadley commented Sep 29, 2015

Thanks!

@krlmlr krlmlr deleted the krlmlr:compare-strings branch Feb 19, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment