tests/testthat/test_selection.R

library(GA)
context("selection")

pop_fitness_test = c(1201.4,1074.453,1100.005,1173.594,1122.976,1168.851,1141.135,1317.805,1171.981,1349.642,1206.789,1178.572,1018.781,1208.038,1050.683,1182.462,1131.363,1090.56,1213.323,1099.458,1220.703,1099.351,1248.989,1074.535,1307.82,1211.793,1182.264,1108.079,1151.159,1095.863,1041.387,1128.541,1127.071,1268.281,1249.636,1248.869,1050.719,980.893,1164.62,1013.899,1050.799,1103.964,1069.859,1165.104,1008.037,1014.875,1242.821,1253.17,1064.414,1086.331,1033.041,1093.276,1245.204,1020.113,1150.557,1147.241,1096.902,1173.409,1159.798,1160.214,1152.463,1210.4,1264.921,1183.344,1176.37,1079.582,990.2919,1134.94,1250.036,1157.02,1213.407,1229.005,1084.196,1088.715,1198.118,1178.824,1232.853,1069.039,1227.466,952.5089,1203.807,1088.636,1076.335,1183.937,1274.909,1087.561,1105.284,1184.097,1121.685,1032.603,1072.382,1221.612,1074.588,1192.706,1248.53,1119.134,1032.609,1293.947,1163.282,1155.273)
pop_fitness_test2 = rep(2, 100)

test_that('selection works', {
  expect_that(selection(pop_fitness_test, "weight", 100, 1:100), is_a("integer"))
  expect_length(selection(pop_fitness_test, "weight", 100, 1:100), 100)
  expect_that(selection(pop_fitness_test, "rank", 100, 1:100), is_a("integer"))
  expect_length(selection(pop_fitness_test, "rank", 100, 1:100), 100)
})

test_that('selection input error',
  expect_error(object = selection(pop_fitness = "character", "weight", 100, 1:100))
  )
slwu89/GA documentation built on May 14, 2019, 5:20 p.m.