tests/testthat/test-smooth.R

context("Smooth series")

search.share <- structure(c(1.47058823529412, 14.2857142857143, 22.2222222222222,
                                6.25, 60, 41.6666666666667, 26.3157894736842, 53.8461538461538,
                                42.8571428571429, 45, 57.1428571428571, 55.5555555555556, 78.5714285714286,
                                77.7777777777778, 66.6666666666667, 59.2592592592593, 60, 90,
                                100, 78.9473684210526, 80, 83.3333333333333, 100, NaN, 85.7142857142857,
                                NaN, 50, 100, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN,
                                NaN, NaN), .Names = c("Week 1 n:136", "2 n:21", "3 n:18", "4 n:16",
                                "5 n:5", "6 n:12", "7 n:19", "8 n:13", "9 n:21", "10 n:20", "11 n:7",
                                "12 n:9", "13 n:14", "14 n:18", "15 n:9", "16 n:27", "17 n:10",
                                "18 n:10", "19 n:6", "20 n:19", "21 n:10", "22 n:6", "23 n:4",
                                "24 n:0", "25 n:7", "26 n:0", "27 n:2", "28 n:1", "29 n:0", "30 n:0",
                                "31 n:0", "32 n:0", "33 n:0", "34 n:0", "35 n:0", "36 n:0", "37 n:0",
                                "38 n:0", "39 n:0", "40 n:0"))

dup.values <- structure(c(6L, 5L, 3L, 3L, 3L, 2L, 4L, 2L, 9L, 2L, 6L, 4L, 7L,
    6L, 10L, 7L, 6L, 2L, 3L, 5L), .Dim = c(10L, 2L), .Dimnames = list(
    c("A", "B", "C", "A", "B", "C", "D", "D", "D", "D"), NULL))

dat <- structure(c(0.326848249027237, 0.350194552529183, 0.32295719844358,
    0.354838709677419, 0.338709677419355, 0.306451612903226, 0.317307692307692,
    0.326923076923077, 0.355769230769231, 0.309090909090909, 0.363636363636364,
    0.327272727272727, 0.25, 0.4375, 0.3125, 0.393617021276596, 0.25531914893617,
    0.351063829787234, 0, 0.5, 0.5, 0.375, 0.25, 0.375), .Dim = c(3L,
    8L), statistic = "Column %", name = "table.Date.of.Interview.by.Q3.Preferred.cola", questions = c("Date of Interview",
    "Q3 - Preferred cola"), assigned.rownames = TRUE, .Dimnames = list(
        c("Jan-Mar 17", "Apr-Jun 17", "Jul-Sep 17"), c("Coca-Cola",
        "Diet Coke", "Coke Zero", "Pepsi ", "Diet Pepsi", "Pepsi Max",
        "Dislike all cola", "Don't care")))
xx <- c(`1` = 1, `2` = 2, `3` = 3, `5` = 4, `6` = 5, `7` = 6, `8` = 7)

