<commit_before>#!/bin/bash

TD="src/td"

test_counts=0
test_failures=0

test_eq() {
  ((test_counts++))
  test_val="$1"
  test_ans="$2"
  shift 2
  result="$("$TD" "$@" -- "$test_val")"
  if [[ "$result" == "$test_ans" ]]; then
    printf "Passed: %10s %-10s => %s\n" "$test_val" "$*" "\"$result\""
    return 0
  else
    ((test_failures++))
    printf "Failed: %10s %-10s => %s != %s\n" "$test_val" "$*" "\"$result\"" "\"$test_ans\"" >&2
    return 1
  fi
  }

test_eq 0 "0 seconds"
test_eq 1 "1 second"
test_eq -1 "1 second"
test_eq 2 "2 seconds"
test_eq 60 "1 minute"
test_eq 61 "1 minute 1 second"
test_eq 3599 "59 minutes 59 seconds"
test_eq 3600 "1 hour"
test_eq 3601 "1 hour 1 second"
test_eq 3660 "1 hour 1 minute"
test_eq 3661 "1 hour 1 minute 1 second"
test_eq 86400 "1 day"
test_eq "$((86400 + 86400 - 1))" "1 day 23 hours 59 minutes 59 seconds"
test_eq "$((2 * 86400 + 86400 - 1))" "2 days 23 hours 59 minutes 59 seconds"
test_eq "$((366 * 86400 + 1))" "366 days 1 second"
# Paddings
test_eq 1 "1 second " -P
test_eq 60 "1 minute " -P
test_eq 60 " 1 minute " -P -p
test_eq 60 "01 minute " -P -p0
test_eq 60 " 0 days  0 hours  1 minute  0 seconds" -p -a
test_eq 60 "0 days 0 hours 1 minute  0 seconds" -P -a
test_eq 60 " 0 days  0 hours  1 minute   0 seconds" -P -p -a

echo "$test_failures failures of $test_counts tests."<commit_msg>add test for multiple duration and use %q to print out strings. resolve #4<commit_after>#!/bin/bash

TD="src/td"

test_counts=0
test_failures=0

test_eq() {
  ((test_counts++))
  test_val="$1"
  test_ans="$2"
  shift 2
  result="$("$TD" "$@" -- $test_val)"
  if [[ "$result" == "$test_ans" ]]; then
    printf "Passed: %10s %-10s => %q\n" "$test_val" "$*" "$result"
    return 0
  else
    ((test_failures++))
    printf "Failed: %10s %-10s => %q != %q\n" "$test_val" "$*" "$result" "$test_ans" >&2
    return 1
  fi
  }

test_eq 0 "0 seconds"
test_eq 1 "1 second"
test_eq -1 "1 second"
test_eq 2 "2 seconds"
test_eq 60 "1 minute"
test_eq 61 "1 minute 1 second"
test_eq 3599 "59 minutes 59 seconds"
test_eq 3600 "1 hour"
test_eq 3601 "1 hour 1 second"
test_eq 3660 "1 hour 1 minute"
test_eq 3661 "1 hour 1 minute 1 second"
test_eq 86400 "1 day"
test_eq "$((86400 + 86400 - 1))" "1 day 23 hours 59 minutes 59 seconds"
test_eq "$((2 * 86400 + 86400 - 1))" "2 days 23 hours 59 minutes 59 seconds"
test_eq "$((366 * 86400 + 1))" "366 days 1 second"
# Paddings
test_eq 1 "1 second " -P
test_eq 60 "1 minute " -P
test_eq 60 " 1 minute " -P -p
test_eq 60 "01 minute " -P -p0
test_eq 60 " 0 days  0 hours  1 minute  0 seconds" -p -a
test_eq 60 "0 days 0 hours 1 minute  0 seconds" -P -a
test_eq 60 " 0 days  0 hours  1 minute   0 seconds" -P -p -a
test_eq "1 60" $'1 second \n1 minute ' -P

echo "$test_failures failures of $test_counts tests."
{'fraction_non_alphanumeric': 0.15666546891843333, 'fraction_numerical': 0.10995328781890047, 'mean_word_length': 3.3773584905660377, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '3539838', 'n_tokens_mistral': 1326, 'n_tokens_neox': 1129, 'n_words': 418}