R Under development (unstable) (2026-01-23 r89325 ucrt) -- "Unsuffered Consequences" Copyright (C) 2026 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(mfdb) > library(unittest, quietly = TRUE) > helpers <- c('utils/helpers.R', 'tests/utils/helpers.R') ; source(helpers[file.exists(helpers)]) > > ok_group("Total Fleet (no extra fields)", { + write_component <- function (comp, ...) { + gd <- gadget_directory(tempfile()) + gadget_dir_write(gd, comp) + return(gd) + } + + area_group <- mfdb_group(divA = c('1','2'), divB = c('3'), divC = c('5')) + + gd <- write_component(gadget_fleet_component( + 'totalfleet', + data = structure(data.frame( + year = c(1998), + step = c(1), + area = c('divA', 'divC'), + count = c(5), + stringsAsFactors = FALSE), area = area_group))) + ok(cmp_file(gd, file.path('Modelfiles', 'fleet.fleet'), + ver_string, + "; ", + "[fleetcomponent]", + "totalfleet\ttotalfleet", + "livesonareas\t1\t3", + "multiplicative\t1", + "suitability\t", + "amount\tData/fleet.totalfleet.data", + NULL), "Totalfleet defaults") + ok(cmp_file(gd, file.path('Data', 'fleet.totalfleet.data'), + ver_string, + "; -- data --", + "; year\tstep\tarea\tfleetname\tcount", + "1998\t1\t1\ttotalfleet\t5", + "1998\t1\t3\ttotalfleet\t5", + NULL), "Totalfleet defaults data pulls area from data") + + gd <- write_component(gadget_fleet_component( + 'totalfleet', + name = 'barry', + livesonareas = c('divA', 'divB', 'divC'), + multiplicative = 8, + suitability = "function constant 4;", + data = structure(data.frame( + year = c(1998:2000), + step = c(1), + area = c('divA'), + count = c(5), + stringsAsFactors = FALSE), area = area_group))) + ok(cmp_file(gd, file.path('Modelfiles', 'fleet.fleet'), + ver_string, + "; ", + "[fleetcomponent]", + "totalfleet\tbarry", + "livesonareas\t1\t2\t3", + "multiplicative\t8", + "suitability\tfunction constant 4;", + "amount\tData/fleet.barry.data", + NULL), "Can override livesonareas and multiplicative") + ok(cmp_file(gd, file.path('Data', 'fleet.barry.data'), + ver_string, + "; -- data --", + "; year\tstep\tarea\tfleetname\tcount", + "1998\t1\t1\tbarry\t5", + "1999\t1\t1\tbarry\t5", + "2000\t1\t1\tbarry\t5", + NULL), "Can override livesonareas and multiplicative (amountfile)") + }) # Total Fleet (no extra fields) ok - Totalfleet defaults ok - Totalfleet defaults data pulls area from data ok - Can override livesonareas and multiplicative ok - Can override livesonareas and multiplicative (amountfile) > > ok_group("Types with extra parameters", { + gd <- gadget_directory(tempfile()) + area_group <- mfdb_group(divA = c('1','2'), divB = c('3'), divC = c('5')) + + gd <- write_component(gadget_fleet_component( + 'totalfleet', + name = 'barry', + suitability = "function constant 4;", + catchability = list(stockA=4, stockB=5), + quotafunction = 'simple', + biomasslevel = c(1000, 2000), + quotalevel = c(0.1, 0.4, 0.9), + data = structure(data.frame( + year = c(1998:2000), + step = c(1), + area = c('divA'), + count = c(5), + stringsAsFactors = FALSE), area = area_group))) + ok(cmp_file(gd, file.path('Modelfiles', 'fleet.fleet'), + ver_string, + "; ", + "[fleetcomponent]", + "totalfleet\tbarry", + "livesonareas\t1", + "multiplicative\t1", + "suitability\tfunction constant 4;", + "amount\tData/fleet.barry.data", + NULL), "Totalfleet ignores catchability") + + gd <- write_component(gadget_fleet_component( + 'effortfleet', + name = 'barry', + suitability = "function constant 4;", + catchability = list(stockA=4, stockB=5), + quotafunction = 'simple', + biomasslevel = c(1000, 2000), + quotalevel = c(0.1, 0.4, 0.9), + data = structure(data.frame( + year = c(1998:2000), + step = c(1), + area = c('divA'), + count = c(5), + stringsAsFactors = FALSE), area = area_group))) + ok(cmp_file(gd, file.path('Modelfiles', 'fleet.fleet'), + ver_string, + "; ", + "[fleetcomponent]", + "effortfleet\tbarry", + "livesonareas\t1", + "multiplicative\t1", + "suitability\tfunction constant 4;", + "catchability\t", + "stockA\t4", + "stockB\t5", + "amount\tData/fleet.barry.data", + NULL), "Effortfleet includes catchability") + + gd <- write_component(gadget_fleet_component( + 'quotafleet', + name = 'barry', + suitability = "function constant 4;", + catchability = list(stockA=4, stockB=5), + quotafunction = 'simple', + biomasslevel = c(1000, 2000), + quotalevel = c(0.1, 0.4, 0.9), + data = structure(data.frame( + year = c(1998:2000), + step = c(1), + area = c('divA'), + count = c(5), + stringsAsFactors = FALSE), area = area_group))) + ok(cmp_file(gd, file.path('Modelfiles', 'fleet.fleet'), + ver_string, + "; ", + "[fleetcomponent]", + "quotafleet\tbarry", + "livesonareas\t1", + "multiplicative\t1", + "suitability\tfunction constant 4;", + "quotafunction\tsimple", + "biomasslevel\t1000\t2000", + "quotalevel\t0.1\t0.4\t0.9", + "amount\tData/fleet.barry.data", + NULL), "Quotafleet includes quotafunction, biomasslevel, quotalevel") + }) # Types with extra parameters ok - Totalfleet ignores catchability ok - Effortfleet includes catchability ok - Quotafleet includes quotafunction, biomasslevel, quotalevel > > ok_group("Multiple fleet files & mainfile", { + gd <- gadget_directory(tempfile()) + area_group <- mfdb_group(divA = c('1','2'), divB = c('3'), divC = c('5')) + + gadget_dir_write(gd, gadget_fleet_component( + 'totalfleet', + name = 'alfred', + data = structure(data.frame( + year = c(1998), + step = c(1), + area = c(1), + count = c(5), + stringsAsFactors = FALSE), area = area_group))) + ok(cmp_file(gd, 'main', + ver_string, + "timefile\t", + "areafile\t", + "printfiles\t; Required comment", + "[stock]", + "[tagging]", + "[otherfood]", + "[fleet]", + "fleetfiles\tModelfiles/fleet.fleet", + "[likelihood]", + NULL), "Added default name to mainfile") + + gadget_dir_write(gd, gadget_fleet_component( + 'totalfleet', + name = 'alfred', + livesonareas = c(1), + data = structure(data.frame( + year = c(1999), + step = c(1), + area = c(1), + count = c(5), + stringsAsFactors = FALSE), area = area_group), + fleetfile = 'otherfleet')) + ok(cmp_file(gd, 'main', + ver_string, + "timefile\t", + "areafile\t", + "printfiles\t; Required comment", + "[stock]", + "[tagging]", + "[otherfood]", + "[fleet]", + "fleetfiles\tModelfiles/fleet.fleet\tModelfiles/otherfleet.fleet", + "[likelihood]", + NULL), "Added otherfleet to mainfile") + ok(cmp_file(gd, file.path('Modelfiles', 'fleet.fleet'), + ver_string, + "; ", + "[fleetcomponent]", + "totalfleet\talfred", + "livesonareas\t1", + "multiplicative\t1", + "suitability\t", + "amount\tData/fleet.alfred.data", + NULL), "Default fleet.fleet file has first alfred") + ok(cmp_file(gd, file.path('Modelfiles', 'otherfleet.fleet'), + ver_string, + "; ", + "[fleetcomponent]", + "totalfleet\talfred", + "livesonareas\t1", + "multiplicative\t1", + "suitability\t", + "amount\tData/otherfleet.alfred.data", + NULL), "otherfleet.fleet has alfred with non-clashing data file") + + gadget_dir_write(gd, gadget_fleet_component( + 'totalfleet', + name = 'alfred', + livesonareas = c(2), + data = structure(data.frame( + year = c(1999), + step = c(1), + area = c(1), + count = c(5), + stringsAsFactors = FALSE), area = area_group), + fleetfile = 'otherfleet')) + ok(cmp_file(gd, 'main', + ver_string, + "timefile\t", + "areafile\t", + "printfiles\t; Required comment", + "[stock]", + "[tagging]", + "[otherfood]", + "[fleet]", + "fleetfiles\tModelfiles/fleet.fleet\tModelfiles/otherfleet.fleet", + "[likelihood]", + NULL), "Still 2 fleet files") + ok(cmp_file(gd, file.path('Modelfiles', 'fleet.fleet'), + ver_string, + "; ", + "[fleetcomponent]", + "totalfleet\talfred", + "livesonareas\t1", + "multiplicative\t1", + "suitability\t", + "amount\tData/fleet.alfred.data", + NULL), "Default fleet.fleet unchanged") + ok(cmp_file(gd, file.path('Modelfiles', 'otherfleet.fleet'), + ver_string, + "; ", + "[fleetcomponent]", + "totalfleet\talfred", + "livesonareas\t2", + "multiplicative\t1", + "suitability\t", + "amount\tData/otherfleet.alfred.data", + NULL), "otherfleet.fleet has updated alfred") + }) # Multiple fleet files & mainfile ok - Added default name to mainfile ok - Added otherfleet to mainfile ok - Default fleet.fleet file has first alfred ok - otherfleet.fleet has alfred with non-clashing data file ok - Still 2 fleet files ok - Default fleet.fleet unchanged ok - otherfleet.fleet has updated alfred > > ok_group("Error conditions", { + area_group <- mfdb_group(divA = c('1','2'), divB = c('3'), divC = c('5')) + + ok(cmp_error( + gadget_fleet_component('totalfleet'), + 'data'), "Notice missing data") + + ok(cmp_error( + gadget_fleet_component('totalfleet', livesonareas = c(1), data = structure(data.frame( + year = c(1998), + stoop = c(1), + area = c(1), + count = c(5), + stringsAsFactors = FALSE), area = area_group)), + 'gadget_fleet_component expects.*stoop'), "Notice incompatible columns") + + ok(cmp_error( + gadget_fleet_component('totalfleet', livesonareas = c(1), data = structure(data.frame( + stringsAsFactors = FALSE), area = area_group)), + 'gadget_fleet_component is empty'), "Notice complete lack of data, say where from") + }) # Error conditions ok - Notice missing data ok - Notice incompatible columns ok - Notice complete lack of data, say where from > > proc.time() user system elapsed 0.84 0.21 1.00 1..17 # Looks like you passed all 17 tests.