library(dplyr)
library(distributional)
context("plinko_board-properties")
set.seed(1234)
board = plinko_board(dist_normal(1,2), n_ball = 6, n_bin = 3)
test_that("slot_edges() works", {
ref = tibble(
x = c(-3.61880215351701, -1.3094010767585, 1, 3.3094010767585, 5.61880215351701),
height = c(22.1702503368816, 8.31384387633061, 8.31384387633061, 8.31384387633061, 22.1702503368816)
)
expect_equal(slot_edges(board), ref)
})
test_that("pins() works", {
ref = tibble(
x = c(-1.3094010767585, 1, 3.3094010767585, -0.154700538379251, 2.15470053837925, -1.3094010767585, 1, 3.3094010767585),
y = c(17.5514481833646, 17.5514481833646, 17.5514481833646, 12.9326460298476, 12.9326460298476, 8.31384387633061, 8.31384387633061, 8.31384387633061)
)
expect_equal(pins(board), ref)
})
test_that("paths() works", {
ref = tibble(
ball_id = c(1L, 2L, 3L, 4L, 5L, 6L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 1L, 2L, 3L, 4L, 5L, 6L),
move_id = c(1, 1, 1, 1, 1, 1, 2, 3, 4, 5, 2, 3, 4, 5, 2, 3, 4, 5, 2, 3, 4, 5, 2, 3, 4, 5, 2, 3, 4, 5, 6, 6, 6, 6, 6, 6),
bin = c(2, 1, 2, 0, 3, 1, 2, 2, 2, 2, 1, 1, 1, 1, 2, 2, 2, 2, 0, 0, 0, 0, 3, 3, 3, 3, 1, 1, 1, 1, 2, 1, 2, 0, 3, 1),
pin = c(4, 2, 4, 0, 6, 2, 4, 4, 4, 4, 2, 2, 2, 2, 4, 4, 4, 4, 0, 0, 0, 0, 6, 6, 6, 6, 2, 2, 2, 2, 4, 2, 4, 0, 6, 2),
x = c(1, 1, 1, 1, 1, 1, 1, 2.15470053837925, 3.3094010767585, 2.15470053837925, 1, -0.154700538379251, -1.3094010767585, -0.154700538379251, 1, -0.154700538379251, 1, 2.15470053837925, 1, -0.154700538379251, -1.3094010767585, -2.46410161513775, 1, 2.15470053837925, 3.3094010767585, 4.46410161513775, 1, -0.154700538379251, -1.3094010767585, -0.154700538379251, 2.15470053837925, -0.154700538379251, 2.15470053837925, -2.46410161513775, 4.46410161513775, -0.154700538379251 ),
y = c(41.684689435491, 41.684689435491, 41.684689435491, 41.684689435491, 41.684689435491, 41.684689435491, 18.590678667906, 13.9718765143889, 9.35307436087194, 4.73427220735493, 18.590678667906, 13.9718765143889, 9.35307436087194, 4.73427220735493, 18.590678667906, 13.9718765143889, 9.35307436087194, 4.73427220735493, 18.590678667906, 13.9718765143889, 9.35307436087194, 4.73427220735493, 18.590678667906, 13.9718765143889, 9.35307436087194, 4.73427220735493, 18.590678667906, 13.9718765143889, 9.35307436087194, 4.73427220735493, 1.03923048454133, 1.03923048454133, 3.11769145362398, 1.03923048454133, 1.03923048454133, 3.11769145362398 ),
width = c(2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265),
region = c("start", "start", "start", "start", "start", "start", "pin", "pin", "pin", "slot", "pin", "pin", "pin", "slot", "pin", "pin", "pin", "slot", "pin", "pin", "pin", "slot", "pin", "pin", "pin", "slot", "pin", "pin", "pin", "slot", "slot", "slot", "slot", "slot", "slot", "slot")
)
expect_equal(paths(board), ref)
})
test_that("balls() works", {
ref = tibble(
ball_id = 1:6,
move_id = c(6, 6, 6, 6, 6, 6),
bin = c(2, 1, 2, 0, 3, 1),
pin = c(4, 2, 4, 0, 6, 2),
x = c(2.15470053837925, -0.154700538379251, 2.15470053837925, -2.46410161513775, 4.46410161513775, -0.154700538379251),
y = c(1.03923048454133, 1.03923048454133, 3.11769145362398, 1.03923048454133, 1.03923048454133, 3.11769145362398),
width = c(2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265),
region = c("slot", "slot", "slot", "slot", "slot", "slot"),
stopped = FALSE,
stopped_for = 0
)
expect_equal(balls(board), ref)
})
test_that("frames() works", {
ref = tibble(
frame_id = c(1L, 2L, 3L, 4L, 5L, 5L, 6L, 6L, 7L, 7L, 8L, 8L, 9L, 9L, 9L, 10L, 10L, 10L, 11L, 11L, 11L, 12L, 12L, 12L, 13L, 13L, 13L, 13L, 14L, 14L, 14L, 14L, 15L, 15L, 15L, 15L, 16L, 16L, 16L, 16L, 17L, 17L, 17L, 17L, 17L, 18L, 18L, 18L, 18L, 18L, 19L, 19L, 19L, 19L, 19L, 20L, 20L, 20L, 20L, 20L, 21L, 21L, 21L, 21L, 21L, 21L, 22L, 22L, 22L, 22L, 22L, 22L, 23L, 23L, 23L, 23L, 23L, 23L, 24L, 24L, 24L, 24L, 24L, 24L, 25L, 25L, 25L, 25L, 25L, 25L, 26L, 26L, 26L, 26L, 26L, 26L, 27L, 27L, 27L, 27L, 27L, 27L),
ball_id = c(1L, 1L, 1L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 3L, 2L, 1L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 4L, 3L, 1L, 2L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 5L, 4L, 1L, 2L, 3L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 6L, 5L, 1L, 2L, 3L, 4L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L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925, 3.3094010767585, 1, 2.15470053837925, 1, 2.15470053837925, -0.154700538379251, 2.15470053837925, -1.3094010767585, 2.15470053837925, 1, -0.154700538379251, 2.15470053837925, 1, 2.15470053837925, -0.154700538379251, -0.154700538379251, 2.15470053837925, -0.154700538379251, 1, 2.15470053837925, -0.154700538379251, 1, 2.15470053837925, 2.15470053837925, -0.154700538379251, 1, 2.15470053837925, -0.154700538379251, 2.15470053837925, -0.154700538379251, 2.15470053837925, -0.154700538379251, 2.15470053837925, -1.3094010767585, 2.15470053837925, -0.154700538379251, 2.15470053837925, 1, -2.46410161513775, 2.15470053837925, -0.154700538379251, 2.15470053837925, 1, 2.15470053837925, -0.154700538379251, 2.15470053837925, -2.46410161513775, 2.15470053837925, 2.15470053837925, -0.154700538379251, 2.15470053837925, -2.46410161513775, 3.3094010767585, 2.15470053837925, -0.154700538379251, 2.15470053837925, -2.46410161513775, 1, 4.46410161513775, 2.15470053837925, -0.154700538379251, 2.15470053837925, -2.46410161513775, 1, 2.15470053837925, -0.154700538379251, 2.15470053837925, -2.46410161513775, 4.46410161513775, -0.154700538379251, 2.15470053837925, -0.154700538379251, 2.15470053837925, -2.46410161513775, 4.46410161513775, -1.3094010767585, 2.15470053837925, -0.154700538379251, 2.15470053837925, -2.46410161513775, 4.46410161513775, -0.154700538379251, 2.15470053837925, -0.154700538379251, 2.15470053837925, -2.46410161513775, 4.46410161513775, 2.15470053837925, -0.154700538379251, 2.15470053837925, -2.46410161513775, 4.46410161513775, -0.154700538379251, 2.15470053837925, -0.154700538379251, 2.15470053837925, -2.46410161513775, 4.46410161513775, -0.154700538379251),
y = c(41.684689435491, 18.590678667906, 13.9718765143889, 9.35307436087194, 41.684689435491, 4.73427220735493, 18.590678667906, 1.03923048454133, 13.9718765143889, 1.03923048454133, 9.35307436087194, 1.03923048454133, 41.684689435491, 4.73427220735493, 1.03923048454133, 18.590678667906, 1.03923048454133, 1.03923048454133, 13.9718765143889, 1.03923048454133, 1.03923048454133, 9.35307436087194, 1.03923048454133, 1.03923048454133, 41.684689435491, 4.73427220735493, 1.03923048454133, 1.03923048454133, 18.590678667906, 1.03923048454133, 1.03923048454133, 3.11769145362398, 13.9718765143889, 1.03923048454133, 1.03923048454133, 3.11769145362398, 9.35307436087194, 1.03923048454133, 1.03923048454133, 3.11769145362398, 41.684689435491, 4.73427220735493, 1.03923048454133, 1.03923048454133, 3.11769145362398, 18.590678667906, 1.03923048454133, 1.03923048454133, 3.11769145362398, 1.03923048454133, 13.9718765143889, 1.03923048454133, 1.03923048454133, 3.11769145362398, 1.03923048454133, 9.35307436087194, 1.03923048454133, 1.03923048454133, 3.11769145362398, 1.03923048454133, 41.684689435491, 4.73427220735493, 1.03923048454133, 1.03923048454133, 3.11769145362398, 1.03923048454133, 18.590678667906, 1.03923048454133, 1.03923048454133, 3.11769145362398, 1.03923048454133, 1.03923048454133, 13.9718765143889, 1.03923048454133, 1.03923048454133, 3.11769145362398, 1.03923048454133, 1.03923048454133, 9.35307436087194, 1.03923048454133, 1.03923048454133, 3.11769145362398, 1.03923048454133, 1.03923048454133, 4.73427220735493, 1.03923048454133, 1.03923048454133, 3.11769145362398, 1.03923048454133, 1.03923048454133, 1.03923048454133, 1.03923048454133, 3.11769145362398, 1.03923048454133, 1.03923048454133, 3.11769145362398, 1.03923048454133, 1.03923048454133, 3.11769145362398, 1.03923048454133, 1.03923048454133, 3.11769145362398),
width = c(2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265, 2.07846096908265),
region = c("start", "pin", "pin", "pin", "start", "slot", "pin", "slot", "pin", "slot", "pin", "slot", "start", "slot", "slot", "pin", "slot", "slot", "pin", "slot", "slot", "pin", "slot", "slot", "start", "slot", "slot", "slot", "pin", "slot", "slot", "slot", "pin", "slot", "slot", "slot", "pin", "slot", "slot", "slot", "start", "slot", "slot", "slot", "slot", "pin", "slot", "slot", "slot", "slot", "pin", "slot", "slot", "slot", "slot", "pin", "slot", "slot", "slot", "slot", "start", "slot", "slot", "slot", "slot", "slot", "pin", "slot", "slot", "slot", "slot", "slot", "pin", "slot", "slot", "slot", "slot", "slot", "pin", "slot", "slot", "slot", "slot", "slot", "slot", "slot", "slot", "slot", "slot", "slot", "slot", "slot", "slot", "slot", "slot", "slot", "slot", "slot", "slot", "slot", "slot", "slot"),
stopped = c(FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, TRUE, FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, FALSE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, FALSE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE),
stopped_for = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 0, 0, 3, 0, 4, 0, 0, 5, 1, 0, 6, 2, 0, 0, 7, 3, 0, 8, 4, 0, 0, 9, 5, 1, 0, 10, 6, 2, 0, 0, 11, 7, 3, 0, 12, 8, 4, 0, 0, 13, 9, 5, 1, 0, 14, 10, 6, 2, 0, 0, 15, 11, 7, 3, 0, 16, 12, 8, 4, 0, 0, 17, 13, 9, 5, 1, 0, 18, 14, 10, 6, 2, 0, 19, 15, 11, 7, 3, 20, 16, 12, 8, 4, 0, 21, 17, 13, 9, 5, 1)
)
expect_equal(frames(board), ref)
})
test_that("n_frame() works", {
expect_equal(n_frame(board), 27)
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.