tests/testthat/test-precision-matrices.R

context("testing precision matrices")

# test_that("make_Q", {
#
#     expect_error(make_Q(4, "aaa"), "phi must be between -1 and 1")
#     expect_error(make_Q(4, NA), "phi must be between -1 and 1")
#     expect_error(make_Q(4, -2), "phi must be between -1 and 1")
#     expect_error(make_Q(4, 2), "phi must be between -1 and 1")
#     make_Q(4, 0.9)
#     # expect_error(wendland_basis(1:10, 1:10), "radius must be a single positive numeric value")
#     # expect_error(wendland_basis(-10:10, 5), "d must be nonnegative")
#     # expect_error(wendland_basis(c(1:10, NA), 2), "d must not contain missing values")
#     # expect_equal(wendland_basis(1:5, 3), c(0.37717827566936, 0.013971447441955, 0, 0, 0))
# })

test_that("make_Q_alpha_2d", {

    # expect_identical(
    #     make_Q_alpha_2d(4, 0.5),
    #     structure(list(new("spam",
    #                        entries = c(2, -0.5, -0.5, -0.5, 3, -0.5, -0.5,
    #                                    -0.5, 3, -0.5, -0.5, -0.5, 2, -0.5, -0.5, 3, -0.5, -0.5, -0.5,
    #                                    -0.5, 4, -0.5, -0.5, -0.5, -0.5, 4, -0.5, -0.5, -0.5, -0.5, 3,
    #                                    -0.5, -0.5, 3, -0.5, -0.5, -0.5, -0.5, 4, -0.5, -0.5, -0.5, -0.5,
    #                                    4, -0.5, -0.5, -0.5, -0.5, 3, -0.5, -0.5, 2, -0.5, -0.5, -0.5,
    #                                    3, -0.5, -0.5, -0.5, 3, -0.5, -0.5, -0.5, 2),
    #                        colindices = c(1L,
    #                                       2L, 5L, 1L, 2L, 3L, 6L, 2L, 3L, 4L, 7L, 3L, 4L, 8L, 1L, 5L, 6L,
    #                                       9L, 2L, 5L, 6L, 7L, 10L, 3L, 6L, 7L, 8L, 11L, 4L, 7L, 8L, 12L,
    #                                       5L, 9L, 10L, 13L, 6L, 9L, 10L, 11L, 14L, 7L, 10L, 11L, 12L, 15L,
    #                                       8L, 11L, 12L, 16L, 9L, 13L, 14L, 10L, 13L, 14L, 15L, 11L, 14L,
    #                                       15L, 16L, 12L, 15L, 16L),
    #                        rowpointers = c(1L, 4L, 8L, 12L, 15L,
    #                                        19L, 24L, 29L, 33L, 37L, 42L, 47L, 51L, 54L, 58L, 62L, 65L),
    #                        dimension = c(16L, 16L))),
    #               class = "Q_alpha"
    #     )
    # )

    n_dims <- c(4, 16)
    phi <- rep(1, 3)
    expect_error(make_Q_alpha_2d(n_dims, phi), "n_dims and phi must both be vectors of length M.")

    n_dims <- c(4, 16, 32)
    phi <- rep(1, 2)
    expect_error(make_Q_alpha_2d(n_dims, phi), "n_dims and phi must both be vectors of length M.")

    n_dims <- c(4, 16)
    phi <- rep(NA, 2)
    expect_error(make_Q_alpha_2d(n_dims, phi), "phi must be a numeric vector of length M with values between -1 and 1.")
    phi <- rep(2, 2)
    expect_error(make_Q_alpha_2d(n_dims, phi), "phi must be a numeric vector of length M with values between -1 and 1.")
    phi <- rep(-2, 2)
    expect_error(make_Q_alpha_2d(n_dims, phi), "phi must be a numeric vector of length M with values between -1 and 1.")

    expect_error(make_Q_alpha_2d(4, 1.5), "phi must be a numeric vector of length M with values between -1 and 1.")
    expect_error(make_Q_alpha_2d(4, -1.5), "phi must be a numeric vector of length M with values between -1 and 1.")
    expect_error(make_Q_alpha_2d(c(2, 4), c(0.5, 1.5)), "phi must be a numeric vector of length M with values between -1 and 1.")
    expect_error(make_Q_alpha_2d(c(2, 4), c(0.5, NA)), "phi must be a numeric vector of length M with values between -1 and 1.")
    expect_error(make_Q_alpha_2d(c(2, 4), c(0.5, "aaa")), "phi must be a numeric vector of length M with values between -1 and 1.")
    expect_error(make_Q_alpha_2d(c(2, NA), c(0.5, 0.5)), "n_dims must be a vector of integers of length M.")
    expect_error(make_Q_alpha_2d(c(2, "aaa"), c(0.5, 0.5)), "n_dims must be a vector of integers of length M.")
    expect_error(make_Q_alpha_2d(c(2, 3.5), c(0.5, 0.5)), "n_dims must be a vector of integers of length M.")

    n_dims <- c(4, 16)
    phi <- rep(1, 2)

    expect_error(make_Q_alpha_2d(n_dims, phi, use_spam = "TRUE"), "use_spam must be either TRUE or FALSE.")
    expect_error(make_Q_alpha_2d(n_dims, phi, use_spam = 3.5), "use_spam must be either TRUE or FALSE.")
    expect_error(make_Q_alpha_2d(n_dims, phi, use_spam = NA), "use_spam must be either TRUE or FALSE.")

    expect_error(make_Q_alpha_2d(n_dims, phi, prec_model = "AAA"), 'The only valid options for prec_model are \"CAR\" and \"SAR\".')
    expect_error(make_Q_alpha_2d(n_dims, phi, prec_model = NA), 'The only valid options for prec_model are \"CAR\" and \"SAR\".')
    expect_error(make_Q_alpha_2d(n_dims, phi, prec_model = 32), 'The only valid options for prec_model are \"CAR\" and \"SAR\".')

})


