-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
parser and associated unit tests, done
- Loading branch information
ironholds
committed
Aug 21, 2015
1 parent
f5267c9
commit 0e13601
Showing
7 changed files
with
137 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# Generated by roxygen2 (4.1.1): do not edit by hand | ||
|
||
export(humaniformat) | ||
importFrom(Rcpp,sourceCpp) | ||
useDynLib(humaniformat) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# This file was generated by Rcpp::compileAttributes | ||
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 | ||
|
||
#' @export | ||
humaniformat <- function(names) { | ||
.Call('humaniformat_humaniformat', PACKAGE = 'humaniformat', names) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// This file was generated by Rcpp::compileAttributes | ||
// Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 | ||
|
||
#include <Rcpp.h> | ||
|
||
using namespace Rcpp; | ||
|
||
// humaniformat | ||
DataFrame humaniformat(std::vector < std::string > names); | ||
RcppExport SEXP humaniformat_humaniformat(SEXP namesSEXP) { | ||
BEGIN_RCPP | ||
Rcpp::RObject __result; | ||
Rcpp::RNGScope __rngScope; | ||
Rcpp::traits::input_parameter< std::vector < std::string > >::type names(namesSEXP); | ||
__result = Rcpp::wrap(humaniformat(names)); | ||
return __result; | ||
END_RCPP | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
#include "human_parse.h" | ||
|
||
//' @export | ||
// [[Rcpp::export]] | ||
DataFrame humaniformat(std::vector < std::string > names){ | ||
|
||
human_parse parse_inst; | ||
return parse_inst.parse_vector(names); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,50 @@ | ||
context("Name parsing") | ||
|
||
context("humaniformat") | ||
test_that("Simple {first, last} names can be parsed", { | ||
result <- unlist(humaniformat("Jim Jeffries")) | ||
expect_true(all(names(result) == c("salutation","first_name","middle_name","last_name","suffix","full_name"))) | ||
expect_true(result["first_name"] == "Jim") | ||
expect_true(result["last_name"] == "Jeffries") | ||
}) | ||
|
||
test_that("Names with salutations can be parsed", { | ||
result <- unlist(humaniformat("Dr. Jim Jeffries")) | ||
expect_true(all(names(result) == c("salutation","first_name","middle_name","last_name","suffix","full_name"))) | ||
expect_true(result["first_name"] == "Jim") | ||
expect_true(result["last_name"] == "Jeffries") | ||
expect_true(result["salutation"] == "Dr.") | ||
}) | ||
|
||
test_that("humaniformat works", { | ||
test_that("Names with suffixes can be parsed", { | ||
result <- unlist(humaniformat("Jim Jeffries PhD")) | ||
expect_true(all(names(result) == c("salutation","first_name","middle_name","last_name","suffix","full_name"))) | ||
expect_true(result["first_name"] == "Jim") | ||
expect_true(result["last_name"] == "Jeffries") | ||
expect_true(result["suffix"] == "PhD") | ||
}) | ||
|
||
expect_true(TRUE) | ||
test_that("Names with middle names can be parsed", { | ||
result <- unlist(humaniformat("Jim Schmidt Jeffries")) | ||
expect_true(all(names(result) == c("salutation","first_name","middle_name","last_name","suffix","full_name"))) | ||
expect_true(result["first_name"] == "Jim") | ||
expect_true(result["middle_name"] == "Schmidt") | ||
expect_true(result["last_name"] == "Jeffries") | ||
}) | ||
|
||
test_that("Names with compound surnames can be parsed", { | ||
result <- unlist(humaniformat("Jim de la ben Jeffries")) | ||
expect_true(all(names(result) == c("salutation","first_name","middle_name","last_name","suffix","full_name"))) | ||
expect_true(result["first_name"] == "Jim") | ||
expect_true(result["last_name"] == "de la ben Jeffries") | ||
}) | ||
|
||
test_that("Names with all elements can be parsed", { | ||
result <- unlist(humaniformat("Rev Jim Schmidt de la ben Jeffries PhD")) | ||
expect_true(all(names(result) == c("salutation","first_name","middle_name","last_name","suffix","full_name"))) | ||
expect_true(result["salutation"] == "Rev") | ||
expect_true(result["first_name"] == "Jim") | ||
expect_true(result["middle_name"] == "Schmidt") | ||
expect_true(result["last_name"] == "de la ben Jeffries") | ||
expect_true(result["suffix"] == "PhD") | ||
|
||
}) |