<commit_before>////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2005 by <NAME>
// Permission to use, copy, modify, distribute, and sell this software for any
//     purpose is hereby granted without fee, provided that the above copyright
//     notice appear in all copies and that both that copyright notice and this
//     permission notice appear in supporting documentation.
// The author makes no representations about the suitability of this software 
//     for any purpose. It is provided "as is" without express or implied 
//     warranty.
////////////////////////////////////////////////////////////////////////////////

#include "loki/SafeFormat.h"
#include <iostream>
#include <cassert>
#include <utility>

using namespace std;

template <class Integral1, class Integral2>
Integral2 RandomInt(Integral1 low, Integral2 up)
{
    // From ``Accelerated C++'', page 135:
    // random integer in the range [0, n)
    // We adjust to generate in the range [0, n]
    const Integral2 
        low2 = low,
        n = up - low;
    
    assert(n > 0);

    const unsigned int bucket_size = RAND_MAX / n;
    assert(bucket_size > 0);
   
    Integral2 r;
    do r = Integral2(rand() / bucket_size);
    while (r > n);

    r += low2;   
    assert(r >= low2 && r <= up);
    return r;
}

string RandomString(unsigned int maxSize)
{
    string result(RandomInt(0, maxSize), '\0');
    unsigned int i = 0;
    for (; i != result.size(); ++i) {
        result[i] = RandomInt('a', 'z');
    }
    return result;
}

template <class T>
void TestCase(const string& fmt, T value) {
    char buf[4096];
    std::string s;
    const int i1 = SPrintf(s, fmt.c_str())(value); 
#ifdef _MSC_VER    
    const int i2 = _snprintf(buf, sizeof(buf), fmt.c_str(), value); 
#else
    const int i2 = snprintf(buf, sizeof(buf), fmt.c_str(), value); 
#endif
    
    if (i1 != i2 || s != buf) {
        cout << 
            "\nReference: " << i2 << 
            "; Actual: " << i1 << "\nV: [" << value << "]\nF: [" << 
            fmt << "]\n" <<
            "R: [" << buf << "]\nA: [" << s.c_str() << "]\n";
        assert(false); 
    }
}

template <class T, class U>
void TestCase2(const string& fmt, T value, U value2) {
    char buf[4096];
    std::string s;
    const int i1 = SPrintf(s, fmt.c_str())(value)(value2); 
    const int i2 = snprintf(buf, sizeof(buf), fmt.c_str(), value, value2); 
    assert(i1 == i2); 
    assert(s == buf); 
}
<commit_msg>make output code more readable<commit_after>////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2005 by <NAME>
// Permission to use, copy, modify, distribute, and sell this software for any
//     purpose is hereby granted without fee, provided that the above copyright
//     notice appear in all copies and that both that copyright notice and this
//     permission notice appear in supporting documentation.
// The author makes no representations about the suitability of this software 
//     for any purpose. It is provided "as is" without express or implied 
//     warranty.
////////////////////////////////////////////////////////////////////////////////

#include "loki/SafeFormat.h"
#include <iostream>
#include <cassert>
#include <utility>

using namespace std;

template <class Integral1, class Integral2>
Integral2 RandomInt(Integral1 low, Integral2 up)
{
    // From ``Accelerated C++'', page 135:
    // random integer in the range [0, n)
    // We adjust to generate in the range [0, n]
    const Integral2 
        low2 = low,
        n = up - low;
    
    assert(n > 0);

    const unsigned int bucket_size = RAND_MAX / n;
    assert(bucket_size > 0);
   
    Integral2 r;
    do r = Integral2(rand() / bucket_size);
    while (r > n);

    r += low2;   
    assert(r >= low2 && r <= up);
    return r;
}

string RandomString(unsigned int maxSize)
{
    string result(RandomInt(0, maxSize), '\0');
    unsigned int i = 0;
    for (; i != result.size(); ++i) {
        result[i] = RandomInt('a', 'z');
    }
    return result;
}

template <class T>
void TestCase(const string& fmt, T value) {
    char buf[4096];
    std::string s;
    const int i1 = SPrintf(s, fmt.c_str())(value); 
#ifdef _MSC_VER    
    const int i2 = _snprintf(buf, sizeof(buf), fmt.c_str(), value); 
#else
    const int i2 = snprintf(buf, sizeof(buf), fmt.c_str(), value); 
#endif
    
    if (i1 != i2 || s != buf) 
    {
        cout << endl
            << "Reference: " << i2 << "; Actual: " << i1 << ",  Difference = " << i2-i1 << endl
            << "V: [" << value << "]" << endl
            << "F: [" << fmt << "]" << endl
            << "R: [" << buf << "]" << endl
            << "A: [" << s.c_str() << "]" << endl;
        assert(false); 
    }
}

template <class T, class U>
void TestCase2(const string& fmt, T value, U value2) {
    char buf[4096];
    std::string s;
    const int i1 = SPrintf(s, fmt.c_str())(value)(value2); 
    const int i2 = snprintf(buf, sizeof(buf), fmt.c_str(), value, value2); 
    assert(i1 == i2); 
    assert(s == buf); 
}

{'fraction_non_alphanumeric': 0.20168892380204242, 'fraction_numerical': 0.0192458758837392, 'mean_word_length': 2.0643802647412755, 'pattern_counts': {'":': 0, '<': 95, '<?xml version=': 0, '>': 25, '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': '780465', 'n_tokens_mistral': 1638, 'n_tokens_neox': 1584, 'n_words': 530}