<commit_before>#!/usr/bin/env bash
#
# defines a shell function called isPrimeTuesday which returns 'true' (0) if this is a prime Tuesday
#
# to use this script, run it as usual:
# $ ./testPrimeTuesday.sh
# , and in order to test it, run it with env variable RUNSHALL set:
# $ RUNSHALL=1 ./testPrimeTuesday.sh
#

# the code:

# testing on Tuesday
isTuesday()
{
    test `date +%w` -eq 2
}

# testing on prime:
isPrime()
{
    # by definition, 1 is no prime
    # we use factor to find about prime numbers
    # $ prime 6
    # 6: 2 3
    # $prime 7
    # 7: 7
    # , which means that 'two words' output identifies a prime
    dayOfMonth=$(date +%d)
    factors=$(factor $dayOfMonth)
    test $dayOfMonth -ne 1 -a $(echo $factors|wc -w) -eq 2
}

isPrimeTuesday()
{
    isPrime && isTuesday
}


#
# only run tests when environment variable RUNSHALL is set
# this way, tests and the real stuff can live in the same
# file
#
if test $RUNSHALL; then
    . ./shall

    # the tests:
    test_Tuesday()
    {
        mock date 'orig_date -d 20140805 $@'
        assertOK isTuesday
    }
    
    test_Wednesday()
    {
        mock date 'orig_date -d 20140812 $@'
        assertFail isTuesday
    }
    
    test_Prime()
    {
        mock date 'orig_date -d 20140805 $@'
        assertOK isPrime
    }
    
    test_NoPrime()
    {
        mock date 'orig_date -d 20140805 $@'
        assertFail isPrime
    }
    test_PrimeTuesday()
    
    {
        mock date 'orig_date -d 20140805 $@'
        assertOK isPrimeTuesday
    }
    mock_dateNoPrimeTueday()
    {
        orig_date -d 20140812 $@
    }
    test_NoPrimeTuesday()
    
    {
        mock date mock_dateNoPrimeTueday
        assertFail isPrimeTuesday
    }
    
    testRun
    exit $?
fi

# running stuff
if isPrimeTuesday; then
    echo "Prime Tuesday"
else
    echo "Meh."
fi

# vi:st=4:ts=4:et:ai:
<commit_msg>some cosmetics on the latest test script<commit_after>#!/usr/bin/env bash
#
# defines a shell function called isPrimeTuesday which returns 'true' (0) if this is a prime Tuesday
#
# to use this script, run it as usual:
# $ ./testPrimeTuesday.sh
# , and in order to test it, run it with env variable RUNSHALL set:
# $ RUNSHALL=1 ./testPrimeTuesday.sh
#

# the code:

# testing on Tuesday
isTuesday()
{
    test `date +%w` -eq 2
}

# testing on prime:
isPrime()
{
    # by definition, 1 is no prime
    # we use factor to find about prime numbers
    # $ prime 6
    # 6: 2 3
    # $prime 7
    # 7: 7
    # , which means that 'two words' output identifies a prime
    dayOfMonth=$(date +%d)
    factors=$(factor $dayOfMonth)
    test $dayOfMonth -ne 1 -a $(echo $factors|wc -w) -eq 2
}

isPrimeTuesday()
{
    isPrime && isTuesday
}


#
# only run tests when environment variable RUNSHALL is set
# this way, tests and the real stuff can live in the same
# file
#
if test $RUNSHALL; then
    . ./shall

    # the tests:
    test_Tuesday()
    {
        mock date 'orig_date -d 20140805 $@'
        assertOK isTuesday
    }
    
    test_Wednesday()
    {
        mock date 'orig_date -d 20140812 $@'
        assertFail isTuesday
    }
    
    test_Prime()
    {
        mock date 'orig_date -d 20140805 $@'
        assertOK isPrime
    }
    
    test_NoPrime()
    {
        mock date 'orig_date -d 20140805 $@'
        assertFail isPrime
    }
    test_PrimeTuesday()
    
    {
        mock date 'orig_date -d 20140805 $@'
        assertOK isPrimeTuesday
    }
    mock_dateNoPrimeTueday()
    {
        orig_date -d 20140812 $@
    }

    test_NoPrimeTuesday()
    {
        mock date mock_dateNoPrimeTueday
        assertFail isPrimeTuesday
    }
    
    test_ZZMorePrimes()
    {
        # try some dates which are primes
        for d in 20140805 20140817 20140823; do
            mock date "orig_date -d $d \$@"
            assertOK isPrime || return 1
        done
    }

    test_ZZMoreNonPrimes()
    {
        # try some dates which are not primes
        for d in 20140801 20140802 20140821; do
            mock date "orig_date -d $d \$@"
            assertFail isPrime || return 1
        done
    }

    testRun
    exit $?
fi

# running stuff
if isPrimeTuesday; then
    echo "Prime Tuesday"
else
    echo "Meh."
fi

# vi:st=4:ts=4:et:ai:

{'fraction_non_alphanumeric': 0.0922858495030762, 'fraction_numerical': 0.0416469474680549, 'mean_word_length': 2.1172566371681416, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5589169', 'n_tokens_mistral': 1636, 'n_tokens_neox': 1393, 'n_words': 457}