<commit_before>use std::cmp::{Ordering};
use std::collections::{BinaryHeap};

#[derive(Eq, PartialEq, PartialOrd, Debug)]
pub struct Length(pub String);

impl Ord for Length {
    fn cmp(&self, other: &Self) -> Ordering {
        self.0.len().cmp(&other.0.len())
    }
}

pub struct HeapDrain<'a, T> where T: 'a + Ord {
    heap: &'a mut BinaryHeap<T>,
}

pub trait HeapPopDrain<T> where T: Ord {
    fn pop_drain(&mut self) -> HeapDrain<T>;
}

impl<T> HeapPopDrain<T> for BinaryHeap<T> where T: Ord {
    fn pop_drain(&mut self) -> HeapDrain<T> {
        HeapDrain{
            heap: self,
        }
    }
}

impl<'a, T> Iterator for HeapDrain<'a, T> where T: 'a + Ord {
    type Item = T;

    fn next(&mut self) -> Option<Self::Item> {
        self.heap.pop()
    }
}

#[cfg(test)]
mod test {
    #[test]
    fn test_length() {
        use super::{Length};
        use std::cmp::{Ordering};

        let short = Length("short".to_string());
        let longer = Length("longer".to_string());
        let equal = Length("equal".to_string());

        assert_eq!(short.cmp(&longer), Ordering::Less);
        assert_eq!(longer.cmp(&short), Ordering::Greater);
        assert_eq!(short.cmp(&equal), Ordering::Equal);
    }

    #[test]
    fn test_heapdrain() {
        use super::{HeapPopDrain};
        use std::collections::{BinaryHeap};

        let mut heap = BinaryHeap::new();
        heap.push(3);
        heap.push(9);
        heap.push(6);

        let mut drain = heap.pop_drain();
        assert_eq!(drain.next(), Some(9));
        assert_eq!(drain.next(), Some(6));
        assert_eq!(drain.next(), Some(3));
        assert_eq!(drain.next(), None);
    }
}<commit_msg>Add more tests.<commit_after>use std::cmp::{Ordering};
use std::collections::{BinaryHeap};

#[derive(Eq, PartialEq, PartialOrd, Debug)]
pub struct Length(pub String);

impl Ord for Length {
    fn cmp(&self, other: &Self) -> Ordering {
        self.0.len().cmp(&other.0.len())
    }
}

pub struct HeapDrain<'a, T> where T: 'a + Ord {
    heap: &'a mut BinaryHeap<T>,
}

pub trait HeapPopDrain<T> where T: Ord {
    fn pop_drain(&mut self) -> HeapDrain<T>;
}

impl<T> HeapPopDrain<T> for BinaryHeap<T> where T: Ord {
    fn pop_drain(&mut self) -> HeapDrain<T> {
        HeapDrain{
            heap: self,
        }
    }
}

impl<'a, T> Iterator for HeapDrain<'a, T> where T: 'a + Ord {
    type Item = T;

    fn next(&mut self) -> Option<Self::Item> {
        self.heap.pop()
    }
}

#[cfg(test)]
mod test {
    #[test]
    fn test_length() {
        use super::{Length};
        use std::cmp::{Ordering};

        let short = Length("short".to_string());
        let longer = Length("longer".to_string());
        let equal = Length("equal".to_string());

        assert_eq!(short.cmp(&longer), Ordering::Less);
        assert_eq!(longer.cmp(&short), Ordering::Greater);
        assert_eq!(short.cmp(&equal), Ordering::Equal);
    }

    #[test]
    fn test_heapdrain() {
        use super::{Length, HeapPopDrain};
        use std::collections::{BinaryHeap};

        {
            let mut heap = BinaryHeap::new();
            heap.push(3);
            heap.push(9);
            heap.push(6);

            let mut drain = heap.pop_drain();
            assert_eq!(drain.next(), Some(9));
            assert_eq!(drain.next(), Some(6));
            assert_eq!(drain.next(), Some(3));
            assert_eq!(drain.next(), None);
        }

        {
            let mut heap = BinaryHeap::new();
            heap.push(Length("short".to_string()));
            heap.push(Length("notequal".to_string()));
            heap.push(Length("longer".to_string()));

            let mut drain = heap.pop_drain();
            assert_eq!(drain.next(), Some(Length("notequal".to_string())));
            assert_eq!(drain.next(), Some(Length("longer".to_string())));
            assert_eq!(drain.next(), Some(Length("short".to_string())));
            assert_eq!(drain.next(), None);
        }
    }
}
{'fraction_non_alphanumeric': 0.1777161583060247, 'fraction_numerical': 0.00403327451474666, 'mean_word_length': 2.5053003533568905, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 33, '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': '4062248', 'n_tokens_mistral': 1354, 'n_tokens_neox': 1371, 'n_words': 276}