tests/testthat/test-fpunique.R

test_that("fpunique works", {
  just_dia <- 12 * log2(c(1, 9/8, 5/4, 4/3, 3/2, 5/3, 15/8))
  semitone <- 12 * log2(16/15)
  just_atonal <- c(0, semitone, 6, 6+semitone+1e-13)

  expect_length(fpunique(sort(sim(just_dia))), 19)
  expect_length(fpunique(sort(sim(just_dia)), rounder=0), 12)
  expect_equal(dim(fpunique(sim(just_atonal), MARGIN=2))[2], 2)
  expect_equal(dim(fpunique(t(sim(just_atonal)), MARGIN=1))[1], 2)
})

test_that("fpmod works", {
  pretty_small <- 1e-9
  satb_maj <- c(0, 4, 7, 12-pretty_small)
  satb_maj_19 <- c(0, 6, 11, 19-pretty_small)

  expect_equal(fpmod(satb_maj), satb_maj)
  expect_equal(fpmod(satb_maj, rounder=8), c(0, 4, 7, 0))
  expect_equal(fpmod(satb_maj_19, edo=19), satb_maj_19)
  expect_equal(fpmod(satb_maj_19, edo=19, rounder=8), c(0, 6, 11, 0))
})

Try the musicMCT package in your browser

Any scripts or data that you put into this service are public.

musicMCT documentation built on June 21, 2026, 9:06 a.m.