xref: /aosp_15_r20/external/rappor/tests/gen_true_values_test.R (revision 2abb31345f6c95944768b5222a9a5ed3fc68cc00)
1#!/usr/bin/Rscript
2#
3# gen_reports_test.R
4
5source('analysis/R/util.R')  # Log()
6
7source('tests/gen_true_values.R')  # module under test
8
9library(RUnit)
10
11TestGenerateTrueValues = function() {
12  num_clients <- 10
13  reports_per_client <- 2
14  num_cohorts <- 4
15  reports <- GenerateTrueValues('exp', 10, num_clients, reports_per_client,
16                                num_cohorts)
17  print(reports)
18
19  # 10 clients, 2 reports per client
20  checkEquals(20, nrow(reports))
21
22  # 10 unique clients
23  checkEquals(10, length(unique(reports$client)))
24
25  # Whether a given client reports different values
26  reports_different_values <- rep(FALSE, num_clients)
27
28  for (c in 1:num_clients) {
29    my_reports <- reports[reports$client == c, ]
30    #Log("CLIENT %d", c)
31    #print(my_reports)
32
33    # If every report for this client isn't same, make note of it
34    if (length(unique(my_reports$value)) != 1) {
35      reports_different_values[[c]] <- TRUE
36    }
37  }
38
39  # At least one client should report different values.  (Technically this
40  # could fail, but is unlikely with 10 clients).
41  checkTrue(any(reports_different_values))
42
43  checkEquals(num_cohorts, length(unique(reports$cohort)))
44}
45
46TestAll <- function(){
47  TestGenerateTrueValues()
48}
49
50TestAll()
51