test_that("make_Q_alpha_tau2", {

    n_dims <- c(4, 16)
    phi    <- c(1, 1)
    tau2 <- c(2, 2)
    Q_alpha <- make_Q_alpha_2d(n_dims, phi)
    class(Q_alpha) <- "aaa"
    expect_error(make_Q_alpha_tau2(Q_alpha, tau2), 'Q_alpha must by of class "Q_alpha" which is the output of make_Q_alpha_2d\\(\\)')
    class(Q_alpha) <- "Q_alpha"
    tau2 <- 1:3
    expect_error(make_Q_alpha_tau2(Q_alpha, tau2), "Q_alpha must be a list of length M and tau2 must be a positive numeric vector of length M.")
    tau2 <- c(1, NA)
    expect_error(make_Q_alpha_tau2(Q_alpha, tau2), "tau2 must be a positive numeric vector of length M.")
    tau2 <- c(1, "aaa")
    expect_error(make_Q_alpha_tau2(Q_alpha, tau2), "tau2 must be a positive numeric vector of length M.")
    tau2 <- c(1, -1)
    expect_error(make_Q_alpha_tau2(Q_alpha, tau2), "tau2 must be a positive numeric vector of length M.")

    tau2 <- 1:2
    expect_error(make_Q_alpha_tau2(Q_alpha, tau2, use_spam = "TRUE"), "use_spam must be either TRUE or FALSE.")
    expect_error(make_Q_alpha_tau2(Q_alpha, tau2, use_spam = 3.5), "use_spam must be either TRUE or FALSE.")
    expect_error(make_Q_alpha_tau2(Q_alpha, tau2, use_spam = NA), "use_spam must be either TRUE or FALSE.")

    expect_equal({
        n_dims <- c(2, 4)
        phi    <- c(1, 1)
        Q_alpha <- make_Q_alpha_2d(n_dims, phi, prec_model = "SAR")
        tau2 <- c(3, 5)
        make_Q_alpha_tau2(Q_alpha, tau2)
    },
    {
        new("spam", entries = c(4.5, -3, -3, 1.5, -3, 4.5, 1.5, -3, -3,
                                1.5, 4.5, -3, 1.5, -3, -3, 4.5, 7.5, -4.16666666666667, 0.833333333333333,
                                -4.16666666666667, 1.25, 0.833333333333333, -4.16666666666667,
                                6.66666666666667, -3.33333333333333, 0.833333333333333, 1.11111111111111,
                                -2.91666666666667, 0.833333333333333, 0.416666666666667, 0.833333333333333,
                                -3.33333333333333, 6.66666666666667, -4.16666666666667, 0.833333333333333,
                                -2.91666666666667, 1.11111111111111, 0.416666666666667, 0.833333333333333,
                                -4.16666666666667, 7.5, 1.25, -4.16666666666667, 0.833333333333333,
                                -4.16666666666667, 1.11111111111111, 6.66666666666667, -2.91666666666667,
                                0.416666666666667, -3.33333333333333, 0.833333333333333, 0.833333333333333,
                                1.25, -2.91666666666667, 0.833333333333333, -2.91666666666667,
                                6.25, -2.5, 0.416666666666667, 0.833333333333333, -2.5, 0.625,
                                0.416666666666667, 0.833333333333333, -2.91666666666667, 1.25,
                                0.416666666666667, -2.5, 6.25, -2.91666666666667, 0.625, -2.5,
                                0.833333333333333, 0.416666666666667, 1.11111111111111, -4.16666666666667,
                                0.416666666666667, -2.91666666666667, 6.66666666666667, 0.833333333333333,
                                -3.33333333333333, 0.833333333333333, 0.833333333333333, -3.33333333333333,
                                0.833333333333333, 6.66666666666667, -2.91666666666667, 0.416666666666667,
                                -4.16666666666667, 1.11111111111111, 0.416666666666667, 0.833333333333333,
                                -2.5, 0.625, -2.91666666666667, 6.25, -2.5, 0.416666666666667,
                                1.25, -2.91666666666667, 0.833333333333333, 0.416666666666667,
                                0.625, -2.5, 0.833333333333333, 0.416666666666667, -2.5, 6.25,
                                -2.91666666666667, 0.833333333333333, -2.91666666666667, 1.25,
                                0.833333333333333, 0.833333333333333, -3.33333333333333, 0.416666666666667,
                                -2.91666666666667, 6.66666666666667, 1.11111111111111, -4.16666666666667,
                                0.833333333333333, -4.16666666666667, 1.25, 7.5, -4.16666666666667,
                                0.833333333333333, 0.416666666666667, 1.11111111111111, -2.91666666666667,
                                0.833333333333333, -4.16666666666667, 6.66666666666667, -3.33333333333333,
                                0.833333333333333, 0.416666666666667, 0.833333333333333, -2.91666666666667,
                                1.11111111111111, 0.833333333333333, -3.33333333333333, 6.66666666666667,
                                -4.16666666666667, 0.833333333333333, 1.25, -4.16666666666667,
                                0.833333333333333, -4.16666666666667, 7.5),
            colindices = c(1L,
                           2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 5L,
                           6L, 7L, 9L, 10L, 13L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 14L, 5L,
                           6L, 7L, 8L, 10L, 11L, 12L, 15L, 6L, 7L, 8L, 11L, 12L, 16L, 5L,
                           6L, 9L, 10L, 11L, 13L, 14L, 17L, 5L, 6L, 7L, 9L, 10L, 11L, 12L,
                           13L, 14L, 15L, 18L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 14L, 15L,
                           16L, 19L, 7L, 8L, 10L, 11L, 12L, 15L, 16L, 20L, 5L, 9L, 10L,
                           13L, 14L, 15L, 17L, 18L, 6L, 9L, 10L, 11L, 13L, 14L, 15L, 16L,
                           17L, 18L, 19L, 7L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 18L, 19L,
                           20L, 8L, 11L, 12L, 14L, 15L, 16L, 19L, 20L, 9L, 13L, 14L, 17L,
                           18L, 19L, 10L, 13L, 14L, 15L, 17L, 18L, 19L, 20L, 11L, 14L, 15L,
                           16L, 17L, 18L, 19L, 20L, 12L, 15L, 16L, 18L, 19L, 20L),
            rowpointers = c(1L,
                            5L, 9L, 13L, 17L, 23L, 31L, 39L, 45L, 53L, 64L, 75L, 83L, 91L,
                            102L, 113L, 121L, 127L, 135L, 143L, 149L),
            dimension = c(20L,
                          20L)
            )
    })

    expect_identical({
        n_dims <- c(2, 4)
        phi    <- c(1, 1)
        Q_alpha <- make_Q_alpha_2d(n_dims, phi)
        tau2 <- c(3, 5)
        make_Q_alpha_tau2(Q_alpha, tau2)
    },
    {
        new("spam",
            entries = c(6, -3, -3, -3, 6, -3, -3, 6, -3, -3,
                        -3, 6, 10, -5, -5, -5, 15, -5, -5, -5, 15, -5, -5, -5, 10, -5,
                        -5, 15, -5, -5, -5, -5, 20, -5, -5, -5, -5, 20, -5, -5, -5, -5,
                        15, -5, -5, 15, -5, -5, -5, -5, 20, -5, -5, -5, -5, 20, -5, -5,
                        -5, -5, 15, -5, -5, 10, -5, -5, -5, 15, -5, -5, -5, 15, -5, -5,
                        -5, 10),
            colindices = c(1L, 2L, 3L, 1L, 2L, 4L, 1L, 3L, 4L, 2L,
                           3L, 4L, 5L, 6L, 9L, 5L, 6L, 7L, 10L, 6L, 7L, 8L, 11L, 7L, 8L,
                           12L, 5L, 9L, 10L, 13L, 6L, 9L, 10L, 11L, 14L, 7L, 10L, 11L, 12L,
                           15L, 8L, 11L, 12L, 16L, 9L, 13L, 14L, 17L, 10L, 13L, 14L, 15L,
                           18L, 11L, 14L, 15L, 16L, 19L, 12L, 15L, 16L, 20L, 13L, 17L, 18L,
                           14L, 17L, 18L, 19L, 15L, 18L, 19L, 20L, 16L, 19L, 20L),
            rowpointers = c(1L,
                            4L, 7L, 10L, 13L, 16L, 20L, 24L, 27L, 31L, 36L, 41L, 45L, 49L,
                            54L, 59L, 63L, 66L, 70L, 74L, 77L),
            dimension = c(20L, 20L))
    })

    expect_equal({
        n_dims <- c(2, 4)
        phi    <- c(1, 1)
        Q_alpha <- make_Q_alpha_2d(n_dims, phi, prec_model = "SAR", use_spam = FALSE)
        tau2 <- c(3, 5)
        make_Q_alpha_tau2(Q_alpha, tau2, use_spam = FALSE)
    },
    {
        new("dgCMatrix",
            i = c(0L, 1L, 2L, 3L, 0L, 1L, 2L, 3L, 0L, 1L,
                  2L, 3L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 8L, 9L, 12L, 4L, 5L, 6L,
                  7L, 8L, 9L, 10L, 13L, 4L, 5L, 6L, 7L, 9L, 10L, 11L, 14L, 5L,
                  6L, 7L, 10L, 11L, 15L, 4L, 5L, 8L, 9L, 10L, 12L, 13L, 16L, 4L,
                  5L, 6L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 17L, 5L, 6L, 7L, 8L,
                  9L, 10L, 11L, 13L, 14L, 15L, 18L, 6L, 7L, 9L, 10L, 11L, 14L,
                  15L, 19L, 4L, 8L, 9L, 12L, 13L, 14L, 16L, 17L, 5L, 8L, 9L, 10L,
                  12L, 13L, 14L, 15L, 16L, 17L, 18L, 6L, 9L, 10L, 11L, 12L, 13L,
                  14L, 15L, 17L, 18L, 19L, 7L, 10L, 11L, 13L, 14L, 15L, 18L, 19L,
                  8L, 12L, 13L, 16L, 17L, 18L, 9L, 12L, 13L, 14L, 16L, 17L, 18L,
                  19L, 10L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 11L, 14L, 15L, 17L,
                  18L, 19L),
            p = c(0L, 4L, 8L, 12L, 16L, 22L, 30L, 38L, 44L, 52L,
                  63L, 74L, 82L, 90L, 101L, 112L, 120L, 126L, 134L, 142L, 148L),
            Dim = c(20L, 20L),
            Dimnames = list(NULL, NULL),
            x = c(4.5,
                  -3, -3, 1.5, -3, 4.5, 1.5, -3, -3, 1.5, 4.5, -3, 1.5, -3,
                  -3, 4.5, 7.5, -4.16666666666667, 0.833333333333333, -4.16666666666667,
                  1.25, 0.833333333333333, -4.16666666666667, 6.66666666666667,
                  -3.33333333333333, 0.833333333333333, 1.11111111111111, -2.91666666666667,
                  0.833333333333333, 0.416666666666667, 0.833333333333333,
                  -3.33333333333333, 6.66666666666667, -4.16666666666667, 0.833333333333333,
                  -2.91666666666667, 1.11111111111111, 0.416666666666667, 0.833333333333333,
                  -4.16666666666667, 7.5, 1.25, -4.16666666666667, 0.833333333333333,
                  -4.16666666666667, 1.11111111111111, 6.66666666666667, -2.91666666666667,
                  0.416666666666667, -3.33333333333333, 0.833333333333333,
                  0.833333333333333, 1.25, -2.91666666666667, 0.833333333333333,
                  -2.91666666666667, 6.25, -2.5, 0.416666666666667, 0.833333333333333,
                  -2.5, 0.625, 0.416666666666667, 0.833333333333333, -2.91666666666667,
                  1.25, 0.416666666666667, -2.5, 6.25, -2.91666666666667, 0.625,
                  -2.5, 0.833333333333333, 0.416666666666667, 1.11111111111111,
                  -4.16666666666667, 0.416666666666667, -2.91666666666667,
                  6.66666666666667, 0.833333333333333, -3.33333333333333, 0.833333333333333,
                  0.833333333333333, -3.33333333333333, 0.833333333333333,
                  6.66666666666667, -2.91666666666667, 0.416666666666667, -4.16666666666667,
                  1.11111111111111, 0.416666666666667, 0.833333333333333, -2.5,
                  0.625, -2.91666666666667, 6.25, -2.5, 0.416666666666667,
                  1.25, -2.91666666666667, 0.833333333333333, 0.416666666666667,
                  0.625, -2.5, 0.833333333333333, 0.416666666666667, -2.5,
                  6.25, -2.91666666666667, 0.833333333333333, -2.91666666666667,
                  1.25, 0.833333333333333, 0.833333333333333, -3.33333333333333,
                  0.416666666666667, -2.91666666666667, 6.66666666666667, 1.11111111111111,
                  -4.16666666666667, 0.833333333333333, -4.16666666666667,
                  1.25, 7.5, -4.16666666666667, 0.833333333333333, 0.416666666666667,
                  1.11111111111111, -2.91666666666667, 0.833333333333333, -4.16666666666667,
                  6.66666666666667, -3.33333333333333, 0.833333333333333, 0.416666666666667,
                  0.833333333333333, -2.91666666666667, 1.11111111111111, 0.833333333333333,
                  -3.33333333333333, 6.66666666666667, -4.16666666666667, 0.833333333333333,
                  1.25, -4.16666666666667, 0.833333333333333, -4.16666666666667,
                  7.5),
            factors = list())
    })

    expect_identical({
        n_dims <- c(2, 4)
        phi    <- c(1, 1)
        Q_alpha <- make_Q_alpha_2d(n_dims, phi, use_spam = FALSE)
        tau2 <- c(3, 5)
        make_Q_alpha_tau2(Q_alpha, tau2, use_spam = FALSE)
    },
    {
        new("dgCMatrix",
            i = c(0L, 1L, 2L, 0L, 1L, 3L, 0L, 2L, 3L, 1L,
                  2L, 3L, 4L, 5L, 8L, 4L, 5L, 6L, 9L, 5L, 6L, 7L, 10L, 6L, 7L,
                  11L, 4L, 8L, 9L, 12L, 5L, 8L, 9L, 10L, 13L, 6L, 9L, 10L, 11L,
                  14L, 7L, 10L, 11L, 15L, 8L, 12L, 13L, 16L, 9L, 12L, 13L, 14L,
                  17L, 10L, 13L, 14L, 15L, 18L, 11L, 14L, 15L, 19L, 12L, 16L, 17L,
                  13L, 16L, 17L, 18L, 14L, 17L, 18L, 19L, 15L, 18L, 19L),
            p = c(0L,
                  3L, 6L, 9L, 12L, 15L, 19L, 23L, 26L, 30L, 35L, 40L, 44L, 48L,
                  53L, 58L, 62L, 65L, 69L, 73L, 76L),
            Dim = c(20L, 20L),
            Dimnames = list(NULL, NULL),
            x = c(6, -3, -3, -3, 6, -3, -3, 6, -3, -3, -3,
                  6, 10, -5, -5, -5, 15, -5, -5, -5, 15, -5, -5, -5, 10, -5, -5,
                  15, -5, -5, -5, -5, 20, -5, -5, -5, -5, 20, -5, -5, -5, -5, 15,
                  -5, -5, 15, -5, -5, -5, -5, 20, -5, -5, -5, -5, 20, -5, -5, -5,
                  -5, 15, -5, -5, 10, -5, -5, -5, 15, -5, -5, -5, 15, -5, -5, -5,
                  10),
            factors = list()
        )
    })

    # locs <- matrix(1:20, 10, 2)
    # MRA <- mra_wendland_2d(locs)
    # locs_pred <- matrix(NA, 20, 2)
    # expect_error(mra_wendland_2d_pred(locs, locs_pred, MRA), "locs_pred must be a numeric matrix with N rows and 2 columns")
    #
    # locs_pred <- matrix(1:30, 10, 3)
    # expect_error(mra_wendland_2d_pred(locs, locs_pred, MRA), "locs_pred must be a numeric matrix with N rows and 2 columns")
    #
    # locs_pred <- matrix("11", 10, 2)
    # expect_error(mra_wendland_2d_pred(locs, locs_pred, MRA), "locs_pred must be a numeric matrix with N rows and 2 columns")
    #
    # locs_pred <- 1:10
    # expect_error(mra_wendland_2d_pred(locs, locs_pred, MRA), "locs_pred must be a numeric matrix with N rows and 2 columns")
    #
    # locs <- matrix(1:30, 10, 3)
    # expect_error(mra_wendland_2d_pred(locs, locs_pred, MRA), "locs must be a numeric matrix with N rows and 2 columns")
    #
    # locs <- matrix(1:20, 10, 2)
    # locs_pred <- matrix(1:20, 10, 2)
    # expect_error(mra_wendland_2d_pred(locs, locs_pred, MRA, use_spam = 3.5), "use_spam must be either TRUE or FALSE")
    # expect_error(mra_wendland_2d_pred(locs, locs_pred, MRA, use_spam = NA), "use_spam must be either TRUE or FALSE")
    # expect_error(mra_wendland_2d_pred(locs, locs_pred, MRA, use_spam = "aaa"), "use_spam must be either TRUE or FALSE")
    #
    # class(MRA) <- NULL
    # expect_error(mra_wendland_2d_pred(locs, locs_pred, MRA), 'MRA must be of class "mra_wendland_2d"')
    #
    # class(MRA) <- "XXX"
    # expect_error(mra_wendland_2d_pred(locs, locs_pred, MRA), 'MRA must be of class "mra_wendland_2d"')
})


