diff --git a/other/swagger/codegen/nbaRcodegen/src/main/java/nl/naturalis/nba/codegen/NbarcodegenGenerator.java b/other/swagger/codegen/nbaRcodegen/src/main/java/nl/naturalis/nba/codegen/NbarcodegenGenerator.java index 44641c7..b6a6350 100644 --- a/other/swagger/codegen/nbaRcodegen/src/main/java/nl/naturalis/nba/codegen/NbarcodegenGenerator.java +++ b/other/swagger/codegen/nbaRcodegen/src/main/java/nl/naturalis/nba/codegen/NbarcodegenGenerator.java @@ -15,6 +15,7 @@ import com.fasterxml.jackson.databind.SerializationFeature; import io.swagger.codegen.CodegenConfig; +import io.swagger.codegen.CodegenConstants; import io.swagger.codegen.CodegenOperation; import io.swagger.codegen.DefaultCodegen; import io.swagger.codegen.SupportingFile; @@ -77,14 +78,12 @@ public NbarcodegenGenerator() supportingFiles.add(new SupportingFile("package.mustache", "", "R/nbaR-package.r")); supportingFiles.add(new SupportingFile("license.mustache", "", "LICENSE")); + // set the output folder here this.outputFolder = "."; - this.testPackage = "tests/testthat/"; + this.testPackage = "tests/testthat"; modelTestTemplateFiles.put("model_test.mustache", ".r"); - - // set the output folder here - outputFolder = "."; /** * Template Location. This is the location which templates will @@ -139,6 +138,50 @@ public NbarcodegenGenerator() } + @Override + public void processOpts() { + super.processOpts(); + + if (additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) { + setPackageName((String) additionalProperties.get(CodegenConstants.PACKAGE_NAME)); + } else { + setPackageName("swagger"); + } + + if (additionalProperties.containsKey(CodegenConstants.PACKAGE_VERSION)) { + setPackageVersion((String) additionalProperties.get(CodegenConstants.PACKAGE_VERSION)); + } else { + setPackageVersion("1.0.0"); + } + + additionalProperties.put(CodegenConstants.PACKAGE_NAME, packageName); + additionalProperties.put(CodegenConstants.PACKAGE_VERSION, packageVersion); + + additionalProperties.put("apiDocPath", apiDocPath); + additionalProperties.put("modelDocPath", modelDocPath); + + //Hannes: Commented out from superclass + //apiTestTemplateFiles.clear(); // TODO: add api test template + //modelTestTemplateFiles.clear(); // TODO: add model test template + + //apiDocTemplateFiles.clear(); // TODO: add api doc template + //modelDocTemplateFiles.clear(); // TODO: add model doc template + + modelPackage = packageName; + apiPackage = packageName; + + supportingFiles.add(new SupportingFile("README.mustache", "", "README.md")); + supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh")); + supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore")); + supportingFiles.add(new SupportingFile("description.mustache", "", "DESCRIPTION")); + supportingFiles.add(new SupportingFile("Rbuildignore.mustache", "", ".Rbuildignore")); + supportingFiles.add(new SupportingFile(".travis.yml", "", ".travis.yml")); + supportingFiles.add(new SupportingFile("response.mustache", "/R", "Response.r")); + supportingFiles.add(new SupportingFile("element.mustache", "/R", "Element.r")); + supportingFiles.add(new SupportingFile("api_client.mustache", "/R", "ApiClient.r")); + supportingFiles.add(new SupportingFile("NAMESPACE.mustache", "", "NAMESPACE")); + } + @Override public String toModelTestFilename(String name) { @@ -146,6 +189,13 @@ public String toModelTestFilename(String name) return ("test-" + name); } +/* @Override + public String modelTestFileFolder() + { + System.out.println("Testpackage : " + testPackage()); + return "tests/testthat/"; + } +*/ /* * Overridden to change later R object name from e.g. SpecimenApi to * SpecimenClient diff --git a/tests/testthat/test-Agent.r b/tests/testthat/test-Agent.r index a44f139..708d602 100644 --- a/tests/testthat/test-Agent.r +++ b/tests/testthat/test-Agent.r @@ -1,12 +1,23 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class Agent") test_that("Constructor works", { obj <- Agent$new() expect_is(obj, "Agent") + + # test constructor with random arguments + # test field agentText, type character + obj <- Agent$new( + agentText = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Agent") }) test_that("toList works", { diff --git a/tests/testthat/test-AssociatedTaxon.r b/tests/testthat/test-AssociatedTaxon.r index 2db2e36..8d7a013 100644 --- a/tests/testthat/test-AssociatedTaxon.r +++ b/tests/testthat/test-AssociatedTaxon.r @@ -1,12 +1,31 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class AssociatedTaxon") test_that("Constructor works", { obj <- AssociatedTaxon$new() expect_is(obj, "AssociatedTaxon") + + # test constructor with random arguments + # test field name, type character + obj <- AssociatedTaxon$new( + name = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "AssociatedTaxon") + # test field relationType, type character + obj <- AssociatedTaxon$new( + relationType = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "AssociatedTaxon") }) test_that("toList works", { diff --git a/tests/testthat/test-BioStratigraphy.r b/tests/testthat/test-BioStratigraphy.r index 3457b8a..5642f5f 100644 --- a/tests/testthat/test-BioStratigraphy.r +++ b/tests/testthat/test-BioStratigraphy.r @@ -1,12 +1,127 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class BioStratigraphy") test_that("Constructor works", { obj <- BioStratigraphy$new() expect_is(obj, "BioStratigraphy") + + # test constructor with random arguments + # test field youngBioDatingQualifier, type character + obj <- BioStratigraphy$new( + youngBioDatingQualifier = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "BioStratigraphy") + # test field youngBioName, type character + obj <- BioStratigraphy$new( + youngBioName = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "BioStratigraphy") + # test field youngFossilZone, type character + obj <- BioStratigraphy$new( + youngFossilZone = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "BioStratigraphy") + # test field youngFossilSubZone, type character + obj <- BioStratigraphy$new( + youngFossilSubZone = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "BioStratigraphy") + # test field youngBioCertainty, type character + obj <- BioStratigraphy$new( + youngBioCertainty = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "BioStratigraphy") + # test field youngStratType, type character + obj <- BioStratigraphy$new( + youngStratType = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "BioStratigraphy") + # test field bioDatingQualifier, type character + obj <- BioStratigraphy$new( + bioDatingQualifier = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "BioStratigraphy") + # test field rangePosition, type character + obj <- BioStratigraphy$new( + rangePosition = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "BioStratigraphy") + # test field oldBioName, type character + obj <- BioStratigraphy$new( + oldBioName = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "BioStratigraphy") + # test field bioIdentifier, type character + obj <- BioStratigraphy$new( + bioIdentifier = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "BioStratigraphy") + # test field oldFossilzone, type character + obj <- BioStratigraphy$new( + oldFossilzone = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "BioStratigraphy") + # test field oldFossilSubzone, type character + obj <- BioStratigraphy$new( + oldFossilSubzone = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "BioStratigraphy") + # test field oldBioCertainty, type character + obj <- BioStratigraphy$new( + oldBioCertainty = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "BioStratigraphy") + # test field oldBioStratType, type character + obj <- BioStratigraphy$new( + oldBioStratType = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "BioStratigraphy") }) test_that("toList works", { diff --git a/tests/testthat/test-ChronoStratigraphy.r b/tests/testthat/test-ChronoStratigraphy.r index 7a07576..bb342b0 100644 --- a/tests/testthat/test-ChronoStratigraphy.r +++ b/tests/testthat/test-ChronoStratigraphy.r @@ -1,12 +1,215 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class ChronoStratigraphy") test_that("Constructor works", { obj <- ChronoStratigraphy$new() expect_is(obj, "ChronoStratigraphy") + + # test constructor with random arguments + # test field youngRegionalSubstage, type character + obj <- ChronoStratigraphy$new( + youngRegionalSubstage = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "ChronoStratigraphy") + # test field youngRegionalStage, type character + obj <- ChronoStratigraphy$new( + youngRegionalStage = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "ChronoStratigraphy") + # test field youngRegionalSeries, type character + obj <- ChronoStratigraphy$new( + youngRegionalSeries = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "ChronoStratigraphy") + # test field youngDatingQualifier, type character + obj <- ChronoStratigraphy$new( + youngDatingQualifier = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "ChronoStratigraphy") + # test field youngInternSystem, type character + obj <- ChronoStratigraphy$new( + youngInternSystem = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "ChronoStratigraphy") + # test field youngInternSubstage, type character + obj <- ChronoStratigraphy$new( + youngInternSubstage = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "ChronoStratigraphy") + # test field youngInternStage, type character + obj <- ChronoStratigraphy$new( + youngInternStage = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "ChronoStratigraphy") + # test field youngInternSeries, type character + obj <- ChronoStratigraphy$new( + youngInternSeries = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "ChronoStratigraphy") + # test field youngInternErathem, type character + obj <- ChronoStratigraphy$new( + youngInternErathem = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "ChronoStratigraphy") + # test field youngInternEonothem, type character + obj <- ChronoStratigraphy$new( + youngInternEonothem = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "ChronoStratigraphy") + # test field youngChronoName, type character + obj <- ChronoStratigraphy$new( + youngChronoName = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "ChronoStratigraphy") + # test field youngCertainty, type character + obj <- ChronoStratigraphy$new( + youngCertainty = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "ChronoStratigraphy") + # test field oldDatingQualifier, type character + obj <- ChronoStratigraphy$new( + oldDatingQualifier = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "ChronoStratigraphy") + # test field oldRegionalSubstage, type character + obj <- ChronoStratigraphy$new( + oldRegionalSubstage = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "ChronoStratigraphy") + # test field oldRegionalStage, type character + obj <- ChronoStratigraphy$new( + oldRegionalStage = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "ChronoStratigraphy") + # test field oldRegionalSeries, type character + obj <- ChronoStratigraphy$new( + oldRegionalSeries = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "ChronoStratigraphy") + # test field oldInternSystem, type character + obj <- ChronoStratigraphy$new( + oldInternSystem = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "ChronoStratigraphy") + # test field oldInternSubstage, type character + obj <- ChronoStratigraphy$new( + oldInternSubstage = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "ChronoStratigraphy") + # test field oldInternStage, type character + obj <- ChronoStratigraphy$new( + oldInternStage = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "ChronoStratigraphy") + # test field oldInternSeries, type character + obj <- ChronoStratigraphy$new( + oldInternSeries = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "ChronoStratigraphy") + # test field oldInternErathem, type character + obj <- ChronoStratigraphy$new( + oldInternErathem = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "ChronoStratigraphy") + # test field oldInternEonothem, type character + obj <- ChronoStratigraphy$new( + oldInternEonothem = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "ChronoStratigraphy") + # test field oldChronoName, type character + obj <- ChronoStratigraphy$new( + oldChronoName = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "ChronoStratigraphy") + # test field chronoIdentifier, type character + obj <- ChronoStratigraphy$new( + chronoIdentifier = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "ChronoStratigraphy") + # test field oldCertainty, type character + obj <- ChronoStratigraphy$new( + oldCertainty = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "ChronoStratigraphy") }) test_that("toList works", { diff --git a/tests/testthat/test-Crs.r b/tests/testthat/test-Crs.r index 483eaea..38f0bb2 100644 --- a/tests/testthat/test-Crs.r +++ b/tests/testthat/test-Crs.r @@ -1,12 +1,23 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class Crs") test_that("Constructor works", { obj <- Crs$new() expect_is(obj, "Crs") + + # test constructor with random arguments + # test field type, type character + obj <- Crs$new( + type = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Crs") }) test_that("toList works", { diff --git a/tests/testthat/test-DefaultClassification.r b/tests/testthat/test-DefaultClassification.r index 77a61eb..25527b4 100644 --- a/tests/testthat/test-DefaultClassification.r +++ b/tests/testthat/test-DefaultClassification.r @@ -1,12 +1,103 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class DefaultClassification") test_that("Constructor works", { obj <- DefaultClassification$new() expect_is(obj, "DefaultClassification") + + # test constructor with random arguments + # test field kingdom, type character + obj <- DefaultClassification$new( + kingdom = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "DefaultClassification") + # test field phylum, type character + obj <- DefaultClassification$new( + phylum = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "DefaultClassification") + # test field className, type character + obj <- DefaultClassification$new( + className = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "DefaultClassification") + # test field order, type character + obj <- DefaultClassification$new( + order = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "DefaultClassification") + # test field superFamily, type character + obj <- DefaultClassification$new( + superFamily = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "DefaultClassification") + # test field family, type character + obj <- DefaultClassification$new( + family = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "DefaultClassification") + # test field genus, type character + obj <- DefaultClassification$new( + genus = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "DefaultClassification") + # test field subgenus, type character + obj <- DefaultClassification$new( + subgenus = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "DefaultClassification") + # test field specificEpithet, type character + obj <- DefaultClassification$new( + specificEpithet = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "DefaultClassification") + # test field infraspecificEpithet, type character + obj <- DefaultClassification$new( + infraspecificEpithet = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "DefaultClassification") + # test field infraspecificRank, type character + obj <- DefaultClassification$new( + infraspecificRank = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "DefaultClassification") }) test_that("toList works", { diff --git a/tests/testthat/test-Expert.r b/tests/testthat/test-Expert.r index e81cf69..559ee3c 100644 --- a/tests/testthat/test-Expert.r +++ b/tests/testthat/test-Expert.r @@ -1,12 +1,34 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class Expert") test_that("Constructor works", { obj <- Expert$new() expect_is(obj, "Expert") + + # test constructor with random arguments + # test field agentText, type character + obj <- Expert$new( + agentText = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Expert") + # test field fullName, type character + obj <- Expert$new( + fullName = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Expert") + # test field organization, type Organization + obj <- Expert$new(organization = Organization$new()) + expect_is(obj, "Expert") }) test_that("toList works", { diff --git a/tests/testthat/test-Feature.r b/tests/testthat/test-Feature.r index 9c54713..b816084 100644 --- a/tests/testthat/test-Feature.r +++ b/tests/testthat/test-Feature.r @@ -1,12 +1,33 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class Feature") test_that("Constructor works", { obj <- Feature$new() expect_is(obj, "Feature") + + # test constructor with random arguments + # test field crs, type Crs + obj <- Feature$new(crs = Crs$new()) + expect_is(obj, "Feature") + # test field bbox, type list, datatype numeric + randomList <- lapply( + 1:sample(5:10, 1), + function(x) paste(sample(letters, sample(1:10, 1)), collapse = "") + ) + obj <- Feature$new(bbox = randomList) + expect_is(obj, "Feature") + # test field id, type character + obj <- Feature$new( + id = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Feature") }) test_that("toList works", { diff --git a/tests/testthat/test-FeatureCollection.r b/tests/testthat/test-FeatureCollection.r index 0ff1925..7bc7be7 100644 --- a/tests/testthat/test-FeatureCollection.r +++ b/tests/testthat/test-FeatureCollection.r @@ -1,12 +1,29 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class FeatureCollection") test_that("Constructor works", { obj <- FeatureCollection$new() expect_is(obj, "FeatureCollection") + + # test constructor with random arguments + # test field crs, type Crs + obj <- FeatureCollection$new(crs = Crs$new()) + expect_is(obj, "FeatureCollection") + # test field bbox, type list, datatype numeric + randomList <- lapply( + 1:sample(5:10, 1), + function(x) paste(sample(letters, sample(1:10, 1)), collapse = "") + ) + obj <- FeatureCollection$new(bbox = randomList) + expect_is(obj, "FeatureCollection") + # test field features, type list, datatype Feature + lst <- lapply(1:sample(1:10, 1), function(x) Feature$new()) + obj <- FeatureCollection$new(features = lst) + expect_is(obj, "FeatureCollection") }) test_that("toList works", { diff --git a/tests/testthat/test-Filter.r b/tests/testthat/test-Filter.r index bbdf4b7..ac4f182 100644 --- a/tests/testthat/test-Filter.r +++ b/tests/testthat/test-Filter.r @@ -1,12 +1,45 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class Filter") test_that("Constructor works", { obj <- Filter$new() expect_is(obj, "Filter") + + # test constructor with random arguments + # test field acceptRegexp, type character + obj <- Filter$new( + acceptRegexp = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Filter") + # test field rejectRegexp, type character + obj <- Filter$new( + rejectRegexp = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Filter") + # test field acceptValues, type list, datatype character + randomList <- lapply( + 1:sample(5:10, 1), + function(x) paste(sample(letters, sample(1:10, 1)), collapse = "") + ) + obj <- Filter$new(acceptValues = randomList) + expect_is(obj, "Filter") + # test field rejectValues, type list, datatype character + randomList <- lapply( + 1:sample(5:10, 1), + function(x) paste(sample(letters, sample(1:10, 1)), collapse = "") + ) + obj <- Filter$new(rejectValues = randomList) + expect_is(obj, "Filter") }) test_that("toList works", { diff --git a/tests/testthat/test-GatheringEvent.r b/tests/testthat/test-GatheringEvent.r index 5a15977..a5a0319 100644 --- a/tests/testthat/test-GatheringEvent.r +++ b/tests/testthat/test-GatheringEvent.r @@ -1,12 +1,197 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class GatheringEvent") test_that("Constructor works", { obj <- GatheringEvent$new() expect_is(obj, "GatheringEvent") + + # test constructor with random arguments + # test field projectTitle, type character + obj <- GatheringEvent$new( + projectTitle = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "GatheringEvent") + # test field worldRegion, type character + obj <- GatheringEvent$new( + worldRegion = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "GatheringEvent") + # test field continent, type character + obj <- GatheringEvent$new( + continent = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "GatheringEvent") + # test field country, type character + obj <- GatheringEvent$new( + country = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "GatheringEvent") + # test field iso3166Code, type character + obj <- GatheringEvent$new( + iso3166Code = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "GatheringEvent") + # test field provinceState, type character + obj <- GatheringEvent$new( + provinceState = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "GatheringEvent") + # test field island, type character + obj <- GatheringEvent$new( + island = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "GatheringEvent") + # test field locality, type character + obj <- GatheringEvent$new( + locality = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "GatheringEvent") + # test field city, type character + obj <- GatheringEvent$new( + city = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "GatheringEvent") + # test field sublocality, type character + obj <- GatheringEvent$new( + sublocality = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "GatheringEvent") + # test field localityText, type character + obj <- GatheringEvent$new( + localityText = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "GatheringEvent") + # test field dateTimeBegin, type character + randomDate <- as.character(sample(seq(as.Date("1600/01/01"), + as.Date("2018/06/04"), + by = "day" + ), 1)) + obj <- GatheringEvent$new(dateTimeBegin = randomDate) + expect_is(obj, "GatheringEvent") + # test field dateTimeEnd, type character + randomDate <- as.character(sample(seq(as.Date("1600/01/01"), + as.Date("2018/06/04"), + by = "day" + ), 1)) + obj <- GatheringEvent$new(dateTimeEnd = randomDate) + expect_is(obj, "GatheringEvent") + # test field method, type character + obj <- GatheringEvent$new( + method = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "GatheringEvent") + # test field altitude, type character + obj <- GatheringEvent$new( + altitude = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "GatheringEvent") + # test field altitudeUnifOfMeasurement, type character + obj <- GatheringEvent$new( + altitudeUnifOfMeasurement = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "GatheringEvent") + # test field biotopeText, type character + obj <- GatheringEvent$new( + biotopeText = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "GatheringEvent") + # test field depth, type character + obj <- GatheringEvent$new( + depth = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "GatheringEvent") + # test field depthUnitOfMeasurement, type character + obj <- GatheringEvent$new( + depthUnitOfMeasurement = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "GatheringEvent") + # test field gatheringPersons, type list, datatype Person + lst <- lapply(1:sample(1:10, 1), function(x) Person$new()) + obj <- GatheringEvent$new(gatheringPersons = lst) + expect_is(obj, "GatheringEvent") + # test field gatheringOrganizations, type list, datatype Organization + lst <- lapply(1:sample(1:10, 1), function(x) Organization$new()) + obj <- GatheringEvent$new(gatheringOrganizations = lst) + expect_is(obj, "GatheringEvent") + # test field siteCoordinates, type list, datatype GatheringSiteCoordinates + lst <- lapply(1:sample(1:10, 1), function(x) GatheringSiteCoordinates$new()) + obj <- GatheringEvent$new(siteCoordinates = lst) + expect_is(obj, "GatheringEvent") + # test field namedAreas, type list, datatype NamedArea + lst <- lapply(1:sample(1:10, 1), function(x) NamedArea$new()) + obj <- GatheringEvent$new(namedAreas = lst) + expect_is(obj, "GatheringEvent") + # test field associatedTaxa, type list, datatype AssociatedTaxon + lst <- lapply(1:sample(1:10, 1), function(x) AssociatedTaxon$new()) + obj <- GatheringEvent$new(associatedTaxa = lst) + expect_is(obj, "GatheringEvent") + # test field chronoStratigraphy, type list, datatype ChronoStratigraphy + lst <- lapply(1:sample(1:10, 1), function(x) ChronoStratigraphy$new()) + obj <- GatheringEvent$new(chronoStratigraphy = lst) + expect_is(obj, "GatheringEvent") + # test field lithoStratigraphy, type list, datatype LithoStratigraphy + lst <- lapply(1:sample(1:10, 1), function(x) LithoStratigraphy$new()) + obj <- GatheringEvent$new(lithoStratigraphy = lst) + expect_is(obj, "GatheringEvent") + # test field bioStratigraphic, type list, datatype BioStratigraphy + lst <- lapply(1:sample(1:10, 1), function(x) BioStratigraphy$new()) + obj <- GatheringEvent$new(bioStratigraphic = lst) + expect_is(obj, "GatheringEvent") }) test_that("toList works", { diff --git a/tests/testthat/test-GatheringSiteCoordinates.r b/tests/testthat/test-GatheringSiteCoordinates.r index 8b31298..452eb6a 100644 --- a/tests/testthat/test-GatheringSiteCoordinates.r +++ b/tests/testthat/test-GatheringSiteCoordinates.r @@ -1,12 +1,54 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class GatheringSiteCoordinates") test_that("Constructor works", { obj <- GatheringSiteCoordinates$new() expect_is(obj, "GatheringSiteCoordinates") + + # test constructor with random arguments + # test field longitudeDecimal, type numeric + obj <- GatheringSiteCoordinates$new(longitudeDecimal = runif(1)) + expect_is(obj, "GatheringSiteCoordinates") + # test field latitudeDecimal, type numeric + obj <- GatheringSiteCoordinates$new(latitudeDecimal = runif(1)) + expect_is(obj, "GatheringSiteCoordinates") + # test field gridCellSystem, type character + obj <- GatheringSiteCoordinates$new( + gridCellSystem = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "GatheringSiteCoordinates") + # test field gridLatitudeDecimal, type numeric + obj <- GatheringSiteCoordinates$new(gridLatitudeDecimal = runif(1)) + expect_is(obj, "GatheringSiteCoordinates") + # test field gridLongitudeDecimal, type numeric + obj <- GatheringSiteCoordinates$new(gridLongitudeDecimal = runif(1)) + expect_is(obj, "GatheringSiteCoordinates") + # test field gridCellCode, type character + obj <- GatheringSiteCoordinates$new( + gridCellCode = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "GatheringSiteCoordinates") + # test field gridQualifier, type character + obj <- GatheringSiteCoordinates$new( + gridQualifier = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "GatheringSiteCoordinates") + # test field geoShape, type Point + obj <- GatheringSiteCoordinates$new(geoShape = Point$new()) + expect_is(obj, "GatheringSiteCoordinates") }) test_that("toList works", { diff --git a/tests/testthat/test-GeoArea.r b/tests/testthat/test-GeoArea.r index 0ab1881..468e7c3 100644 --- a/tests/testthat/test-GeoArea.r +++ b/tests/testthat/test-GeoArea.r @@ -1,12 +1,82 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class GeoArea") test_that("Constructor works", { obj <- GeoArea$new() expect_is(obj, "GeoArea") + + # test constructor with random arguments + # test field sourceSystem, type SourceSystem + obj <- GeoArea$new(sourceSystem = SourceSystem$new()) + expect_is(obj, "GeoArea") + # test field sourceSystemId, type character + obj <- GeoArea$new( + sourceSystemId = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "GeoArea") + # test field recordURI, type character + obj <- GeoArea$new( + recordURI = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "GeoArea") + # test field id, type character + obj <- GeoArea$new( + id = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "GeoArea") + # test field areaType, type character + obj <- GeoArea$new( + areaType = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "GeoArea") + # test field locality, type character + obj <- GeoArea$new( + locality = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "GeoArea") + # test field source, type character + obj <- GeoArea$new( + source = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "GeoArea") + # test field isoCode, type character + obj <- GeoArea$new( + isoCode = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "GeoArea") + # test field countryNL, type character + obj <- GeoArea$new( + countryNL = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "GeoArea") }) test_that("toList works", { diff --git a/tests/testthat/test-GeoJsonObject.r b/tests/testthat/test-GeoJsonObject.r index 7a5295f..def372b 100644 --- a/tests/testthat/test-GeoJsonObject.r +++ b/tests/testthat/test-GeoJsonObject.r @@ -1,12 +1,25 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class GeoJsonObject") test_that("Constructor works", { obj <- GeoJsonObject$new() expect_is(obj, "GeoJsonObject") + + # test constructor with random arguments + # test field crs, type Crs + obj <- GeoJsonObject$new(crs = Crs$new()) + expect_is(obj, "GeoJsonObject") + # test field bbox, type list, datatype numeric + randomList <- lapply( + 1:sample(5:10, 1), + function(x) paste(sample(letters, sample(1:10, 1)), collapse = "") + ) + obj <- GeoJsonObject$new(bbox = randomList) + expect_is(obj, "GeoJsonObject") }) test_that("toList works", { diff --git a/tests/testthat/test-GeometryCollection.r b/tests/testthat/test-GeometryCollection.r index e5c6c6c..b8fdd3b 100644 --- a/tests/testthat/test-GeometryCollection.r +++ b/tests/testthat/test-GeometryCollection.r @@ -1,12 +1,32 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class GeometryCollection") test_that("Constructor works", { obj <- GeometryCollection$new() expect_is(obj, "GeometryCollection") + + # test constructor with random arguments + # test field crs, type Crs + obj <- GeometryCollection$new(crs = Crs$new()) + expect_is(obj, "GeometryCollection") + # test field bbox, type list, datatype numeric + randomList <- lapply( + 1:sample(5:10, 1), + function(x) paste(sample(letters, sample(1:10, 1)), collapse = "") + ) + obj <- GeometryCollection$new(bbox = randomList) + expect_is(obj, "GeometryCollection") + # test field geometries, type list, datatype list + randomList <- lapply( + 1:sample(5:10, 1), + function(x) paste(sample(letters, sample(1:10, 1)), collapse = "") + ) + obj <- GeometryCollection$new(geometries = randomList) + expect_is(obj, "GeometryCollection") }) test_that("toList works", { diff --git a/tests/testthat/test-GroupByScientificNameQuerySpec.r b/tests/testthat/test-GroupByScientificNameQuerySpec.r index 1bba772..009c907 100644 --- a/tests/testthat/test-GroupByScientificNameQuerySpec.r +++ b/tests/testthat/test-GroupByScientificNameQuerySpec.r @@ -1,12 +1,65 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class GroupByScientificNameQuerySpec") test_that("Constructor works", { obj <- GroupByScientificNameQuerySpec$new() expect_is(obj, "GroupByScientificNameQuerySpec") + + # test constructor with random arguments + # test field fields, type list, datatype character + randomList <- lapply( + 1:sample(5:10, 1), + function(x) paste(sample(letters, sample(1:10, 1)), collapse = "") + ) + obj <- GroupByScientificNameQuerySpec$new(fields = randomList) + expect_is(obj, "GroupByScientificNameQuerySpec") + # test field conditions, type list, datatype QueryCondition + lst <- lapply(1:sample(1:10, 1), function(x) QueryCondition$new()) + obj <- GroupByScientificNameQuerySpec$new(conditions = lst) + expect_is(obj, "GroupByScientificNameQuerySpec") + # test field logicalOperator, type character + obj <- GroupByScientificNameQuerySpec$new( + logicalOperator = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "GroupByScientificNameQuerySpec") + # test field sortFields, type list, datatype SortField + lst <- lapply(1:sample(1:10, 1), function(x) SortField$new()) + obj <- GroupByScientificNameQuerySpec$new(sortFields = lst) + expect_is(obj, "GroupByScientificNameQuerySpec") + # test field from, type integer + obj <- GroupByScientificNameQuerySpec$new(from = sample(0:10, 1)) + expect_is(obj, "GroupByScientificNameQuerySpec") + # test field size, type integer + obj <- GroupByScientificNameQuerySpec$new(size = sample(0:10, 1)) + expect_is(obj, "GroupByScientificNameQuerySpec") + # test field groupSort, type character + obj <- GroupByScientificNameQuerySpec$new( + groupSort = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "GroupByScientificNameQuerySpec") + # test field groupFilter, type Filter + obj <- GroupByScientificNameQuerySpec$new(groupFilter = Filter$new()) + expect_is(obj, "GroupByScientificNameQuerySpec") + # test field specimensFrom, type integer + obj <- GroupByScientificNameQuerySpec$new(specimensFrom = sample(0:10, 1)) + expect_is(obj, "GroupByScientificNameQuerySpec") + # test field specimensSize, type integer + obj <- GroupByScientificNameQuerySpec$new(specimensSize = sample(0:10, 1)) + expect_is(obj, "GroupByScientificNameQuerySpec") + # test field specimensSortFields, type list, datatype SortField + lst <- lapply(1:sample(1:10, 1), function(x) SortField$new()) + obj <- GroupByScientificNameQuerySpec$new(specimensSortFields = lst) + expect_is(obj, "GroupByScientificNameQuerySpec") }) test_that("toList works", { diff --git a/tests/testthat/test-Iptc4xmpExt.r b/tests/testthat/test-Iptc4xmpExt.r index ec073d8..d4ed728 100644 --- a/tests/testthat/test-Iptc4xmpExt.r +++ b/tests/testthat/test-Iptc4xmpExt.r @@ -1,12 +1,71 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class Iptc4xmpExt") test_that("Constructor works", { obj <- Iptc4xmpExt$new() expect_is(obj, "Iptc4xmpExt") + + # test constructor with random arguments + # test field locationShown, type character + obj <- Iptc4xmpExt$new( + locationShown = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Iptc4xmpExt") + # test field worldRegion, type character + obj <- Iptc4xmpExt$new( + worldRegion = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Iptc4xmpExt") + # test field countryCode, type character + obj <- Iptc4xmpExt$new( + countryCode = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Iptc4xmpExt") + # test field countryName, type character + obj <- Iptc4xmpExt$new( + countryName = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Iptc4xmpExt") + # test field provinceState, type character + obj <- Iptc4xmpExt$new( + provinceState = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Iptc4xmpExt") + # test field city, type character + obj <- Iptc4xmpExt$new( + city = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Iptc4xmpExt") + # test field sublocation, type character + obj <- Iptc4xmpExt$new( + sublocation = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Iptc4xmpExt") }) test_that("toList works", { diff --git a/tests/testthat/test-LineString.r b/tests/testthat/test-LineString.r index eaf0ab6..8d05c52 100644 --- a/tests/testthat/test-LineString.r +++ b/tests/testthat/test-LineString.r @@ -1,12 +1,29 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class LineString") test_that("Constructor works", { obj <- LineString$new() expect_is(obj, "LineString") + + # test constructor with random arguments + # test field crs, type Crs + obj <- LineString$new(crs = Crs$new()) + expect_is(obj, "LineString") + # test field bbox, type list, datatype numeric + randomList <- lapply( + 1:sample(5:10, 1), + function(x) paste(sample(letters, sample(1:10, 1)), collapse = "") + ) + obj <- LineString$new(bbox = randomList) + expect_is(obj, "LineString") + # test field coordinates, type list, datatype LngLatAlt + lst <- lapply(1:sample(1:10, 1), function(x) LngLatAlt$new()) + obj <- LineString$new(coordinates = lst) + expect_is(obj, "LineString") }) test_that("toList works", { diff --git a/tests/testthat/test-LithoStratigraphy.r b/tests/testthat/test-LithoStratigraphy.r index dec701f..af6efc0 100644 --- a/tests/testthat/test-LithoStratigraphy.r +++ b/tests/testthat/test-LithoStratigraphy.r @@ -1,12 +1,143 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class LithoStratigraphy") test_that("Constructor works", { obj <- LithoStratigraphy$new() expect_is(obj, "LithoStratigraphy") + + # test constructor with random arguments + # test field qualifier, type character + obj <- LithoStratigraphy$new( + qualifier = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "LithoStratigraphy") + # test field member2, type character + obj <- LithoStratigraphy$new( + member2 = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "LithoStratigraphy") + # test field member, type character + obj <- LithoStratigraphy$new( + member = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "LithoStratigraphy") + # test field informalName2, type character + obj <- LithoStratigraphy$new( + informalName2 = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "LithoStratigraphy") + # test field informalName, type character + obj <- LithoStratigraphy$new( + informalName = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "LithoStratigraphy") + # test field importedName2, type character + obj <- LithoStratigraphy$new( + importedName2 = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "LithoStratigraphy") + # test field importedName1, type character + obj <- LithoStratigraphy$new( + importedName1 = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "LithoStratigraphy") + # test field lithoIdentifier, type character + obj <- LithoStratigraphy$new( + lithoIdentifier = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "LithoStratigraphy") + # test field formation2, type character + obj <- LithoStratigraphy$new( + formation2 = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "LithoStratigraphy") + # test field formationGroup2, type character + obj <- LithoStratigraphy$new( + formationGroup2 = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "LithoStratigraphy") + # test field formationGroup, type character + obj <- LithoStratigraphy$new( + formationGroup = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "LithoStratigraphy") + # test field formation, type character + obj <- LithoStratigraphy$new( + formation = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "LithoStratigraphy") + # test field certainty2, type character + obj <- LithoStratigraphy$new( + certainty2 = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "LithoStratigraphy") + # test field certainty, type character + obj <- LithoStratigraphy$new( + certainty = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "LithoStratigraphy") + # test field bed2, type character + obj <- LithoStratigraphy$new( + bed2 = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "LithoStratigraphy") + # test field bed, type character + obj <- LithoStratigraphy$new( + bed = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "LithoStratigraphy") }) test_that("toList works", { diff --git a/tests/testthat/test-LngLatAlt.r b/tests/testthat/test-LngLatAlt.r index 24ed2c8..6ec8b44 100644 --- a/tests/testthat/test-LngLatAlt.r +++ b/tests/testthat/test-LngLatAlt.r @@ -1,12 +1,31 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class LngLatAlt") test_that("Constructor works", { obj <- LngLatAlt$new() expect_is(obj, "LngLatAlt") + + # test constructor with random arguments + # test field longitude, type numeric + obj <- LngLatAlt$new(longitude = runif(1)) + expect_is(obj, "LngLatAlt") + # test field latitude, type numeric + obj <- LngLatAlt$new(latitude = runif(1)) + expect_is(obj, "LngLatAlt") + # test field altitude, type numeric + obj <- LngLatAlt$new(altitude = runif(1)) + expect_is(obj, "LngLatAlt") + # test field additionalElements, type list, datatype numeric + randomList <- lapply( + 1:sample(5:10, 1), + function(x) paste(sample(letters, sample(1:10, 1)), collapse = "") + ) + obj <- LngLatAlt$new(additionalElements = randomList) + expect_is(obj, "LngLatAlt") }) test_that("toList works", { diff --git a/tests/testthat/test-Monomial.r b/tests/testthat/test-Monomial.r index 345d2c4..f1c04dd 100644 --- a/tests/testthat/test-Monomial.r +++ b/tests/testthat/test-Monomial.r @@ -1,12 +1,31 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class Monomial") test_that("Constructor works", { obj <- Monomial$new() expect_is(obj, "Monomial") + + # test constructor with random arguments + # test field rank, type character + obj <- Monomial$new( + rank = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Monomial") + # test field name, type character + obj <- Monomial$new( + name = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Monomial") }) test_that("toList works", { diff --git a/tests/testthat/test-MultiLineString.r b/tests/testthat/test-MultiLineString.r index d987f72..208f9c7 100644 --- a/tests/testthat/test-MultiLineString.r +++ b/tests/testthat/test-MultiLineString.r @@ -1,12 +1,32 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class MultiLineString") test_that("Constructor works", { obj <- MultiLineString$new() expect_is(obj, "MultiLineString") + + # test constructor with random arguments + # test field crs, type Crs + obj <- MultiLineString$new(crs = Crs$new()) + expect_is(obj, "MultiLineString") + # test field bbox, type list, datatype numeric + randomList <- lapply( + 1:sample(5:10, 1), + function(x) paste(sample(letters, sample(1:10, 1)), collapse = "") + ) + obj <- MultiLineString$new(bbox = randomList) + expect_is(obj, "MultiLineString") + # test field coordinates, type list, datatype LngLatAlt + randomList <- lapply( + 1:sample(5:10, 1), + function(x) paste(sample(letters, sample(1:10, 1)), collapse = "") + ) + obj <- MultiLineString$new(coordinates = randomList) + expect_is(obj, "MultiLineString") }) test_that("toList works", { diff --git a/tests/testthat/test-MultiMediaContentIdentification.r b/tests/testthat/test-MultiMediaContentIdentification.r index 228889c..fa4db00 100644 --- a/tests/testthat/test-MultiMediaContentIdentification.r +++ b/tests/testthat/test-MultiMediaContentIdentification.r @@ -1,12 +1,67 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class MultiMediaContentIdentification") test_that("Constructor works", { obj <- MultiMediaContentIdentification$new() expect_is(obj, "MultiMediaContentIdentification") + + # test constructor with random arguments + # test field taxonRank, type character + obj <- MultiMediaContentIdentification$new( + taxonRank = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "MultiMediaContentIdentification") + # test field scientificName, type ScientificName + obj <- MultiMediaContentIdentification$new(scientificName = ScientificName$new()) + expect_is(obj, "MultiMediaContentIdentification") + # test field typeStatus, type character + obj <- MultiMediaContentIdentification$new( + typeStatus = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "MultiMediaContentIdentification") + # test field dateIdentified, type character + randomDate <- as.character(sample(seq(as.Date("1600/01/01"), + as.Date("2018/06/04"), + by = "day" + ), 1)) + obj <- MultiMediaContentIdentification$new(dateIdentified = randomDate) + expect_is(obj, "MultiMediaContentIdentification") + # test field defaultClassification, type DefaultClassification + obj <- MultiMediaContentIdentification$new(defaultClassification = DefaultClassification$new()) + expect_is(obj, "MultiMediaContentIdentification") + # test field systemClassification, type list, datatype Monomial + lst <- lapply(1:sample(1:10, 1), function(x) Monomial$new()) + obj <- MultiMediaContentIdentification$new(systemClassification = lst) + expect_is(obj, "MultiMediaContentIdentification") + # test field vernacularNames, type list, datatype VernacularName + lst <- lapply(1:sample(1:10, 1), function(x) VernacularName$new()) + obj <- MultiMediaContentIdentification$new(vernacularNames = lst) + expect_is(obj, "MultiMediaContentIdentification") + # test field identificationQualifiers, type list, datatype character + randomList <- lapply( + 1:sample(5:10, 1), + function(x) paste(sample(letters, sample(1:10, 1)), collapse = "") + ) + obj <- MultiMediaContentIdentification$new(identificationQualifiers = randomList) + expect_is(obj, "MultiMediaContentIdentification") + # test field identifiers, type list, datatype Agent + lst <- lapply(1:sample(1:10, 1), function(x) Agent$new()) + obj <- MultiMediaContentIdentification$new(identifiers = lst) + expect_is(obj, "MultiMediaContentIdentification") + # test field taxonomicEnrichments, type list, datatype TaxonomicEnrichment + lst <- lapply(1:sample(1:10, 1), function(x) TaxonomicEnrichment$new()) + obj <- MultiMediaContentIdentification$new(taxonomicEnrichments = lst) + expect_is(obj, "MultiMediaContentIdentification") }) test_that("toList works", { diff --git a/tests/testthat/test-MultiMediaGatheringEvent.r b/tests/testthat/test-MultiMediaGatheringEvent.r index fd3009b..66587f2 100644 --- a/tests/testthat/test-MultiMediaGatheringEvent.r +++ b/tests/testthat/test-MultiMediaGatheringEvent.r @@ -1,12 +1,200 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class MultiMediaGatheringEvent") test_that("Constructor works", { obj <- MultiMediaGatheringEvent$new() expect_is(obj, "MultiMediaGatheringEvent") + + # test constructor with random arguments + # test field projectTitle, type character + obj <- MultiMediaGatheringEvent$new( + projectTitle = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "MultiMediaGatheringEvent") + # test field worldRegion, type character + obj <- MultiMediaGatheringEvent$new( + worldRegion = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "MultiMediaGatheringEvent") + # test field continent, type character + obj <- MultiMediaGatheringEvent$new( + continent = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "MultiMediaGatheringEvent") + # test field country, type character + obj <- MultiMediaGatheringEvent$new( + country = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "MultiMediaGatheringEvent") + # test field iso3166Code, type character + obj <- MultiMediaGatheringEvent$new( + iso3166Code = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "MultiMediaGatheringEvent") + # test field provinceState, type character + obj <- MultiMediaGatheringEvent$new( + provinceState = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "MultiMediaGatheringEvent") + # test field island, type character + obj <- MultiMediaGatheringEvent$new( + island = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "MultiMediaGatheringEvent") + # test field locality, type character + obj <- MultiMediaGatheringEvent$new( + locality = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "MultiMediaGatheringEvent") + # test field city, type character + obj <- MultiMediaGatheringEvent$new( + city = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "MultiMediaGatheringEvent") + # test field sublocality, type character + obj <- MultiMediaGatheringEvent$new( + sublocality = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "MultiMediaGatheringEvent") + # test field localityText, type character + obj <- MultiMediaGatheringEvent$new( + localityText = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "MultiMediaGatheringEvent") + # test field dateTimeBegin, type character + randomDate <- as.character(sample(seq(as.Date("1600/01/01"), + as.Date("2018/06/04"), + by = "day" + ), 1)) + obj <- MultiMediaGatheringEvent$new(dateTimeBegin = randomDate) + expect_is(obj, "MultiMediaGatheringEvent") + # test field dateTimeEnd, type character + randomDate <- as.character(sample(seq(as.Date("1600/01/01"), + as.Date("2018/06/04"), + by = "day" + ), 1)) + obj <- MultiMediaGatheringEvent$new(dateTimeEnd = randomDate) + expect_is(obj, "MultiMediaGatheringEvent") + # test field method, type character + obj <- MultiMediaGatheringEvent$new( + method = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "MultiMediaGatheringEvent") + # test field altitude, type character + obj <- MultiMediaGatheringEvent$new( + altitude = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "MultiMediaGatheringEvent") + # test field altitudeUnifOfMeasurement, type character + obj <- MultiMediaGatheringEvent$new( + altitudeUnifOfMeasurement = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "MultiMediaGatheringEvent") + # test field biotopeText, type character + obj <- MultiMediaGatheringEvent$new( + biotopeText = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "MultiMediaGatheringEvent") + # test field depth, type character + obj <- MultiMediaGatheringEvent$new( + depth = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "MultiMediaGatheringEvent") + # test field depthUnitOfMeasurement, type character + obj <- MultiMediaGatheringEvent$new( + depthUnitOfMeasurement = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "MultiMediaGatheringEvent") + # test field gatheringPersons, type list, datatype Person + lst <- lapply(1:sample(1:10, 1), function(x) Person$new()) + obj <- MultiMediaGatheringEvent$new(gatheringPersons = lst) + expect_is(obj, "MultiMediaGatheringEvent") + # test field gatheringOrganizations, type list, datatype Organization + lst <- lapply(1:sample(1:10, 1), function(x) Organization$new()) + obj <- MultiMediaGatheringEvent$new(gatheringOrganizations = lst) + expect_is(obj, "MultiMediaGatheringEvent") + # test field siteCoordinates, type list, datatype GatheringSiteCoordinates + lst <- lapply(1:sample(1:10, 1), function(x) GatheringSiteCoordinates$new()) + obj <- MultiMediaGatheringEvent$new(siteCoordinates = lst) + expect_is(obj, "MultiMediaGatheringEvent") + # test field namedAreas, type list, datatype NamedArea + lst <- lapply(1:sample(1:10, 1), function(x) NamedArea$new()) + obj <- MultiMediaGatheringEvent$new(namedAreas = lst) + expect_is(obj, "MultiMediaGatheringEvent") + # test field associatedTaxa, type list, datatype AssociatedTaxon + lst <- lapply(1:sample(1:10, 1), function(x) AssociatedTaxon$new()) + obj <- MultiMediaGatheringEvent$new(associatedTaxa = lst) + expect_is(obj, "MultiMediaGatheringEvent") + # test field chronoStratigraphy, type list, datatype ChronoStratigraphy + lst <- lapply(1:sample(1:10, 1), function(x) ChronoStratigraphy$new()) + obj <- MultiMediaGatheringEvent$new(chronoStratigraphy = lst) + expect_is(obj, "MultiMediaGatheringEvent") + # test field lithoStratigraphy, type list, datatype LithoStratigraphy + lst <- lapply(1:sample(1:10, 1), function(x) LithoStratigraphy$new()) + obj <- MultiMediaGatheringEvent$new(lithoStratigraphy = lst) + expect_is(obj, "MultiMediaGatheringEvent") + # test field iptc, type Iptc4xmpExt + obj <- MultiMediaGatheringEvent$new(iptc = Iptc4xmpExt$new()) + expect_is(obj, "MultiMediaGatheringEvent") + # test field bioStratigraphic, type list, datatype BioStratigraphy + lst <- lapply(1:sample(1:10, 1), function(x) BioStratigraphy$new()) + obj <- MultiMediaGatheringEvent$new(bioStratigraphic = lst) + expect_is(obj, "MultiMediaGatheringEvent") }) test_that("toList works", { diff --git a/tests/testthat/test-MultiMediaObject.r b/tests/testthat/test-MultiMediaObject.r index 6588651..8e8a2f1 100644 --- a/tests/testthat/test-MultiMediaObject.r +++ b/tests/testthat/test-MultiMediaObject.r @@ -1,12 +1,218 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class MultiMediaObject") test_that("Constructor works", { obj <- MultiMediaObject$new() expect_is(obj, "MultiMediaObject") + + # test constructor with random arguments + # test field sourceSystem, type SourceSystem + obj <- MultiMediaObject$new(sourceSystem = SourceSystem$new()) + expect_is(obj, "MultiMediaObject") + # test field sourceSystemId, type character + obj <- MultiMediaObject$new( + sourceSystemId = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "MultiMediaObject") + # test field recordURI, type character + obj <- MultiMediaObject$new( + recordURI = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "MultiMediaObject") + # test field id, type character + obj <- MultiMediaObject$new( + id = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "MultiMediaObject") + # test field sourceInstitutionID, type character + obj <- MultiMediaObject$new( + sourceInstitutionID = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "MultiMediaObject") + # test field sourceID, type character + obj <- MultiMediaObject$new( + sourceID = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "MultiMediaObject") + # test field owner, type character + obj <- MultiMediaObject$new( + owner = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "MultiMediaObject") + # test field licenseType, type character + obj <- MultiMediaObject$new( + licenseType = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "MultiMediaObject") + # test field license, type character + obj <- MultiMediaObject$new( + license = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "MultiMediaObject") + # test field unitID, type character + obj <- MultiMediaObject$new( + unitID = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "MultiMediaObject") + # test field collectionType, type character + obj <- MultiMediaObject$new( + collectionType = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "MultiMediaObject") + # test field title, type character + obj <- MultiMediaObject$new( + title = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "MultiMediaObject") + # test field caption, type character + obj <- MultiMediaObject$new( + caption = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "MultiMediaObject") + # test field description, type character + obj <- MultiMediaObject$new( + description = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "MultiMediaObject") + # test field serviceAccessPoints, type list, datatype ServiceAccessPoint + lst <- lapply(1:sample(1:10, 1), function(x) ServiceAccessPoint$new()) + obj <- MultiMediaObject$new(serviceAccessPoints = lst) + expect_is(obj, "MultiMediaObject") + # test field type, type character + obj <- MultiMediaObject$new( + type = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "MultiMediaObject") + # test field taxonCount, type integer + obj <- MultiMediaObject$new(taxonCount = sample(0:10, 1)) + expect_is(obj, "MultiMediaObject") + # test field creator, type character + obj <- MultiMediaObject$new( + creator = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "MultiMediaObject") + # test field copyrightText, type character + obj <- MultiMediaObject$new( + copyrightText = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "MultiMediaObject") + # test field associatedSpecimenReference, type character + obj <- MultiMediaObject$new( + associatedSpecimenReference = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "MultiMediaObject") + # test field associatedTaxonReference, type character + obj <- MultiMediaObject$new( + associatedTaxonReference = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "MultiMediaObject") + # test field subjectParts, type list, datatype character + randomList <- lapply( + 1:sample(5:10, 1), + function(x) paste(sample(letters, sample(1:10, 1)), collapse = "") + ) + obj <- MultiMediaObject$new(subjectParts = randomList) + expect_is(obj, "MultiMediaObject") + # test field subjectOrientations, type list, datatype character + randomList <- lapply( + 1:sample(5:10, 1), + function(x) paste(sample(letters, sample(1:10, 1)), collapse = "") + ) + obj <- MultiMediaObject$new(subjectOrientations = randomList) + expect_is(obj, "MultiMediaObject") + # test field phasesOrStages, type list, datatype character + randomList <- lapply( + 1:sample(5:10, 1), + function(x) paste(sample(letters, sample(1:10, 1)), collapse = "") + ) + obj <- MultiMediaObject$new(phasesOrStages = randomList) + expect_is(obj, "MultiMediaObject") + # test field sexes, type list, datatype character + randomList <- lapply( + 1:sample(5:10, 1), + function(x) paste(sample(letters, sample(1:10, 1)), collapse = "") + ) + obj <- MultiMediaObject$new(sexes = randomList) + expect_is(obj, "MultiMediaObject") + # test field gatheringEvents, type list, datatype MultiMediaGatheringEvent + lst <- lapply(1:sample(1:10, 1), function(x) MultiMediaGatheringEvent$new()) + obj <- MultiMediaObject$new(gatheringEvents = lst) + expect_is(obj, "MultiMediaObject") + # test field identifications, type list, datatype MultiMediaContentIdentification + lst <- lapply(1:sample(1:10, 1), function(x) MultiMediaContentIdentification$new()) + obj <- MultiMediaObject$new(identifications = lst) + expect_is(obj, "MultiMediaObject") + # test field theme, type list, datatype character + randomList <- lapply( + 1:sample(5:10, 1), + function(x) paste(sample(letters, sample(1:10, 1)), collapse = "") + ) + obj <- MultiMediaObject$new(theme = randomList) + expect_is(obj, "MultiMediaObject") + # test field associatedSpecimen, type Specimen + obj <- MultiMediaObject$new(associatedSpecimen = Specimen$new()) + expect_is(obj, "MultiMediaObject") + # test field associatedTaxon, type Taxon + obj <- MultiMediaObject$new(associatedTaxon = Taxon$new()) + expect_is(obj, "MultiMediaObject") }) test_that("toList works", { diff --git a/tests/testthat/test-MultiPoint.r b/tests/testthat/test-MultiPoint.r index 35e5168..682000d 100644 --- a/tests/testthat/test-MultiPoint.r +++ b/tests/testthat/test-MultiPoint.r @@ -1,12 +1,29 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class MultiPoint") test_that("Constructor works", { obj <- MultiPoint$new() expect_is(obj, "MultiPoint") + + # test constructor with random arguments + # test field crs, type Crs + obj <- MultiPoint$new(crs = Crs$new()) + expect_is(obj, "MultiPoint") + # test field bbox, type list, datatype numeric + randomList <- lapply( + 1:sample(5:10, 1), + function(x) paste(sample(letters, sample(1:10, 1)), collapse = "") + ) + obj <- MultiPoint$new(bbox = randomList) + expect_is(obj, "MultiPoint") + # test field coordinates, type list, datatype LngLatAlt + lst <- lapply(1:sample(1:10, 1), function(x) LngLatAlt$new()) + obj <- MultiPoint$new(coordinates = lst) + expect_is(obj, "MultiPoint") }) test_that("toList works", { diff --git a/tests/testthat/test-MultiPolygon.r b/tests/testthat/test-MultiPolygon.r index 81776b1..a9bb506 100644 --- a/tests/testthat/test-MultiPolygon.r +++ b/tests/testthat/test-MultiPolygon.r @@ -1,12 +1,32 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class MultiPolygon") test_that("Constructor works", { obj <- MultiPolygon$new() expect_is(obj, "MultiPolygon") + + # test constructor with random arguments + # test field crs, type Crs + obj <- MultiPolygon$new(crs = Crs$new()) + expect_is(obj, "MultiPolygon") + # test field bbox, type list, datatype numeric + randomList <- lapply( + 1:sample(5:10, 1), + function(x) paste(sample(letters, sample(1:10, 1)), collapse = "") + ) + obj <- MultiPolygon$new(bbox = randomList) + expect_is(obj, "MultiPolygon") + # test field coordinates, type list, datatype LngLatAlt + randomList <- lapply( + 1:sample(5:10, 1), + function(x) paste(sample(letters, sample(1:10, 1)), collapse = "") + ) + obj <- MultiPolygon$new(coordinates = randomList) + expect_is(obj, "MultiPolygon") }) test_that("toList works", { diff --git a/tests/testthat/test-NamedArea.r b/tests/testthat/test-NamedArea.r index 2c0957b..f9489c9 100644 --- a/tests/testthat/test-NamedArea.r +++ b/tests/testthat/test-NamedArea.r @@ -1,12 +1,31 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class NamedArea") test_that("Constructor works", { obj <- NamedArea$new() expect_is(obj, "NamedArea") + + # test constructor with random arguments + # test field areaClass, type character + obj <- NamedArea$new( + areaClass = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "NamedArea") + # test field areaName, type character + obj <- NamedArea$new( + areaName = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "NamedArea") }) test_that("toList works", { diff --git a/tests/testthat/test-Organization.r b/tests/testthat/test-Organization.r index ac5743e..0178c58 100644 --- a/tests/testthat/test-Organization.r +++ b/tests/testthat/test-Organization.r @@ -1,12 +1,31 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class Organization") test_that("Constructor works", { obj <- Organization$new() expect_is(obj, "Organization") + + # test constructor with random arguments + # test field agentText, type character + obj <- Organization$new( + agentText = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Organization") + # test field name, type character + obj <- Organization$new( + name = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Organization") }) test_that("toList works", { diff --git a/tests/testthat/test-Path.r b/tests/testthat/test-Path.r index c51de59..a1032d5 100644 --- a/tests/testthat/test-Path.r +++ b/tests/testthat/test-Path.r @@ -1,12 +1,15 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class Path") test_that("Constructor works", { obj <- Path$new() expect_is(obj, "Path") + + # test constructor with random arguments }) test_that("toList works", { diff --git a/tests/testthat/test-Person.r b/tests/testthat/test-Person.r index caf7dd6..4e0fa12 100644 --- a/tests/testthat/test-Person.r +++ b/tests/testthat/test-Person.r @@ -1,12 +1,34 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class Person") test_that("Constructor works", { obj <- Person$new() expect_is(obj, "Person") + + # test constructor with random arguments + # test field agentText, type character + obj <- Person$new( + agentText = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Person") + # test field fullName, type character + obj <- Person$new( + fullName = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Person") + # test field organization, type Organization + obj <- Person$new(organization = Organization$new()) + expect_is(obj, "Person") }) test_that("toList works", { diff --git a/tests/testthat/test-Point.r b/tests/testthat/test-Point.r index 3293a23..75ed694 100644 --- a/tests/testthat/test-Point.r +++ b/tests/testthat/test-Point.r @@ -1,12 +1,28 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class Point") test_that("Constructor works", { obj <- Point$new() expect_is(obj, "Point") + + # test constructor with random arguments + # test field crs, type Crs + obj <- Point$new(crs = Crs$new()) + expect_is(obj, "Point") + # test field bbox, type list, datatype numeric + randomList <- lapply( + 1:sample(5:10, 1), + function(x) paste(sample(letters, sample(1:10, 1)), collapse = "") + ) + obj <- Point$new(bbox = randomList) + expect_is(obj, "Point") + # test field coordinates, type LngLatAlt + obj <- Point$new(coordinates = LngLatAlt$new()) + expect_is(obj, "Point") }) test_that("toList works", { diff --git a/tests/testthat/test-Polygon.r b/tests/testthat/test-Polygon.r index 366bc51..171985a 100644 --- a/tests/testthat/test-Polygon.r +++ b/tests/testthat/test-Polygon.r @@ -1,12 +1,32 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class Polygon") test_that("Constructor works", { obj <- Polygon$new() expect_is(obj, "Polygon") + + # test constructor with random arguments + # test field crs, type Crs + obj <- Polygon$new(crs = Crs$new()) + expect_is(obj, "Polygon") + # test field bbox, type list, datatype numeric + randomList <- lapply( + 1:sample(5:10, 1), + function(x) paste(sample(letters, sample(1:10, 1)), collapse = "") + ) + obj <- Polygon$new(bbox = randomList) + expect_is(obj, "Polygon") + # test field coordinates, type list, datatype LngLatAlt + randomList <- lapply( + 1:sample(5:10, 1), + function(x) paste(sample(letters, sample(1:10, 1)), collapse = "") + ) + obj <- Polygon$new(coordinates = randomList) + expect_is(obj, "Polygon") }) test_that("toList works", { diff --git a/tests/testthat/test-QueryCondition.r b/tests/testthat/test-QueryCondition.r index 0521621..5f9742f 100644 --- a/tests/testthat/test-QueryCondition.r +++ b/tests/testthat/test-QueryCondition.r @@ -1,12 +1,42 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class QueryCondition") test_that("Constructor works", { obj <- QueryCondition$new() expect_is(obj, "QueryCondition") + + # test constructor with random arguments + # test field not, type character + obj <- QueryCondition$new( + not = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "QueryCondition") + # test field operator, type character + obj <- QueryCondition$new( + operator = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "QueryCondition") + # test field and, type list, datatype QueryCondition + lst <- lapply(1:sample(1:10, 1), function(x) QueryCondition$new()) + obj <- QueryCondition$new(and = lst) + expect_is(obj, "QueryCondition") + # test field or, type list, datatype QueryCondition + lst <- lapply(1:sample(1:10, 1), function(x) QueryCondition$new()) + obj <- QueryCondition$new(or = lst) + expect_is(obj, "QueryCondition") + # test field boost, type numeric + obj <- QueryCondition$new(boost = runif(1)) + expect_is(obj, "QueryCondition") }) test_that("toList works", { diff --git a/tests/testthat/test-QueryResult.r b/tests/testthat/test-QueryResult.r index de7802b..fafc898 100644 --- a/tests/testthat/test-QueryResult.r +++ b/tests/testthat/test-QueryResult.r @@ -1,12 +1,22 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class QueryResult") test_that("Constructor works", { obj <- QueryResult$new() expect_is(obj, "QueryResult") + + # test constructor with random arguments + # test field totalSize, type integer + obj <- QueryResult$new(totalSize = runif(1)) + expect_is(obj, "QueryResult") + # test field resultSet, type list, datatype QueryResultItemObject + lst <- lapply(1:sample(1:10, 1), function(x) QueryResultItemObject$new()) + obj <- QueryResult$new(resultSet = lst) + expect_is(obj, "QueryResult") }) test_that("toList works", { diff --git a/tests/testthat/test-QueryResultItem.r b/tests/testthat/test-QueryResultItem.r index 010c44f..07b8d78 100644 --- a/tests/testthat/test-QueryResultItem.r +++ b/tests/testthat/test-QueryResultItem.r @@ -1,12 +1,18 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class QueryResultItem") test_that("Constructor works", { obj <- QueryResultItem$new() expect_is(obj, "QueryResultItem") + + # test constructor with random arguments + # test field score, type numeric + obj <- QueryResultItem$new(score = runif(1)) + expect_is(obj, "QueryResultItem") }) test_that("toList works", { diff --git a/tests/testthat/test-QueryResultItemObject.r b/tests/testthat/test-QueryResultItemObject.r index dbd11ae..39e2818 100644 --- a/tests/testthat/test-QueryResultItemObject.r +++ b/tests/testthat/test-QueryResultItemObject.r @@ -1,12 +1,18 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class QueryResultItemObject") test_that("Constructor works", { obj <- QueryResultItemObject$new() expect_is(obj, "QueryResultItemObject") + + # test constructor with random arguments + # test field score, type numeric + obj <- QueryResultItemObject$new(score = runif(1)) + expect_is(obj, "QueryResultItemObject") }) test_that("toList works", { diff --git a/tests/testthat/test-QuerySpec.r b/tests/testthat/test-QuerySpec.r index 4b2d881..7b1d633 100644 --- a/tests/testthat/test-QuerySpec.r +++ b/tests/testthat/test-QuerySpec.r @@ -1,12 +1,44 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class QuerySpec") test_that("Constructor works", { obj <- QuerySpec$new() expect_is(obj, "QuerySpec") + + # test constructor with random arguments + # test field fields, type list, datatype character + randomList <- lapply( + 1:sample(5:10, 1), + function(x) paste(sample(letters, sample(1:10, 1)), collapse = "") + ) + obj <- QuerySpec$new(fields = randomList) + expect_is(obj, "QuerySpec") + # test field conditions, type list, datatype QueryCondition + lst <- lapply(1:sample(1:10, 1), function(x) QueryCondition$new()) + obj <- QuerySpec$new(conditions = lst) + expect_is(obj, "QuerySpec") + # test field logicalOperator, type character + obj <- QuerySpec$new( + logicalOperator = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "QuerySpec") + # test field sortFields, type list, datatype SortField + lst <- lapply(1:sample(1:10, 1), function(x) SortField$new()) + obj <- QuerySpec$new(sortFields = lst) + expect_is(obj, "QuerySpec") + # test field from, type integer + obj <- QuerySpec$new(from = sample(0:10, 1)) + expect_is(obj, "QuerySpec") + # test field size, type integer + obj <- QuerySpec$new(size = sample(0:10, 1)) + expect_is(obj, "QuerySpec") }) test_that("toList works", { diff --git a/tests/testthat/test-Reference.r b/tests/testthat/test-Reference.r index 7104748..c9e626d 100644 --- a/tests/testthat/test-Reference.r +++ b/tests/testthat/test-Reference.r @@ -1,12 +1,49 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class Reference") test_that("Constructor works", { obj <- Reference$new() expect_is(obj, "Reference") + + # test constructor with random arguments + # test field titleCitation, type character + obj <- Reference$new( + titleCitation = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Reference") + # test field citationDetail, type character + obj <- Reference$new( + citationDetail = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Reference") + # test field uri, type character + obj <- Reference$new( + uri = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Reference") + # test field author, type Person + obj <- Reference$new(author = Person$new()) + expect_is(obj, "Reference") + # test field publicationDate, type character + randomDate <- as.character(sample(seq(as.Date("1600/01/01"), + as.Date("2018/06/04"), + by = "day" + ), 1)) + obj <- Reference$new(publicationDate = randomDate) + expect_is(obj, "Reference") }) test_that("toList works", { diff --git a/tests/testthat/test-RestService.r b/tests/testthat/test-RestService.r index 24b6e0d..30562ef 100644 --- a/tests/testthat/test-RestService.r +++ b/tests/testthat/test-RestService.r @@ -1,12 +1,55 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class RestService") test_that("Constructor works", { obj <- RestService$new() expect_is(obj, "RestService") + + # test constructor with random arguments + # test field endPoint, type character + obj <- RestService$new( + endPoint = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "RestService") + # test field method, type character + obj <- RestService$new( + method = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "RestService") + # test field consumes, type character + obj <- RestService$new( + consumes = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "RestService") + # test field produces, type character + obj <- RestService$new( + produces = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "RestService") + # test field url, type character + obj <- RestService$new( + url = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "RestService") }) test_that("toList works", { diff --git a/tests/testthat/test-ScientificName.r b/tests/testthat/test-ScientificName.r index 359f36d..194f541 100644 --- a/tests/testthat/test-ScientificName.r +++ b/tests/testthat/test-ScientificName.r @@ -1,12 +1,119 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class ScientificName") test_that("Constructor works", { obj <- ScientificName$new() expect_is(obj, "ScientificName") + + # test constructor with random arguments + # test field fullScientificName, type character + obj <- ScientificName$new( + fullScientificName = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "ScientificName") + # test field taxonomicStatus, type character + obj <- ScientificName$new( + taxonomicStatus = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "ScientificName") + # test field genusOrMonomial, type character + obj <- ScientificName$new( + genusOrMonomial = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "ScientificName") + # test field subgenus, type character + obj <- ScientificName$new( + subgenus = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "ScientificName") + # test field specificEpithet, type character + obj <- ScientificName$new( + specificEpithet = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "ScientificName") + # test field infraspecificEpithet, type character + obj <- ScientificName$new( + infraspecificEpithet = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "ScientificName") + # test field infraspecificMarker, type character + obj <- ScientificName$new( + infraspecificMarker = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "ScientificName") + # test field nameAddendum, type character + obj <- ScientificName$new( + nameAddendum = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "ScientificName") + # test field authorshipVerbatim, type character + obj <- ScientificName$new( + authorshipVerbatim = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "ScientificName") + # test field author, type character + obj <- ScientificName$new( + author = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "ScientificName") + # test field year, type character + obj <- ScientificName$new( + year = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "ScientificName") + # test field scientificNameGroup, type character + obj <- ScientificName$new( + scientificNameGroup = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "ScientificName") + # test field references, type list, datatype Reference + lst <- lapply(1:sample(1:10, 1), function(x) Reference$new()) + obj <- ScientificName$new(references = lst) + expect_is(obj, "ScientificName") + # test field experts, type list, datatype Expert + lst <- lapply(1:sample(1:10, 1), function(x) Expert$new()) + obj <- ScientificName$new(experts = lst) + expect_is(obj, "ScientificName") }) test_that("toList works", { diff --git a/tests/testthat/test-ServiceAccessPoint.r b/tests/testthat/test-ServiceAccessPoint.r index 2e6443a..6e76483 100644 --- a/tests/testthat/test-ServiceAccessPoint.r +++ b/tests/testthat/test-ServiceAccessPoint.r @@ -1,12 +1,39 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class ServiceAccessPoint") test_that("Constructor works", { obj <- ServiceAccessPoint$new() expect_is(obj, "ServiceAccessPoint") + + # test constructor with random arguments + # test field accessUri, type character + obj <- ServiceAccessPoint$new( + accessUri = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "ServiceAccessPoint") + # test field format, type character + obj <- ServiceAccessPoint$new( + format = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "ServiceAccessPoint") + # test field variant, type character + obj <- ServiceAccessPoint$new( + variant = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "ServiceAccessPoint") }) test_that("toList works", { diff --git a/tests/testthat/test-SortField.r b/tests/testthat/test-SortField.r index 9763ff6..760a056 100644 --- a/tests/testthat/test-SortField.r +++ b/tests/testthat/test-SortField.r @@ -1,12 +1,23 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class SortField") test_that("Constructor works", { obj <- SortField$new() expect_is(obj, "SortField") + + # test constructor with random arguments + # test field sortOrder, type character + obj <- SortField$new( + sortOrder = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "SortField") }) test_that("toList works", { diff --git a/tests/testthat/test-SourceSystem.r b/tests/testthat/test-SourceSystem.r index 09632cb..d98ce90 100644 --- a/tests/testthat/test-SourceSystem.r +++ b/tests/testthat/test-SourceSystem.r @@ -1,12 +1,31 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class SourceSystem") test_that("Constructor works", { obj <- SourceSystem$new() expect_is(obj, "SourceSystem") + + # test constructor with random arguments + # test field code, type character + obj <- SourceSystem$new( + code = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "SourceSystem") + # test field name, type character + obj <- SourceSystem$new( + name = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "SourceSystem") }) test_that("toList works", { diff --git a/tests/testthat/test-Specimen.r b/tests/testthat/test-Specimen.r index 4de91d5..ad772d9 100644 --- a/tests/testthat/test-Specimen.r +++ b/tests/testthat/test-Specimen.r @@ -1,12 +1,217 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class Specimen") test_that("Constructor works", { obj <- Specimen$new() expect_is(obj, "Specimen") + + # test constructor with random arguments + # test field sourceSystem, type SourceSystem + obj <- Specimen$new(sourceSystem = SourceSystem$new()) + expect_is(obj, "Specimen") + # test field sourceSystemId, type character + obj <- Specimen$new( + sourceSystemId = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Specimen") + # test field recordURI, type character + obj <- Specimen$new( + recordURI = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Specimen") + # test field id, type character + obj <- Specimen$new( + id = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Specimen") + # test field unitID, type character + obj <- Specimen$new( + unitID = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Specimen") + # test field unitGUID, type character + obj <- Specimen$new( + unitGUID = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Specimen") + # test field collectorsFieldNumber, type character + obj <- Specimen$new( + collectorsFieldNumber = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Specimen") + # test field assemblageID, type character + obj <- Specimen$new( + assemblageID = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Specimen") + # test field sourceInstitutionID, type character + obj <- Specimen$new( + sourceInstitutionID = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Specimen") + # test field sourceID, type character + obj <- Specimen$new( + sourceID = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Specimen") + # test field previousSourceID, type list, datatype character + randomList <- lapply( + 1:sample(5:10, 1), + function(x) paste(sample(letters, sample(1:10, 1)), collapse = "") + ) + obj <- Specimen$new(previousSourceID = randomList) + expect_is(obj, "Specimen") + # test field owner, type character + obj <- Specimen$new( + owner = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Specimen") + # test field licenseType, type character + obj <- Specimen$new( + licenseType = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Specimen") + # test field license, type character + obj <- Specimen$new( + license = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Specimen") + # test field recordBasis, type character + obj <- Specimen$new( + recordBasis = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Specimen") + # test field kindOfUnit, type character + obj <- Specimen$new( + kindOfUnit = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Specimen") + # test field collectionType, type character + obj <- Specimen$new( + collectionType = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Specimen") + # test field sex, type character + obj <- Specimen$new( + sex = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Specimen") + # test field phaseOrStage, type character + obj <- Specimen$new( + phaseOrStage = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Specimen") + # test field title, type character + obj <- Specimen$new( + title = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Specimen") + # test field notes, type character + obj <- Specimen$new( + notes = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Specimen") + # test field preparationType, type character + obj <- Specimen$new( + preparationType = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Specimen") + # test field previousUnitsText, type character + obj <- Specimen$new( + previousUnitsText = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Specimen") + # test field numberOfSpecimen, type integer + obj <- Specimen$new(numberOfSpecimen = sample(0:10, 1)) + expect_is(obj, "Specimen") + # test field acquiredFrom, type Agent + obj <- Specimen$new(acquiredFrom = Agent$new()) + expect_is(obj, "Specimen") + # test field gatheringEvent, type GatheringEvent + obj <- Specimen$new(gatheringEvent = GatheringEvent$new()) + expect_is(obj, "Specimen") + # test field identifications, type list, datatype SpecimenIdentification + lst <- lapply(1:sample(1:10, 1), function(x) SpecimenIdentification$new()) + obj <- Specimen$new(identifications = lst) + expect_is(obj, "Specimen") + # test field associatedMultiMediaUris, type list, datatype ServiceAccessPoint + lst <- lapply(1:sample(1:10, 1), function(x) ServiceAccessPoint$new()) + obj <- Specimen$new(associatedMultiMediaUris = lst) + expect_is(obj, "Specimen") + # test field theme, type list, datatype character + randomList <- lapply( + 1:sample(5:10, 1), + function(x) paste(sample(letters, sample(1:10, 1)), collapse = "") + ) + obj <- Specimen$new(theme = randomList) + expect_is(obj, "Specimen") }) test_that("toList works", { diff --git a/tests/testthat/test-SpecimenIdentification.r b/tests/testthat/test-SpecimenIdentification.r index f10fa20..dee999c 100644 --- a/tests/testthat/test-SpecimenIdentification.r +++ b/tests/testthat/test-SpecimenIdentification.r @@ -1,12 +1,115 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class SpecimenIdentification") test_that("Constructor works", { obj <- SpecimenIdentification$new() expect_is(obj, "SpecimenIdentification") + + # test constructor with random arguments + # test field taxonRank, type character + obj <- SpecimenIdentification$new( + taxonRank = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "SpecimenIdentification") + # test field scientificName, type ScientificName + obj <- SpecimenIdentification$new(scientificName = ScientificName$new()) + expect_is(obj, "SpecimenIdentification") + # test field typeStatus, type character + obj <- SpecimenIdentification$new( + typeStatus = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "SpecimenIdentification") + # test field dateIdentified, type character + randomDate <- as.character(sample(seq(as.Date("1600/01/01"), + as.Date("2018/06/04"), + by = "day" + ), 1)) + obj <- SpecimenIdentification$new(dateIdentified = randomDate) + expect_is(obj, "SpecimenIdentification") + # test field defaultClassification, type DefaultClassification + obj <- SpecimenIdentification$new(defaultClassification = DefaultClassification$new()) + expect_is(obj, "SpecimenIdentification") + # test field systemClassification, type list, datatype Monomial + lst <- lapply(1:sample(1:10, 1), function(x) Monomial$new()) + obj <- SpecimenIdentification$new(systemClassification = lst) + expect_is(obj, "SpecimenIdentification") + # test field vernacularNames, type list, datatype VernacularName + lst <- lapply(1:sample(1:10, 1), function(x) VernacularName$new()) + obj <- SpecimenIdentification$new(vernacularNames = lst) + expect_is(obj, "SpecimenIdentification") + # test field identificationQualifiers, type list, datatype character + randomList <- lapply( + 1:sample(5:10, 1), + function(x) paste(sample(letters, sample(1:10, 1)), collapse = "") + ) + obj <- SpecimenIdentification$new(identificationQualifiers = randomList) + expect_is(obj, "SpecimenIdentification") + # test field identifiers, type list, datatype Agent + lst <- lapply(1:sample(1:10, 1), function(x) Agent$new()) + obj <- SpecimenIdentification$new(identifiers = lst) + expect_is(obj, "SpecimenIdentification") + # test field taxonomicEnrichments, type list, datatype TaxonomicEnrichment + lst <- lapply(1:sample(1:10, 1), function(x) TaxonomicEnrichment$new()) + obj <- SpecimenIdentification$new(taxonomicEnrichments = lst) + expect_is(obj, "SpecimenIdentification") + # test field verificationStatus, type character + obj <- SpecimenIdentification$new( + verificationStatus = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "SpecimenIdentification") + # test field rockType, type character + obj <- SpecimenIdentification$new( + rockType = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "SpecimenIdentification") + # test field associatedFossilAssemblage, type character + obj <- SpecimenIdentification$new( + associatedFossilAssemblage = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "SpecimenIdentification") + # test field rockMineralUsage, type character + obj <- SpecimenIdentification$new( + rockMineralUsage = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "SpecimenIdentification") + # test field associatedMineralName, type character + obj <- SpecimenIdentification$new( + associatedMineralName = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "SpecimenIdentification") + # test field remarks, type character + obj <- SpecimenIdentification$new( + remarks = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "SpecimenIdentification") }) test_that("toList works", { diff --git a/tests/testthat/test-SummaryScientificName.r b/tests/testthat/test-SummaryScientificName.r index f3412d6..2520dc7 100644 --- a/tests/testthat/test-SummaryScientificName.r +++ b/tests/testthat/test-SummaryScientificName.r @@ -1,12 +1,71 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class SummaryScientificName") test_that("Constructor works", { obj <- SummaryScientificName$new() expect_is(obj, "SummaryScientificName") + + # test constructor with random arguments + # test field fullScientificName, type character + obj <- SummaryScientificName$new( + fullScientificName = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "SummaryScientificName") + # test field taxonomicStatus, type character + obj <- SummaryScientificName$new( + taxonomicStatus = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "SummaryScientificName") + # test field genusOrMonomial, type character + obj <- SummaryScientificName$new( + genusOrMonomial = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "SummaryScientificName") + # test field subgenus, type character + obj <- SummaryScientificName$new( + subgenus = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "SummaryScientificName") + # test field specificEpithet, type character + obj <- SummaryScientificName$new( + specificEpithet = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "SummaryScientificName") + # test field infraspecificEpithet, type character + obj <- SummaryScientificName$new( + infraspecificEpithet = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "SummaryScientificName") + # test field authorshipVerbatim, type character + obj <- SummaryScientificName$new( + authorshipVerbatim = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "SummaryScientificName") }) test_that("toList works", { diff --git a/tests/testthat/test-SummarySourceSystem.r b/tests/testthat/test-SummarySourceSystem.r index 100aba0..defff50 100644 --- a/tests/testthat/test-SummarySourceSystem.r +++ b/tests/testthat/test-SummarySourceSystem.r @@ -1,12 +1,23 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class SummarySourceSystem") test_that("Constructor works", { obj <- SummarySourceSystem$new() expect_is(obj, "SummarySourceSystem") + + # test constructor with random arguments + # test field code, type character + obj <- SummarySourceSystem$new( + code = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "SummarySourceSystem") }) test_that("toList works", { diff --git a/tests/testthat/test-SummaryVernacularName.r b/tests/testthat/test-SummaryVernacularName.r index 18fcc46..3c5bb43 100644 --- a/tests/testthat/test-SummaryVernacularName.r +++ b/tests/testthat/test-SummaryVernacularName.r @@ -1,12 +1,31 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class SummaryVernacularName") test_that("Constructor works", { obj <- SummaryVernacularName$new() expect_is(obj, "SummaryVernacularName") + + # test constructor with random arguments + # test field name, type character + obj <- SummaryVernacularName$new( + name = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "SummaryVernacularName") + # test field language, type character + obj <- SummaryVernacularName$new( + language = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "SummaryVernacularName") }) test_that("toList works", { diff --git a/tests/testthat/test-Taxon.r b/tests/testthat/test-Taxon.r index 69bf17b..06a49d0 100644 --- a/tests/testthat/test-Taxon.r +++ b/tests/testthat/test-Taxon.r @@ -1,12 +1,107 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class Taxon") test_that("Constructor works", { obj <- Taxon$new() expect_is(obj, "Taxon") + + # test constructor with random arguments + # test field sourceSystem, type SourceSystem + obj <- Taxon$new(sourceSystem = SourceSystem$new()) + expect_is(obj, "Taxon") + # test field sourceSystemId, type character + obj <- Taxon$new( + sourceSystemId = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Taxon") + # test field recordURI, type character + obj <- Taxon$new( + recordURI = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Taxon") + # test field id, type character + obj <- Taxon$new( + id = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Taxon") + # test field sourceSystemParentId, type character + obj <- Taxon$new( + sourceSystemParentId = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Taxon") + # test field taxonRank, type character + obj <- Taxon$new( + taxonRank = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Taxon") + # test field taxonRemarks, type character + obj <- Taxon$new( + taxonRemarks = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Taxon") + # test field occurrenceStatusVerbatim, type character + obj <- Taxon$new( + occurrenceStatusVerbatim = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "Taxon") + # test field acceptedName, type ScientificName + obj <- Taxon$new(acceptedName = ScientificName$new()) + expect_is(obj, "Taxon") + # test field defaultClassification, type DefaultClassification + obj <- Taxon$new(defaultClassification = DefaultClassification$new()) + expect_is(obj, "Taxon") + # test field systemClassification, type list, datatype Monomial + lst <- lapply(1:sample(1:10, 1), function(x) Monomial$new()) + obj <- Taxon$new(systemClassification = lst) + expect_is(obj, "Taxon") + # test field synonyms, type list, datatype ScientificName + lst <- lapply(1:sample(1:10, 1), function(x) ScientificName$new()) + obj <- Taxon$new(synonyms = lst) + expect_is(obj, "Taxon") + # test field vernacularNames, type list, datatype VernacularName + lst <- lapply(1:sample(1:10, 1), function(x) VernacularName$new()) + obj <- Taxon$new(vernacularNames = lst) + expect_is(obj, "Taxon") + # test field descriptions, type list, datatype TaxonDescription + lst <- lapply(1:sample(1:10, 1), function(x) TaxonDescription$new()) + obj <- Taxon$new(descriptions = lst) + expect_is(obj, "Taxon") + # test field references, type list, datatype Reference + lst <- lapply(1:sample(1:10, 1), function(x) Reference$new()) + obj <- Taxon$new(references = lst) + expect_is(obj, "Taxon") + # test field experts, type list, datatype Expert + lst <- lapply(1:sample(1:10, 1), function(x) Expert$new()) + obj <- Taxon$new(experts = lst) + expect_is(obj, "Taxon") + # test field validName, type ScientificName + obj <- Taxon$new(validName = ScientificName$new()) + expect_is(obj, "Taxon") }) test_that("toList works", { diff --git a/tests/testthat/test-TaxonDescription.r b/tests/testthat/test-TaxonDescription.r index 4e0eac7..8987566 100644 --- a/tests/testthat/test-TaxonDescription.r +++ b/tests/testthat/test-TaxonDescription.r @@ -1,12 +1,39 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class TaxonDescription") test_that("Constructor works", { obj <- TaxonDescription$new() expect_is(obj, "TaxonDescription") + + # test constructor with random arguments + # test field category, type character + obj <- TaxonDescription$new( + category = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "TaxonDescription") + # test field description, type character + obj <- TaxonDescription$new( + description = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "TaxonDescription") + # test field language, type character + obj <- TaxonDescription$new( + language = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "TaxonDescription") }) test_that("toList works", { diff --git a/tests/testthat/test-TaxonomicEnrichment.r b/tests/testthat/test-TaxonomicEnrichment.r index a7cbbc8..55b531b 100644 --- a/tests/testthat/test-TaxonomicEnrichment.r +++ b/tests/testthat/test-TaxonomicEnrichment.r @@ -1,12 +1,34 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class TaxonomicEnrichment") test_that("Constructor works", { obj <- TaxonomicEnrichment$new() expect_is(obj, "TaxonomicEnrichment") + + # test constructor with random arguments + # test field vernacularNames, type list, datatype SummaryVernacularName + lst <- lapply(1:sample(1:10, 1), function(x) SummaryVernacularName$new()) + obj <- TaxonomicEnrichment$new(vernacularNames = lst) + expect_is(obj, "TaxonomicEnrichment") + # test field synonyms, type list, datatype SummaryScientificName + lst <- lapply(1:sample(1:10, 1), function(x) SummaryScientificName$new()) + obj <- TaxonomicEnrichment$new(synonyms = lst) + expect_is(obj, "TaxonomicEnrichment") + # test field sourceSystem, type SummarySourceSystem + obj <- TaxonomicEnrichment$new(sourceSystem = SummarySourceSystem$new()) + expect_is(obj, "TaxonomicEnrichment") + # test field taxonId, type character + obj <- TaxonomicEnrichment$new( + taxonId = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "TaxonomicEnrichment") }) test_that("toList works", { diff --git a/tests/testthat/test-VernacularName.r b/tests/testthat/test-VernacularName.r index dcdb524..bf61f21 100644 --- a/tests/testthat/test-VernacularName.r +++ b/tests/testthat/test-VernacularName.r @@ -1,12 +1,39 @@ - library("nbaR") library("testthat") +set.seed(111) + context("Testing class VernacularName") test_that("Constructor works", { obj <- VernacularName$new() expect_is(obj, "VernacularName") + + # test constructor with random arguments + # test field name, type character + obj <- VernacularName$new( + name = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "VernacularName") + # test field language, type character + obj <- VernacularName$new( + language = paste(sample( + c(LETTERS, letters), + sample(1:20, 1) + ), collapse = "") + ) + expect_is(obj, "VernacularName") + # test field references, type list, datatype Reference + lst <- lapply(1:sample(1:10, 1), function(x) Reference$new()) + obj <- VernacularName$new(references = lst) + expect_is(obj, "VernacularName") + # test field experts, type list, datatype Expert + lst <- lapply(1:sample(1:10, 1), function(x) Expert$new()) + obj <- VernacularName$new(experts = lst) + expect_is(obj, "VernacularName") }) test_that("toList works", {