// use pyo3::{Python, prepare_freethreaded_python};

#[cfg(test)]
mod tests {
    // use super::*;
    use ganz::DnaSequence;

    #[test]
    fn test_basic_encoding() {
        let seq = "ACGT";
        let dna = DnaSequence::new(seq);
        let decoded = dna.decode();
        assert_eq!(decoded, seq);
        assert_eq!(decoded.len(), 4);
    }

    #[test]
    fn test_longer_sequence() {
        let seq = "ACGTACGT";
        let dna = DnaSequence::new(seq);
        
        // Should be exactly one u32 with all bits used
        assert_eq!(dna.data[0], 0b1000_0100_0010_0001_1000_0100_0010_0001);
        assert_eq!(dna.length, 8);
    }

    #[test]
    fn test_partial_chunk() {
        let seq = "ACGTA";  // 5 nucleotides
        let dna = DnaSequence::new(seq);
        
        // First 5 nucleotides encoded, rest should be 0
        assert_eq!(dna.data[0], 0b1000_0100_0010_0001_1000_0000_0000_0000);
        assert_eq!(dna.length, 5);
    }

    #[test]
    fn test_lowercase() {
        let seq = "acgt";
        let dna = DnaSequence::new(seq);
        
        assert_eq!(dna.data[0], 0b1000_0100_0010_0001_0000_0000_0000_0000);
    }

    #[test]
    fn test_invalid_nucleotides() {
        let seq = "ACGN";  // N is invalid
        let dna = DnaSequence::new(seq);
        
        // N should be encoded as 0000
        assert_eq!(dna.data[0], 0b1000_0100_0010_0000_0000_0000_0000_0000);
    }

    #[test]
    fn test_roundtrip() {
        let original = "ACGTACGT";
        let dna = DnaSequence::new(original);
        let decoded = dna.decode();
        
        assert_eq!(original, decoded);
    }

    // #[test]
    // #[ignore = "Requires Python environment with NumPy installed"]
    // fn test_unpack_bits() {
    //     prepare_freethreaded_python();
    //     Python::with_gil(|py| {
    //         let dna = DnaSequence::new("ACGT");
    //         let bits = dna.unpack_bits(py).unwrap();
            
    //         // Expected one-hot encodings:
    //         // A: 1000
    //         // C: 0100
    //         // G: 0010
    //         // T: 0001
    //         let expected = vec![
    //             1, 0, 0, 0,  // A
    //             0, 1, 0, 0,  // C
    //             0, 0, 1, 0,  // G
    //             0, 0, 0, 1,  // T
    //         ];
            
    //         // Convert PyArray2 to Vec for comparison
    //         let array_slice = unsafe { bits.as_slice().unwrap() };
    //         assert_eq!(array_slice, expected.as_slice());
    //     });
    // }

    // #[test]
    // #[ignore = "Requires Python environment with NumPy installed"]
    // fn test_unpack_bits_longer() {
    //     prepare_freethreaded_python();
    //     Python::with_gil(|py| {
    //         let dna = DnaSequence::new("ACGTACGT");
    //         let bits = dna.unpack_bits(py).unwrap();
            
    //         let expected = vec![
    //             1, 0, 0, 0,  // A
    //             0, 1, 0, 0,  // C
    //             0, 0, 1, 0,  // G
    //             0, 0, 0, 1,  // T
    //             1, 0, 0, 0,  // A
    //             0, 1, 0, 0,  // C
    //             0, 0, 1, 0,  // G
    //             0, 0, 0, 1,  // T
    //         ];
            
    //         let array_slice = unsafe { bits.as_slice().unwrap() };
    //         assert_eq!(array_slice, expected.as_slice());
    //     });
    // }

    #[test]
    fn test_iterator() {
        let dna = DnaSequence::new("ACGT");
        let nucleotides: Vec<char> = dna.iter().collect();
        assert_eq!(nucleotides, vec!['A', 'C', 'G', 'T']);
    }

    #[test]
    fn test_iterator_with_invalid() {
        let dna = DnaSequence::new("ACGTN");
        let nucleotides: Vec<char> = dna.iter().collect();
        assert_eq!(nucleotides, vec!['A', 'C', 'G', 'T', 'N']);
    }

    #[test]
    fn test_iterator_empty() {
        let dna = DnaSequence::new("");
        let nucleotides: Vec<char> = dna.iter().collect();
        assert!(nucleotides.is_empty());
    }

    #[test]
    fn test_for_loop() {
        let dna = DnaSequence::new("ACGT");
        let mut nucleotides = Vec::new();
        for nucleotide in &dna {
            nucleotides.push(nucleotide);
        }
        assert_eq!(nucleotides, vec!['A', 'C', 'G', 'T']);
    }

    #[test]
    fn test_long_sequence() {
        let seq = "ACGTACGTACGT";  // 12 nucleotides
        let dna = DnaSequence::new(seq);
        
        // Should be two u32s
        assert_eq!(dna.data.len(), 2);
        assert_eq!(dna.data[0], 0b1000_0100_0010_0001_1000_0100_0010_0001);
        assert_eq!(dna.data[1], 0b1000_0100_0010_0001_0000_0000_0000_0000);
        assert_eq!(dna.length, 12);
        
        let decoded = dna.decode();
        assert_eq!(decoded, seq);
    }

    #[test]
    fn test_odd_length_sequence() {
        let seq = "ACGTACGTACG";  // 11 nucleotides
        let dna = DnaSequence::new(seq);
        
        // Should be two u32s
        assert_eq!(dna.data.len(), 2);
        assert_eq!(dna.data[0], 0b1000_0100_0010_0001_1000_0100_0010_0001);
        assert_eq!(dna.data[1], 0b1000_0100_0010_0000_0000_0000_0000_0000);
        assert_eq!(dna.length, 11);
        
        let decoded = dna.decode();
        assert_eq!(decoded, seq);
    }
} 