test_that("test_constraint", {
    locs <- matrix(1:20, 10, 2)
    MRA <- mra_wendland_2d(locs, M = 2, n_coarse_grid = 4)
    expect_equal(make_constraint(MRA, constraint = "unconstrained"),
                 list(A_constraint = NULL, a_constraint = NULL))
    expect_equal(make_constraint(MRA, constraint = "overall"),
                 list(A_constraint = structure(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                 0, 1.08601623125006e-05, 0.000112496007290721, 1.08654289635091e-05,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.000625061236957296, 0.0225489224875791,
                                                 0.0633262258769764, 0.0312738163856595, 0.00121730932738073,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 1.08601623125006e-05, 0.0225489224875791,
                                                 0.321435192757127, 0.857954760387478, 0.622740078658578, 0.113913040814712,
                                                 0.00180999093529261, 0, 0, 0, 0, 0, 0, 0, 0.000112496007290721,
                                                 0.0633262258769764, 0.857954760387478, 2.69320117577294, 2.6738302846565,
                                                 0.995571956296118, 0.1245002417436, 0.00180999093529261, 0, 0,
                                                 0, 0, 0, 0, 1.08654289635091e-05, 0.0312738163856595, 0.622740078658578,
                                                 2.6738302846565, 4.30156261189159, 3.04319377260997, 0.995571956296118,
                                                 0.113913040814712, 0.00121730932738073, 0, 0, 0, 0, 0, 0, 0.00121730932738073,
                                                 0.113913040814712, 0.995571956296118, 3.04319377260997, 4.30156261189159,
                                                 2.67383028465651, 0.622740078658578, 0.0312738163856595, 1.08654289635091e-05,
                                                 0, 0, 0, 0, 0, 0, 0.00180999093529261, 0.1245002417436, 0.995571956296118,
                                                 2.67383028465651, 2.69320117577294, 0.857954760387479, 0.0633262258769764,
                                                 0.000112496007290721, 0, 0, 0, 0, 0, 0, 0, 0.00180999093529261,
                                                 0.113913040814712, 0.622740078658578, 0.857954760387479, 0.321435192757127,
                                                 0.0225489224875791, 1.08601623125006e-05, 0, 0, 0, 0, 0, 0, 0,
                                                 0, 0.00121730932738073, 0.0312738163856595, 0.0633262258769764,
                                                 0.0225489224875791, 0.000625061236957296, 0, 0, 0, 0, 0, 0, 0,
                                                 0, 0, 0, 1.08654289635091e-05, 0.000112496007290721, 1.08601623125006e-05,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5.05673652316797e-10,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3.4496711175134e-05,
                                                 0.0015701089925862, 0.003896397104994, 0.00157213610851392, 3.45007275290915e-05,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3.44967111751343e-05, 0.00872963127077592,
                                                 0.0661544886375021, 0.124017651192734, 0.0759808782995632, 0.0120248586792744,
                                                 9.61902739128458e-05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.00157010899258622,
                                                 0.0661544886375023, 0.375690548876713, 0.723386677289052, 0.549050844946753,
                                                 0.168170211647942, 0.0153085619417029, 9.53250421932223e-05,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 5.05673652316932e-10, 0.00389639710499403,
                                                 0.124017651192734, 0.723386677289053, 1.59744074560367, 1.53908699828218,
                                                 0.744223319422889, 0.178596350346924, 0.0153052083946846, 9.57044116187268e-05,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.00157213610851394, 0.0759808782995634,
                                                 0.549050844946754, 1.53908699828218, 2.16411927874826, 1.67691161703102,
                                                 0.75100032952569, 0.178611592076099, 0.015317207123465, 9.6417509205864e-05,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 3.45007275290925e-05, 0.0120248586792744,
                                                 0.168170211647942, 0.744223319422889, 1.67691161703102, 2.19167865690685,
                                                 1.67725643503247, 0.751057520686108, 0.17863784828745, 0.0153172071234649,
                                                 9.57044116187268e-05, 0, 0, 0, 0, 0, 0, 0, 0, 9.61902739128473e-05,
                                                 0.0153085619417029, 0.178596350346924, 0.751000329525689, 1.67725643503247,
                                                 2.19421288675405, 1.67673692684187, 0.751057520686108, 0.178611592076099,
                                                 0.0153052083946846, 9.53250421932245e-05, 0, 0, 0, 0, 0, 0, 0,
                                                 0, 9.53250421932241e-05, 0.0153052083946846, 0.178611592076099,
                                                 0.751057520686108, 1.67673692684187, 2.19421288675405, 1.67725643503247,
                                                 0.751000329525689, 0.178596350346924, 0.0153085619417029, 9.61902739128473e-05,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 9.57044116187261e-05, 0.0153172071234649,
                                                 0.178637848287449, 0.751057520686107, 1.67725643503247, 2.19167865690685,
                                                 1.67691161703102, 0.74422331942289, 0.168170211647943, 0.0120248586792745,
                                                 3.45007275290925e-05, 0, 0, 0, 0, 0, 0, 0, 0, 9.64175092058634e-05,
                                                 0.015317207123465, 0.178611592076099, 0.751000329525689, 1.67691161703101,
                                                 2.16411927874826, 1.53908699828218, 0.549050844946754, 0.0759808782995635,
                                                 0.00157213610851394, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9.57044116187275e-05,
                                                 0.0153052083946846, 0.178596350346925, 0.744223319422889, 1.53908699828218,
                                                 1.59744074560367, 0.723386677289053, 0.124017651192734, 0.00389639710499402,
                                                 5.05673652316932e-10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9.53250421932245e-05,
                                                 0.015308561941703, 0.168170211647942, 0.549050844946754, 0.723386677289053,
                                                 0.375690548876713, 0.0661544886375023, 0.00157010899258621, 0,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9.61902739128465e-05, 0.0120248586792744,
                                                 0.0759808782995633, 0.124017651192734, 0.0661544886375021, 0.00872963127077592,
                                                 3.4496711175134e-05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3.45007275290909e-05,
                                                 0.00157213610851391, 0.00389639710499397, 0.00157010899258619,
                                                 3.44967111751334e-05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                 0, 0, 5.05673652316797e-10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), .Dim = c(1L, 520L)), a_constraint = 0))
    expect_equal(make_constraint(MRA, constraint = "resolution"),
                 list(A_constraint = structure(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.08601623125006e-05, 0,
                                                 0.000112496007290721, 0, 1.08654289635091e-05, 0, 0, 0, 0, 0,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.000625061236957296,
                                                 0, 0.0225489224875791, 0, 0.0633262258769764, 0, 0.0312738163856595,
                                                 0, 0.00121730932738073, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                 0, 0, 0, 0, 1.08601623125006e-05, 0, 0.0225489224875791, 0, 0.321435192757127,
                                                 0, 0.857954760387478, 0, 0.622740078658578, 0, 0.113913040814712,
                                                 0, 0.00180999093529261, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                 0, 0, 0.000112496007290721, 0, 0.0633262258769764, 0, 0.857954760387478,
                                                 0, 2.69320117577294, 0, 2.6738302846565, 0, 0.995571956296118,
                                                 0, 0.1245002417436, 0, 0.00180999093529261, 0, 0, 0, 0, 0, 0,
                                                 0, 0, 0, 0, 0, 0, 0, 1.08654289635091e-05, 0, 0.0312738163856595,
                                                 0, 0.622740078658578, 0, 2.6738302846565, 0, 4.30156261189159,
                                                 0, 3.04319377260997, 0, 0.995571956296118, 0, 0.113913040814712,
                                                 0, 0.00121730932738073, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                 0.00121730932738073, 0, 0.113913040814712, 0, 0.995571956296118,
                                                 0, 3.04319377260997, 0, 4.30156261189159, 0, 2.67383028465651,
                                                 0, 0.622740078658578, 0, 0.0312738163856595, 0, 1.08654289635091e-05,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.00180999093529261, 0,
                                                 0.1245002417436, 0, 0.995571956296118, 0, 2.67383028465651, 0,
                                                 2.69320117577294, 0, 0.857954760387479, 0, 0.0633262258769764,
                                                 0, 0.000112496007290721, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                 0, 0, 0, 0.00180999093529261, 0, 0.113913040814712, 0, 0.622740078658578,
                                                 0, 0.857954760387479, 0, 0.321435192757127, 0, 0.0225489224875791,
                                                 0, 1.08601623125006e-05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                 0, 0, 0, 0, 0, 0.00121730932738073, 0, 0.0312738163856595, 0,
                                                 0.0633262258769764, 0, 0.0225489224875791, 0, 0.000625061236957296,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                 1.08654289635091e-05, 0, 0.000112496007290721, 0, 1.08601623125006e-05,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                 0, 0, 0, 0, 0, 0, 0, 5.05673652316797e-10, 0, 0, 0, 0, 0, 0,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                 0, 0, 0, 0, 3.4496711175134e-05, 0, 0.0015701089925862, 0, 0.003896397104994,
                                                 0, 0.00157213610851392, 0, 3.45007275290915e-05, 0, 0, 0, 0,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                 3.44967111751343e-05, 0, 0.00872963127077592, 0, 0.0661544886375021,
                                                 0, 0.124017651192734, 0, 0.0759808782995632, 0, 0.0120248586792744,
                                                 0, 9.61902739128458e-05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.00157010899258622, 0, 0.0661544886375023,
                                                 0, 0.375690548876713, 0, 0.723386677289052, 0, 0.549050844946753,
                                                 0, 0.168170211647942, 0, 0.0153085619417029, 0, 9.53250421932223e-05,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5.05673652316932e-10,
                                                 0, 0.00389639710499403, 0, 0.124017651192734, 0, 0.723386677289053,
                                                 0, 1.59744074560367, 0, 1.53908699828218, 0, 0.744223319422889,
                                                 0, 0.178596350346924, 0, 0.0153052083946846, 0, 9.57044116187268e-05,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.00157213610851394,
                                                 0, 0.0759808782995634, 0, 0.549050844946754, 0, 1.53908699828218,
                                                 0, 2.16411927874826, 0, 1.67691161703102, 0, 0.75100032952569,
                                                 0, 0.178611592076099, 0, 0.015317207123465, 0, 9.6417509205864e-05,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3.45007275290925e-05,
                                                 0, 0.0120248586792744, 0, 0.168170211647942, 0, 0.744223319422889,
                                                 0, 1.67691161703102, 0, 2.19167865690685, 0, 1.67725643503247,
                                                 0, 0.751057520686108, 0, 0.17863784828745, 0, 0.0153172071234649,
                                                 0, 9.57044116187268e-05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                 0, 0, 0, 0, 0, 9.61902739128473e-05, 0, 0.0153085619417029, 0,
                                                 0.178596350346924, 0, 0.751000329525689, 0, 1.67725643503247,
                                                 0, 2.19421288675405, 0, 1.67673692684187, 0, 0.751057520686108,
                                                 0, 0.178611592076099, 0, 0.0153052083946846, 0, 9.53250421932245e-05,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9.53250421932241e-05,
                                                 0, 0.0153052083946846, 0, 0.178611592076099, 0, 0.751057520686108,
                                                 0, 1.67673692684187, 0, 2.19421288675405, 0, 1.67725643503247,
                                                 0, 0.751000329525689, 0, 0.178596350346924, 0, 0.0153085619417029,
                                                 0, 9.61902739128473e-05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                 0, 0, 0, 0, 0, 9.57044116187261e-05, 0, 0.0153172071234649, 0,
                                                 0.178637848287449, 0, 0.751057520686107, 0, 1.67725643503247,
                                                 0, 2.19167865690685, 0, 1.67691161703102, 0, 0.74422331942289,
                                                 0, 0.168170211647943, 0, 0.0120248586792745, 0, 3.45007275290925e-05,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9.64175092058634e-05,
                                                 0, 0.015317207123465, 0, 0.178611592076099, 0, 0.751000329525689,
                                                 0, 1.67691161703101, 0, 2.16411927874826, 0, 1.53908699828218,
                                                 0, 0.549050844946754, 0, 0.0759808782995635, 0, 0.00157213610851394,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9.57044116187275e-05,
                                                 0, 0.0153052083946846, 0, 0.178596350346925, 0, 0.744223319422889,
                                                 0, 1.53908699828218, 0, 1.59744074560367, 0, 0.723386677289053,
                                                 0, 0.124017651192734, 0, 0.00389639710499402, 0, 5.05673652316932e-10,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9.53250421932245e-05,
                                                 0, 0.015308561941703, 0, 0.168170211647942, 0, 0.549050844946754,
                                                 0, 0.723386677289053, 0, 0.375690548876713, 0, 0.0661544886375023,
                                                 0, 0.00157010899258621, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9.61902739128465e-05, 0, 0.0120248586792744,
                                                 0, 0.0759808782995633, 0, 0.124017651192734, 0, 0.0661544886375021,
                                                 0, 0.00872963127077592, 0, 3.4496711175134e-05, 0, 0, 0, 0, 0,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3.45007275290909e-05,
                                                 0, 0.00157213610851391, 0, 0.00389639710499397, 0, 0.00157010899258619,
                                                 0, 3.44967111751334e-05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5.05673652316797e-10,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                 0, 0, 0, 0), .Dim = c(2L, 520L)), a_constraint = c(0, 0)))

    expect_equal(make_constraint(MRA, constraint = "unconstrained", joint = FALSE),
                 list(A_constraint = NULL, a_constraint = NULL))
    expect_equal(make_constraint(MRA, constraint = "overall", joint = FALSE),
                 list(A_constraint = structure(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                 0, 1.08601623125006e-05, 0.000112496007290721, 1.08654289635091e-05,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.000625061236957296, 0.0225489224875791,
                                                 0.0633262258769764, 0.0312738163856595, 0.00121730932738073,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 1.08601623125006e-05, 0.0225489224875791,
                                                 0.321435192757127, 0.857954760387478, 0.622740078658578, 0.113913040814712,
                                                 0.00180999093529261, 0, 0, 0, 0, 0, 0, 0, 0.000112496007290721,
                                                 0.0633262258769764, 0.857954760387478, 2.69320117577294, 2.6738302846565,
                                                 0.995571956296118, 0.1245002417436, 0.00180999093529261, 0, 0,
                                                 0, 0, 0, 0, 1.08654289635091e-05, 0.0312738163856595, 0.622740078658578,
                                                 2.6738302846565, 4.30156261189159, 3.04319377260997, 0.995571956296118,
                                                 0.113913040814712, 0.00121730932738073, 0, 0, 0, 0, 0, 0, 0.00121730932738073,
                                                 0.113913040814712, 0.995571956296118, 3.04319377260997, 4.30156261189159,
                                                 2.67383028465651, 0.622740078658578, 0.0312738163856595, 1.08654289635091e-05,
                                                 0, 0, 0, 0, 0, 0, 0.00180999093529261, 0.1245002417436, 0.995571956296118,
                                                 2.67383028465651, 2.69320117577294, 0.857954760387479, 0.0633262258769764,
                                                 0.000112496007290721, 0, 0, 0, 0, 0, 0, 0, 0.00180999093529261,
                                                 0.113913040814712, 0.622740078658578, 0.857954760387479, 0.321435192757127,
                                                 0.0225489224875791, 1.08601623125006e-05, 0, 0, 0, 0, 0, 0, 0,
                                                 0, 0.00121730932738073, 0.0312738163856595, 0.0633262258769764,
                                                 0.0225489224875791, 0.000625061236957296, 0, 0, 0, 0, 0, 0, 0,
                                                 0, 0, 0, 1.08654289635091e-05, 0.000112496007290721, 1.08601623125006e-05,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5.05673652316797e-10,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3.4496711175134e-05,
                                                 0.0015701089925862, 0.003896397104994, 0.00157213610851392, 3.45007275290915e-05,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3.44967111751343e-05, 0.00872963127077592,
                                                 0.0661544886375021, 0.124017651192734, 0.0759808782995632, 0.0120248586792744,
                                                 9.61902739128458e-05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.00157010899258622,
                                                 0.0661544886375023, 0.375690548876713, 0.723386677289052, 0.549050844946753,
                                                 0.168170211647942, 0.0153085619417029, 9.53250421932223e-05,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 5.05673652316932e-10, 0.00389639710499403,
                                                 0.124017651192734, 0.723386677289053, 1.59744074560367, 1.53908699828218,
                                                 0.744223319422889, 0.178596350346924, 0.0153052083946846, 9.57044116187268e-05,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.00157213610851394, 0.0759808782995634,
                                                 0.549050844946754, 1.53908699828218, 2.16411927874826, 1.67691161703102,
                                                 0.75100032952569, 0.178611592076099, 0.015317207123465, 9.6417509205864e-05,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 3.45007275290925e-05, 0.0120248586792744,
                                                 0.168170211647942, 0.744223319422889, 1.67691161703102, 2.19167865690685,
                                                 1.67725643503247, 0.751057520686108, 0.17863784828745, 0.0153172071234649,
                                                 9.57044116187268e-05, 0, 0, 0, 0, 0, 0, 0, 0, 9.61902739128473e-05,
                                                 0.0153085619417029, 0.178596350346924, 0.751000329525689, 1.67725643503247,
                                                 2.19421288675405, 1.67673692684187, 0.751057520686108, 0.178611592076099,
                                                 0.0153052083946846, 9.53250421932245e-05, 0, 0, 0, 0, 0, 0, 0,
                                                 0, 9.53250421932241e-05, 0.0153052083946846, 0.178611592076099,
                                                 0.751057520686108, 1.67673692684187, 2.19421288675405, 1.67725643503247,
                                                 0.751000329525689, 0.178596350346924, 0.0153085619417029, 9.61902739128473e-05,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 9.57044116187261e-05, 0.0153172071234649,
                                                 0.178637848287449, 0.751057520686107, 1.67725643503247, 2.19167865690685,
                                                 1.67691161703102, 0.74422331942289, 0.168170211647943, 0.0120248586792745,
                                                 3.45007275290925e-05, 0, 0, 0, 0, 0, 0, 0, 0, 9.64175092058634e-05,
                                                 0.015317207123465, 0.178611592076099, 0.751000329525689, 1.67691161703101,
                                                 2.16411927874826, 1.53908699828218, 0.549050844946754, 0.0759808782995635,
                                                 0.00157213610851394, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9.57044116187275e-05,
                                                 0.0153052083946846, 0.178596350346925, 0.744223319422889, 1.53908699828218,
                                                 1.59744074560367, 0.723386677289053, 0.124017651192734, 0.00389639710499402,
                                                 5.05673652316932e-10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9.53250421932245e-05,
                                                 0.015308561941703, 0.168170211647942, 0.549050844946754, 0.723386677289053,
                                                 0.375690548876713, 0.0661544886375023, 0.00157010899258621, 0,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9.61902739128465e-05, 0.0120248586792744,
                                                 0.0759808782995633, 0.124017651192734, 0.0661544886375021, 0.00872963127077592,
                                                 3.4496711175134e-05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3.45007275290909e-05,
                                                 0.00157213610851391, 0.00389639710499397, 0.00157010899258619,
                                                 3.44967111751334e-05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                 0, 0, 5.05673652316797e-10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), .Dim = c(1L, 520L)), a_constraint = 0))
    expect_equal(make_constraint(MRA, constraint = "resolution", joint = FALSE),
                 list(A_constraint = list(structure(c(0, 0, 0, 0, 0, 0, 0, 0,
                                                      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                      0, 0, 0, 1.08601623125006e-05, 0.000112496007290721, 1.08654289635091e-05,
                                                      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.000625061236957296, 0.0225489224875791,
                                                      0.0633262258769764, 0.0312738163856595, 0.00121730932738073,
                                                      0, 0, 0, 0, 0, 0, 0, 0, 1.08601623125006e-05, 0.0225489224875791,
                                                      0.321435192757127, 0.857954760387478, 0.622740078658578, 0.113913040814712,
                                                      0.00180999093529261, 0, 0, 0, 0, 0, 0, 0, 0.000112496007290721,
                                                      0.0633262258769764, 0.857954760387478, 2.69320117577294, 2.6738302846565,
                                                      0.995571956296118, 0.1245002417436, 0.00180999093529261, 0, 0,
                                                      0, 0, 0, 0, 1.08654289635091e-05, 0.0312738163856595, 0.622740078658578,
                                                      2.6738302846565, 4.30156261189159, 3.04319377260997, 0.995571956296118,
                                                      0.113913040814712, 0.00121730932738073, 0, 0, 0, 0, 0, 0, 0.00121730932738073,
                                                      0.113913040814712, 0.995571956296118, 3.04319377260997, 4.30156261189159,
                                                      2.67383028465651, 0.622740078658578, 0.0312738163856595, 1.08654289635091e-05,
                                                      0, 0, 0, 0, 0, 0, 0.00180999093529261, 0.1245002417436, 0.995571956296118,
                                                      2.67383028465651, 2.69320117577294, 0.857954760387479, 0.0633262258769764,
                                                      0.000112496007290721, 0, 0, 0, 0, 0, 0, 0, 0.00180999093529261,
                                                      0.113913040814712, 0.622740078658578, 0.857954760387479, 0.321435192757127,
                                                      0.0225489224875791, 1.08601623125006e-05, 0, 0, 0, 0, 0, 0, 0,
                                                      0, 0.00121730932738073, 0.0312738163856595, 0.0633262258769764,
                                                      0.0225489224875791, 0.000625061236957296, 0, 0, 0, 0, 0, 0, 0,
                                                      0, 0, 0, 1.08654289635091e-05, 0.000112496007290721, 1.08601623125006e-05,
                                                      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), .Dim = c(1L, 196L)),
                                          structure(c(0,
                                                      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                      0, 5.05673652316797e-10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                      0, 0, 0, 3.4496711175134e-05, 0.0015701089925862, 0.003896397104994,
                                                      0.00157213610851392, 3.45007275290915e-05, 0, 0, 0, 0, 0, 0,
                                                      0, 0, 0, 0, 0, 0, 3.44967111751343e-05, 0.00872963127077592,
                                                      0.0661544886375021, 0.124017651192734, 0.0759808782995632, 0.0120248586792744,
                                                      9.61902739128458e-05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.00157010899258622,
                                                      0.0661544886375023, 0.375690548876713, 0.723386677289052, 0.549050844946753,
                                                      0.168170211647942, 0.0153085619417029, 9.53250421932223e-05,
                                                      0, 0, 0, 0, 0, 0, 0, 0, 0, 5.05673652316932e-10, 0.00389639710499403,
                                                      0.124017651192734, 0.723386677289053, 1.59744074560367, 1.53908699828218,
                                                      0.744223319422889, 0.178596350346924, 0.0153052083946846, 9.57044116187268e-05,
                                                      0, 0, 0, 0, 0, 0, 0, 0, 0, 0.00157213610851394, 0.0759808782995634,
                                                      0.549050844946754, 1.53908699828218, 2.16411927874826, 1.67691161703102,
                                                      0.75100032952569, 0.178611592076099, 0.015317207123465, 9.6417509205864e-05,
                                                      0, 0, 0, 0, 0, 0, 0, 0, 3.45007275290925e-05, 0.0120248586792744,
                                                      0.168170211647942, 0.744223319422889, 1.67691161703102, 2.19167865690685,
                                                      1.67725643503247, 0.751057520686108, 0.17863784828745, 0.0153172071234649,
                                                      9.57044116187268e-05, 0, 0, 0, 0, 0, 0, 0, 0, 9.61902739128473e-05,
                                                      0.0153085619417029, 0.178596350346924, 0.751000329525689, 1.67725643503247,
                                                      2.19421288675405, 1.67673692684187, 0.751057520686108, 0.178611592076099,
                                                      0.0153052083946846, 9.53250421932245e-05, 0, 0, 0, 0, 0, 0, 0,
                                                      0, 9.53250421932241e-05, 0.0153052083946846, 0.178611592076099,
                                                      0.751057520686108, 1.67673692684187, 2.19421288675405, 1.67725643503247,
                                                      0.751000329525689, 0.178596350346924, 0.0153085619417029, 9.61902739128473e-05,
                                                      0, 0, 0, 0, 0, 0, 0, 0, 9.57044116187261e-05, 0.0153172071234649,
                                                      0.178637848287449, 0.751057520686107, 1.67725643503247, 2.19167865690685,
                                                      1.67691161703102, 0.74422331942289, 0.168170211647943, 0.0120248586792745,
                                                      3.45007275290925e-05, 0, 0, 0, 0, 0, 0, 0, 0, 9.64175092058634e-05,
                                                      0.015317207123465, 0.178611592076099, 0.751000329525689, 1.67691161703101,
                                                      2.16411927874826, 1.53908699828218, 0.549050844946754, 0.0759808782995635,
                                                      0.00157213610851394, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9.57044116187275e-05,
                                                      0.0153052083946846, 0.178596350346925, 0.744223319422889, 1.53908699828218,
                                                      1.59744074560367, 0.723386677289053, 0.124017651192734, 0.00389639710499402,
                                                      5.05673652316932e-10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9.53250421932245e-05,
                                                      0.015308561941703, 0.168170211647942, 0.549050844946754, 0.723386677289053,
                                                      0.375690548876713, 0.0661544886375023, 0.00157010899258621, 0,
                                                      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9.61902739128465e-05, 0.0120248586792744,
                                                      0.0759808782995633, 0.124017651192734, 0.0661544886375021, 0.00872963127077592,
                                                      3.4496711175134e-05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3.45007275290909e-05,
                                                      0.00157213610851391, 0.00389639710499397, 0.00157010899258619,
                                                      3.44967111751334e-05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                      0, 0, 5.05673652316797e-10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), .Dim = c(1L, 324L))), a_constraint = list(
                                                          0, 0)))
    MRA <- mra_wendland_2d(locs, M = 2, n_coarse_grid = 4)
    class(MRA) <- NULL
    expect_error(make_constraint(MRA), 'MRA must be of class "mra_wendland_2d" which is the output of mra_wendland_1d()')
    class(MRA) <- "aaa"
    expect_error(make_constraint(MRA), 'MRA must be of class "mra_wendland_2d" which is the output of mra_wendland_1d()')
    MRA <- mra_wendland_2d(locs, M = 2, n_coarse_grid = 4)
    expect_error(make_constraint(MRA, constraint = "predicted"), 'constraint = \"predicted\" is not currently supported -- developer note: add W_pred to function call to enable this in future results')
    expect_error(make_constraint(MRA, constraint = "adsfs"), 'constraint must be either \"unconstrained\", \"overall\", \"resolution\", or \"predicted\"')
    expect_error(make_constraint(MRA, constraint = TRUE), 'constraint must be either \"unconstrained\", \"overall\", \"resolution\", or \"predicted\"')
    expect_error(make_constraint(MRA, constraint = 33), 'constraint must be either \"unconstrained\", \"overall\", \"resolution\", or \"predicted\"')
    expect_error(make_constraint(MRA, constraint = NA), 'constraint must be either \"unconstrained\", \"overall\", \"resolution\", or \"predicted\"')
    expect_error(make_constraint(MRA, joint = "TRUE"), 'joint must be either TRUE or FALSE.')
    expect_error(make_constraint(MRA, joint = 35), 'joint must be either TRUE or FALSE.')
    expect_error(make_constraint(MRA, joint = NA), 'joint must be either TRUE or FALSE.')
})
jtipton25/BayesMRA documentation built on Feb. 28, 2024, 1:27 p.m.