#[cfg(test)] mod testing { use anyhow::Result; use assert_cmd::prelude::*; use std::{fmt::Display, process::Command}; type Expected3 = Vec<(T, u32, u32)>; type Expected6 = Vec<(S, T, T, S, F, C)>; type Expected12 = Vec<(S, T, T, S, F, C, T, T, T, T, T, T)>; fn build_expected_str(expected: &Expected3) -> String { expected .iter() .map(|(chr, start, end)| format!("{}\t{}\t{}\n", chr, start, end)) .collect::>() .join("") } fn build_expected_str_bed6( expected: &Expected6, ) -> String { expected .iter() .map(|(chr, start, end, name, score, strand)| { format!( "{}\t{}\t{}\t{}\t{:.3}\t{}\n", chr, start, end, name, score, strand ) }) .collect::>() .join("") } fn build_expected_str_bed12( expected: &Expected12, ) -> String { expected .iter() .map( |( chr, start, end, name, score, strand, thick_start, thick_end, rgb, block_count, block_sizes, block_starts, )| { format!( "{}\t{}\t{}\t{}\t{:.3}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\n", chr, start, end, name, score, strand, thick_start, thick_end, rgb, block_count, block_sizes, block_starts ) }, ) .collect::>() .join("") } #[test] fn test_segment_bed3() -> Result<()> { let input = "tests/datasets/segment/test.bed3"; let mut cmd = Command::cargo_bin("gia")?; let output = cmd.arg("segment").arg("-i").arg(input).output()?; let expected = vec![ (1, 83, 142), (1, 142, 233), (1, 233, 292), (1, 349, 437), (1, 437, 499), (1, 499, 587), (1, 704, 854), ]; let expected_str = build_expected_str(&expected); assert_eq!(output.stdout, expected_str.as_bytes()); Ok(()) } #[test] fn test_segment_bed6() -> Result<()> { let input = "tests/datasets/segment/test.bed6"; let mut cmd = Command::cargo_bin("gia")?; let output = cmd.arg("segment").arg("-i").arg(input).output()?; let expected = vec![ (1, 83, 142, 0, ".", "-"), (1, 142, 233, 0, ".", "-"), (1, 233, 292, 0, ".", "-"), (1, 349, 437, 0, ".", "+"), (1, 437, 499, 0, ".", "+"), (1, 499, 587, 0, ".", "+"), (1, 704, 854, 0, ".", "+"), ]; let expected_str = build_expected_str_bed6(&expected); assert_eq!(output.stdout, expected_str.as_bytes()); Ok(()) } #[test] fn test_segment_bed12() -> Result<()> { let input = "tests/datasets/segment/test.bed12"; let mut cmd = Command::cargo_bin("gia")?; let output = cmd.arg("segment").arg("-i").arg(input).output()?; let expected = vec![ (1, 83, 142, 0, ".", "-", 0, 0, 0, 0, 0, 0), (1, 142, 233, 0, ".", "-", 0, 0, 0, 0, 0, 0), (1, 233, 292, 0, ".", "-", 0, 0, 0, 0, 0, 0), (1, 349, 437, 0, ".", "+", 0, 0, 0, 0, 0, 0), (1, 437, 499, 0, ".", "+", 0, 0, 0, 0, 0, 0), (1, 499, 587, 0, ".", "+", 0, 0, 0, 0, 0, 0), (1, 704, 854, 0, ".", "+", 0, 0, 0, 0, 0, 0), ]; let expected_str = build_expected_str_bed12(&expected); assert_eq!(output.stdout, expected_str.as_bytes()); Ok(()) } }