|
| 1 | +test_that("Correct frequency found", { |
| 2 | + a<-new_acc(list(matrix(sin(1:200/(50/(pi*2))))), units::set_units(200,'Hz')) |
| 3 | + expect_equal(peak_frequency(a), list(units::set_units(4,'Hz'))) |
| 4 | +}) |
| 5 | + |
| 6 | +test_that("Multiple axis peak freq and changing freq", { |
| 7 | + a<-new_acc(list(cbind(z=cos(1:200/(100/(pi*2))), |
| 8 | + x=sin(1:200/(5/(pi*2))))), units::set_units(200,'Hz')) |
| 9 | + expect_equal(peak_frequency(a), list(units::set_units(c(z=2,x=40),'Hz'))) |
| 10 | + |
| 11 | + a<-new_acc(list(cbind(z=cos(1:200/(100/(pi*2))), |
| 12 | + x=sin(1:200/(5/(pi*2))))), units::set_units(100,'Hz')) |
| 13 | + expect_equal(peak_frequency(a), list(units::set_units(c(z=1,x=20),'Hz'))) |
| 14 | + a<-new_acc(list(cbind(z=cos(1:200/(100/(pi*2))), |
| 15 | + x=sin(1:200/(5/(pi*2))))), units::set_units(400,'Hz')) |
| 16 | + expect_equal(peak_frequency(a), list(units::set_units(c(z=4,x=80),'Hz'))) |
| 17 | +}) |
| 18 | + |
| 19 | +test_that("length does not influnce result", { |
| 20 | + a<-new_acc(list(cbind(z=cos(1:199/(100/(pi*2))), |
| 21 | + x=sin(1:199/(5/(pi*2))))), units::set_units(200,'Hz')) |
| 22 | + expect_equal(peak_frequency(a), list(units::set_units(c(z=2,x=40),'Hz'))) |
| 23 | + a<-new_acc(list(cbind(z=cos(1:199/(100/(pi*2))), |
| 24 | + x=sin(1:199/(5/(pi*2))))), units::set_units(100,'Hz')) |
| 25 | + expect_equal(peak_frequency(a), list(units::set_units(c(z=1,x=20),'Hz'))) |
| 26 | + a<-new_acc(list(cbind(z=cos(1:199/(100/(pi*2))), |
| 27 | + x=sin(1:199/(5/(pi*2))))), units::set_units(400,'Hz')) |
| 28 | + expect_equal(peak_frequency(a), list(units::set_units(c(z=4,x=80),'Hz'))) |
| 29 | +}) |
| 30 | + |
| 31 | +test_that("Multiple axis peak freq intercept does not matter", { |
| 32 | + a<-new_acc(list(cbind(z=-3+.1*cos(1:200/(100/(pi*2))),x=3*(2+sin(1:200/(50/(pi*2)))))), units::set_units(200,'Hz')) |
| 33 | + expect_equal(peak_frequency(a), list(units::set_units(c(z=2,x=4),'Hz'))) |
| 34 | +}) |
| 35 | + |
| 36 | +test_that("NA returns empty",{ |
| 37 | + expect_equal(peak_frequency(new_acc(list(NULL), frequency = NA)), list(NULL)) |
| 38 | + expect_equal(peak_frequency(new_acc(list(NULL, NULL), frequency = c(NA, NA))), list(NULL, NULL)) |
| 39 | + expect_equal(peak_frequency(new_acc(list(NULL,matrix(sin(1:200/(50/(pi*2)))), NULL), |
| 40 | + frequency = units::set_units(c(NA,200, NA),'Hz'))), |
| 41 | + list(NULL,units::set_units(4,"Hz"), NULL)) |
| 42 | + |
| 43 | +}) |
| 44 | + |
| 45 | +test_that("Resolution alows to identify partial frequencies", { |
| 46 | + a<-new_acc(list(cbind(z=cos(1:200/(80/(pi*2))), |
| 47 | + x=sin(1:200/(5/(pi*2))))), units::set_units(200,'Hz')) |
| 48 | + expect_equal(peak_frequency(a), |
| 49 | + list(units::set_units(c(z=3,x=40),'Hz'))) |
| 50 | + expect_equal(peak_frequency(a, resolution = units::set_units(.5,'Hz')), |
| 51 | + list(units::set_units(c(z=2.5,x=40),'Hz'))) |
| 52 | + expect_equal(peak_frequency(a, resolution = units::set_units(.25,'Hz')), |
| 53 | + list(units::set_units(c(z=2.5,x=40),'Hz'))) |
| 54 | +}) |
| 55 | + |
| 56 | + |
| 57 | +test_that("Resolution alows to identify partial frequencies", { |
| 58 | + a<-new_acc(list(matrix(runif(100), ncol=10)), units::set_units(23,'Hz')) |
| 59 | + expect_equal((((unlist(peak_frequency(a, resolution = units::set_units(.005,'Hz')))/.005)+.5)%%1)-.5, |
| 60 | + rep(0,10) ) |
| 61 | + expect_equal((((unlist(peak_frequency(a, resolution = units::set_units(.025,'Hz')))/.025)+.5)%%1)-.5, |
| 62 | + rep(0,10) ) |
| 63 | +# expect_equal((((unlist(peak_frequency(a, resolution = units::set_units(.035,'Hz')))/.035)+.5)%%1)-.5, |
| 64 | +# rep(0,10) ) |
| 65 | + a<-new_acc(list(matrix(runif(1000), ncol=10)), units::set_units(23,'Hz')) |
| 66 | + expect_equal((((unlist(peak_frequency(a, resolution = units::set_units(.005,'Hz')))/.005)+.5)%%1)-.5, |
| 67 | + rep(0,10) ) |
| 68 | + expect_equal((((unlist(peak_frequency(a, resolution = units::set_units(.025,'Hz')))/.025)+.5)%%1)-.5, |
| 69 | + rep(0,10) ) |
| 70 | + |
| 71 | + }) |
| 72 | + |
0 commit comments