<commit_before>// Implements http://rosettacode.org/wiki/Binary_digits
use std::vec::Vec;
use std::string::String;

#[cfg(not(test))]
fn main() {
    let bins=binaries(16u);
    for s in bins.iter() {
        println!("{}", s);
    }
}

fn binaries(n:uint) -> Vec<String> {
    range(0, n).map(|i| format!("{:t}", i)).collect()
}

#[test]
fn test_digits() {
    let bins=binaries(16u);
    assert_eq!(bins, vec![String::from_str("0")
                        ,String::from_str("1")
                        ,String::from_str("10")
                        ,String::from_str("11")
                        ,String::from_str("100")
                        ,String::from_str("101")
                        ,String::from_str("110")
                        ,String::from_str("111")
                        ,String::from_str("1000")
                        ,String::from_str("1001")
                        ,String::from_str("1010")
                        ,String::from_str("1011")
                        ,String::from_str("1100")
                        ,String::from_str("1101")
                        ,String::from_str("1110")
                        ,String::from_str("1111")]);
}
<commit_msg>binary digits: Example of using a trait + style<commit_after>// Implements http://rosettacode.org/wiki/Binary_digits
use std::iter::range_inclusive;

trait BinaryString {
    fn to_binary_string(&self) -> String;
}

impl BinaryString for uint {
    fn to_binary_string(&self) -> String {
        format!("{:t}", *self)
    }
}

#[cfg(not(test))]
fn main() {
    for s in range_inclusive(0, 16u) {
        println!("{}", s.to_binary_string());
    }
}

#[test]
fn test_digits() {
    let expected = ["0", "1", "10", "11",
                    "100", "101", "110", "111",
                    "1000", "1001", "1010", "1011",
                    "1100", "1101", "1110", "1111"];

    for (n, expected) in range_inclusive(0, 16u).zip(expected.iter()) {
        assert_eq!(n.to_binary_string().as_slice(), *expected);
    }
}

{'fraction_non_alphanumeric': 0.18218018914883027, 'fraction_numerical': 0.055251368840219015, 'mean_word_length': 1.9515418502202644, 'pattern_counts': {'":': 0, '<': 4, '<?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': '6052175', 'n_tokens_mistral': 728, 'n_tokens_neox': 637, 'n_words': 112}