Navigation Menu

Skip to content
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
Merged

Conversation

krlmlr
Copy link
Member

@krlmlr 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

ly <- length(y)
if (lx != ly) {
length(x) <- length(y) <- max(lx, ly)
length_diff = sprintf("Lengths (%s, %s) differ\n", lx, ly)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be <- not =

@hadley
Copy link
Member

hadley commented Sep 24, 2015

Looks good - just a few minor suggestions.

@krlmlr
Copy link
Member Author

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
@hadley
Copy link
Member

hadley commented Sep 29, 2015

Thanks!

@krlmlr krlmlr deleted the compare-strings branch February 19, 2016 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants