<commit_before>#!/bin/bash
#
# Simple smoke test for the decode-dist tool.  This will fail if your machine
# doesn't have the right R libraries.
#
# Usage:
#   ./test.sh <function name>
#
# Example:
#   ./test.sh write-assoc-testdata       # write data needed for R and C++ tests
#   ./test.sh decode-assoc-R-smoke       # test pure R implementation
#   ./test.sh decode-assoc-cpp-smoke     # test with analysis/cpp/fast_em.cc
#   ./test.sh decode-assoc-cpp-converge  # run for longer with C++
#   ./test.sh decode-assoc-tensorflow

set -o nounset
set -o pipefail
set -o errexit

readonly THIS_DIR=$(dirname $0)
readonly RAPPOR_SRC=$(cd $THIS_DIR/.. && pwd)
readonly EM_CPP_EXECUTABLE=$RAPPOR_SRC/analysis/cpp/_tmp/fast_em

source $RAPPOR_SRC/util.sh


decode-dist-help() {
  time $RAPPOR_SRC/bin/decode-dist --help
}

decode-dist() {
  # ./demo.sh quick-python creates these files
  local case_dir=$RAPPOR_SRC/_tmp/python/demo3

  mkdir -p _tmp

  # Uses the ./demo.sh regtest files
  time $RAPPOR_SRC/bin/decode-dist \
    --counts $case_dir/1/case_counts.csv \
    --map $case_dir/case_map.csv \
    --params $case_dir/case_params.csv \
    --output-dir _tmp

  echo
  head _tmp/results.csv 
  echo
  cat _tmp/metrics.json
}

decode-assoc-help() {
  time $RAPPOR_SRC/bin/decode-assoc --help
}

write-assoc-testdata() {
  mkdir -p _tmp

  cat >_tmp/true_values.csv <<EOF 
domain,flag..HTTPS<commit_msg>clear cached .rda files every time testdata is written<commit_after>#!/bin/bash
#
# Simple smoke test for the decode-dist tool.  This will fail if your machine
# doesn't have the right R libraries.
#
# Usage:
#   ./test.sh <function name>
#
# Example:
#   ./test.sh write-assoc-testdata       # write data needed for R and C++ tests
#   ./test.sh decode-assoc-R-smoke       # test pure R implementation
#   ./test.sh decode-assoc-cpp-smoke     # test with analysis/cpp/fast_em.cc
#   ./test.sh decode-assoc-cpp-converge  # run for longer with C++
#   ./test.sh decode-assoc-tensorflow

set -o nounset
set -o pipefail
set -o errexit

readonly THIS_DIR=$(dirname $0)
readonly RAPPOR_SRC=$(cd $THIS_DIR/.. && pwd)
readonly EM_CPP_EXECUTABLE=$RAPPOR_SRC/analysis/cpp/_tmp/fast_em

source $RAPPOR_SRC/util.sh


decode-dist-help() {
  time $RAPPOR_SRC/bin/decode-dist --help
}

decode-dist() {
  # ./demo.sh quick-python creates these files
  local case_dir=$RAPPOR_SRC/_tmp/python/demo3

  mkdir -p _tmp

  # Uses the ./demo.sh regtest files
  time $RAPPOR_SRC/bin/decode-dist \
    --counts $case_dir/1/case_counts.csv \
    --map $case_dir/case_map.csv \
    --params $case_dir/case_params.csv \
    --output-dir _tmp

  echo
  head _tmp/results.csv 
  echo
  cat _tmp/metrics.json
}

decode-assoc-help() {
  time $RAPPOR_SRC/bin/decode-assoc --help
}

# Clear the R cache for the map files.
clear-cached-files() {
  local dir=$1
  find $dir -name '*.rda' | xargs rm --verbose
}

write-assoc-testdata() {
  mkdir -p _tmp

  clear-cached-files _tmp

  cat >_tmp/true_values.csv <<EOF 
domain,flag..HTTPS
{'fraction_non_alphanumeric': 0.1312021312021312, 'fraction_numerical': 0.002331002331002331, 'mean_word_length': 3.0, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4684393', 'n_tokens_mistral': 1152, 'n_tokens_neox': 1118, 'n_words': 273}