<commit_before><?php
class TestFailure extends Exception {}

class TestCase implements Minim_Plugin // {{{
{
    const PASS = 0;
    const FAIL = 1;
    const ERROR = 2;

    function set_up() // {{{
    {
    } // }}}

    function tear_down() // {{{
    {
    } // }}}

    function is_test($method_name) // {{{
    {
        return strpos(strtolower($method_name), 'test_') === 0;
    } // }}}

    function fail($reason = NULL) // {{{
    {
        throw new TestFailure($reason);
    } // }}}

    function assertEqual($a, $b) // {{{
    {
        if ($a == $b)
        {
            return TRUE;
        }
        $this->fail("Assertion failure: $a != $b");
    } // }}}

    function run() // {{{
    {
        // find methods starting with 'test_'
        $methods = get_class_methods(get_class($this));
        $methods = array_filter($methods, array(&$this, 'is_test'));

        // execute each one
        $results = array_combine($methods, array_fill(0, count($methods), array(
            'result' => TestCase::PASS,
            'reason' => ''
        )));
        foreach ($methods as $test)
        {
            try
            {
                $this->set_up();
                $result = $this->$test();
                $this->tear_down();
                if (is_array($result))
                {
                    $results[$test] = $result;
                }
            }
            catch (TestFailure $f)
            {
                $results[$test] = array(
                    'result' => TestCase::FAIL,
                    'reason' => $f->getMessage()<commit_msg>Fleshed out testing framework a bit<commit_after><?php
class TestFailure extends Exception {}

function dump_results($results)
{
    $msgs = array();
    foreach ($results as $result)
    {
        switch ($result['result'])
        {
            case TestCase::PASS:
                print '.';
                break;
            case TestCase::FAIL:
                print 'F';
                $msgs[] = $result['reason'];
                break;
            case TestCase::ERROR:
                print 'E';
                $msgs[] = $result['reason'];
                break;
        }
    }
    print "\n";
    foreach ($msgs as $msg)
    {
        print str_repeat('-', 80)."\n".$msg."\n";
    }
    if (!$msgs)
    {
        print str_repeat('-', 80)."\nAll tests passed\n";
    }
}

class TestCase // {{{
{
    const PASS = 0;
    const FAIL = 1;
    const ERROR = 2;

    function set_up() // {{{
    {
    } // }}}

    function tear_down() // {{{
    {
    } // }}}

    function is_test($method_name) // {{{
    {
        return strpos(strtolower($method_name), 'test_') === 0;
    } // }}}

    function fail($reason = NULL) // {{{
    {
        throw new TestFailure($reason);
    } // }}}

    function assertEqual($a, $b, $msg=NULL) // {{{
    {
        if ($a == $b)
        {
            return TRUE;
        }
        $this->fail($msg ? $msg : "Assertion failure: $a != $b");
    } // }}}

    function assertTrue($a, $msg=NULL) // {{{
    {
        $this->assertEqual($a, TRUE, $msg);
    } // }}}

    function run() // {{{
    {
        // find methods starting with 'test_'
        $methods = get_class_methods(get_class($this));
        $methods = array_filter($methods, array(&$this, 'is_test'));

        // execute each one
        $results = array_combine($methods, array_fill(0, count($methods), array(
            'result' => TestCase::PASS,
            'reason' => ''
        )));
        foreach ($methods as $test)
        {
            try
            {
                $this->set_up();
                $result = $this->$test();
                $this->tear_down();
                if (is_array($result))
                {
                    $results[$test] = $result;
                }
            }
            catch (TestFailure $f)
            {
                $results[$test] = array(
                    'result' => TestCase::FAIL,
                    'reason' => $f->getMessage()
{'fraction_non_alphanumeric': 0.1694111776447106, 'fraction_numerical': 0.003493013972055888, 'mean_word_length': 1.3834720570749108, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 22, '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': '6308837', 'n_tokens_mistral': 1226, 'n_tokens_neox': 1179, 'n_words': 239}