monthly.dat <- structure(c(74.4444444444444, 73.7556561085973, 75.462962962963,
73.953488372093, 71.6312056737589, 74.054054054054, 79.7202797202797,
78.9115646258503, 74.585635359116, 69.5652173913043, 77.1812080536913,
75.8241758241758, 75.8389261744966, 72.2222222222222, 75.1381215469613,
69.9346405228758, 77.3722627737226, 76.1111111111111, 75.8620689655172,
73.6111111111111, 78.9772727272727, 78.0821917808219, 77.5510204081633,
76.1627906976744, 80, 83.2402234636871, 79.5454545454545, 78.0821917808219,
77.0949720670391, 80.2816901408451, 98.5185185185185, 98.1900452488688,
97.6851851851852, 97.2093023255814, 97.8723404255319, 97.8378378378378,
98.6013986013986, 97.2789115646258, 97.7900552486188, 98.5507246376812,
98.6577181208054, 98.3516483516484, 94.6308724832215, 96.5277777777778,
96.6850828729282, 94.7712418300653, 98.5401459854015, 97.2222222222222,
97.2413793103448, 99.3055555555556, 98.2954545454545, 97.2602739726027,
95.9183673469388, 94.7674418604651, 97.4193548387097, 98.3240223463687,
96.969696969697, 96.5753424657534, 94.9720670391062, 98.5915492957747,
20, 21.2669683257919, 26.3888888888889, 21.3953488372093, 15.6028368794326,
18.3783783783784, 22.3776223776224, 29.9319727891156, 27.0718232044199,
34.7826086956522, 33.5570469798658, 36.2637362637363, 41.6107382550336,
40.2777777777778, 49.7237569060773, 49.0196078431373, 61.3138686131387,
57.7777777777778, 64.8275862068965, 59.7222222222222, 68.75,
64.3835616438356, 63.9455782312925, 67.4418604651163, 64.5161290322581,
73.7430167597765, 70.4545454545455, 71.9178082191781, 64.804469273743,
73.943661971831, 94.4444444444444, 95.9276018099548, 93.9814814814815,
94.8837209302326, 93.6170212765958, 94.0540540540541, 95.8041958041958,
95.9183673469388, 93.9226519337017, 95.6521739130435, 97.3154362416107,
97.2527472527473, 93.2885906040269, 93.75, 96.1325966850829,
92.8104575163399, 97.8102189781022, 93.3333333333333, 94.4827586206897,
96.5277777777778, 96.5909090909091, 95.8904109589041, 95.2380952380952,
92.4418604651163, 94.1935483870968, 97.7653631284916, 91.6666666666667,
95.2054794520548, 92.1787709497207, 95.7746478873239, 92.962962962963,
94.5701357466063, 93.0555555555556, 93.4883720930233, 88.6524822695035,
90.2702702702703, 97.2027972027972, 94.5578231292517, 91.7127071823204,
94.2028985507246, 91.9463087248322, 95.6043956043956, 88.5906040268456,
88.8888888888889, 90.0552486187845, 86.9281045751634, 97.8102189781022,
91.1111111111111, 92.4137931034483, 87.5, 93.1818181818182, 84.9315068493151,
92.5170068027211, 89.5348837209302, 90.3225806451613, 94.413407821229,
90.9090909090909, 91.0958904109589, 86.5921787709497, 92.2535211267606,
98.5185185185185, 97.737556561086, 99.0740740740741, 96.7441860465116,
96.4539007092199, 98.9189189189189, 98.6013986013986, 97.9591836734694,
97.2375690607735, 98.5507246376812, 97.9865771812081, 100, 98.6577181208054,
97.2222222222222, 97.2375690607735, 97.3856209150327, 98.5401459854015,
97.7777777777778, 95.8620689655172, 98.6111111111111, 98.2954545454545,
98.6301369863014, 96.5986394557823, 97.6744186046512, 96.7741935483871,
98.3240223463687, 98.4848484848485, 98.6301369863014, 96.0893854748603,
97.887323943662, 98.5185185185185, 98.6425339366516, 99.0740740740741,
98.1395348837209, 99.290780141844, 98.3783783783784, 99.3006993006993,
98.6394557823129, 97.7900552486188, 98.5507246376812, 99.3288590604027,
100, 97.9865771812081, 97.2222222222222, 98.3425414364641, 98.6928104575163,
97.8102189781022, 98.3333333333333, 99.3103448275862, 99.3055555555556,
98.8636363636364, 100, 95.2380952380952, 97.0930232558139, 98.7096774193548,
97.7653631284916, 98.4848484848485, 96.5753424657534, 98.3240223463687,
96.4788732394366, 96.2962962962963, 96.8325791855204, 96.2962962962963,
95.8139534883721, 94.3262411347518, 95.1351351351351, 96.5034965034965,
95.9183673469388, 94.475138121547, 97.1014492753623, 95.9731543624161,
97.8021978021978, 92.6174496644295, 95.1388888888889, 95.0276243093923,
93.4640522875817, 97.0802919708029, 96.1111111111111, 96.551724137931,
97.9166666666667, 95.4545454545455, 95.8904109589041, 95.2380952380952,
92.4418604651163, 92.258064516129, 98.3240223463687, 92.4242424242424,
95.8904109589041, 93.2960893854749, 95.7746478873239, 98.1481481481482,
97.737556561086, 95.8333333333333, 97.6744186046512, 96.4539007092199,
95.6756756756757, 99.3006993006993, 97.2789115646258, 95.0276243093923,
97.1014492753623, 97.9865771812081, 98.3516483516484, 94.6308724832215,
94.4444444444444, 95.5801104972376, 95.4248366013072, 98.5401459854015,
96.6666666666667, 95.1724137931034, 98.6111111111111, 98.2954545454545,
94.5205479452055, 95.2380952380952, 95.3488372093023, 97.4193548387097,
98.3240223463687, 96.969696969697, 96.5753424657534, 96.0893854748603,
96.4788732394366, 92.2222222222222, 91.8552036199095, 91.6666666666667,
92.093023255814, 93.6170212765958, 87.027027027027, 95.1048951048951,
91.8367346938776, 87.8453038674033, 86.9565217391304, 91.2751677852349,
91.2087912087912, 87.9194630872483, 88.1944444444444, 87.292817679558,
92.156862745098, 88.3211678832117, 88.8888888888889, 91.7241379310345,
91.6666666666667, 94.3181818181818, 90.4109589041096, 88.4353741496599,
88.3720930232558, 88.3870967741936, 94.413407821229, 90.9090909090909,
93.1506849315068, 87.1508379888268, 93.6619718309859, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 20.1342281879195, 47.2527472527472, 45.6375838926174,
46.5277777777778, 51.3812154696133, 49.0196078431373, 57.6642335766423,
60, 55.8620689655172, 58.3333333333333, 59.0909090909091, 64.3835616438356,
62.5850340136054, 68.6046511627907, 63.8709677419355, 72.0670391061452,
75.7575757575758, 71.2328767123288, 69.2737430167598, 80.9859154929577,
85.1851851851852, 89.1402714932127, 89.3518518518518, 89.7674418604651,
81.5602836879433, 84.8648648648649, 90.9090909090909, 91.8367346938776,
85.6353591160221, 88.4057971014493, 83.8926174496644, 87.3626373626374,
85.2348993288591, 84.7222222222222, 83.9779005524862, 83.0065359477124,
90.5109489051095, 83.8888888888889, 87.5862068965517, 86.8055555555556,
89.2045454545455, 90.4109589041096, 81.6326530612245, 85.4651162790698,
83.8709677419355, 88.268156424581, 92.4242424242424, 87.6712328767123,
79.8882681564246, 85.9154929577465, 93.7037037037037, 96.8325791855204,
94.4444444444444, 93.953488372093, 91.4893617021277, 90.8108108108108,
97.2027972027972, 95.9183673469388, 93.3701657458564, 94.2028985507246,
94.6308724832215, 96.1538461538462, 90.6040268456376, 91.6666666666667,
88.9502762430939, 90.1960784313726, 96.3503649635037, 91.1111111111111,
91.0344827586207, 92.3611111111111, 96.0227272727273, 91.7808219178082,
90.4761904761905, 89.5348837209302, 92.9032258064516, 93.854748603352,
93.1818181818182, 93.8356164383562, 86.5921787709497, 94.3661971830986,
24.8148148148148, 21.2669683257919, 24.537037037037, 25.1162790697674,
19.1489361702128, 27.027027027027, 25.1748251748252, 25.8503401360544,
29.2817679558011, 21.7391304347826, 20.8053691275168, 25.8241758241758,
20.1342281879195, 29.8611111111111, 20.4419889502762, 24.1830065359477,
24.8175182481752, 23.8888888888889, 24.1379310344828, 16.6666666666667,
31.8181818181818, 24.6575342465753, 28.5714285714286, 25.5813953488372,
27.741935483871, 27.9329608938547, 28.7878787878788, 25.3424657534247,
25.1396648044693, 27.4647887323944, 0, 0, 0, 0, 0, 0, 0, 0, 0.552486187845304,
1.44927536231884, 0, 0, 0, 0.694444444444444, 0.552486187845304,
0, 0.72992700729927, 0, 0, 0, 0, 0, 0.680272108843537, 0.581395348837209,
0, 0, 0, 0, 0, 0, 100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100, 100, 100, 100, 100, 100, 100), statistic = "Row %", .Dim = c(30L,
16L), .Dimnames = list(c("July 2015", "August 2015", "September 2015",
"October 2015", "November 2015", "December 2015", "January 2016",
"February 2016", "March 2016", "April 2016", "May 2016", "June 2016",
"July 2016", "August 2016", "September 2016", "October 2016",
"November 2016", "December 2016", "January 2017", "February 2017",
"March 2017", "April 2017", "May 2017", "June 2017", "July 2017",
"August 2017", "September 2017", "October 2017", "November 2017",
"December 2017"), c("Burger Shack", "Burger Chef", "Nuovo Burger",
"Lucky's Pizza", "Pizza Heaven", "Southern Fried Chicken", "Arnold's",
"Nero's Pizza", "Pret'a'pane", "Ma's burgers", "Bread Basket",
"Asian", "Mexican", "Other fast food", "None of these", "NET"
)), name = "table.Date.by.Q1.Aided.brand.awareness", questions = c("Date",
"Q1. Aided brand awareness"))

test_that("line-of-best-fit",
{
    expect_warning(Column(search.share, fit.type = "Friedman"), "Missing values have been set to zero")
    expect_warning(Column(search.share, fit.type = "LOESS"), "Missing values have been set to zero")
    expect_warning(Column(search.share, fit.type = "Linear"), "Missing values have been set to zero")
    expect_warning(Scatter(dup.values, fit.type = "Friedman"), "Multiple points at the same x-coordinate ignored for estimating line of best fit.")

    expect_error(SmallMultiples(dat, "Column", fit.type = "Moving averages", fit.window.size = 2), NA) # no warnings
    expect_warning(Column(dat[,1,drop=FALSE], fit.type = "Moving average", fit.window.size = 3), "Trend line could not be shown")
    expect_warning(Column(xx, fit.type = "Moving average"), "Moving averages do not account for the different intervals between values")
    expect_error(Line(monthly.dat, fit.type = "Moving average"), NA)

})
Displayr/flipStandardCharts documentation built on May 2, 2024, 6:22 p.m.