Решение на Сметки с ДНК от Светломир Станков

Обратно към всички решения

Към профила на Светломир Станков

Резултати

  • 20 точки от тестове
  • 0 бонус точки
  • 20 точки общо
  • 12 успешни тест(а)
  • 0 неуспешни тест(а)

Код

pub struct NucleotideCounter {
pub a: usize,
pub c: usize,
pub g: usize,
pub t: usize,
}
pub fn counts(dna: &[char]) -> NucleotideCounter {
let mut nucl_counter = NucleotideCounter {
a: 0, c: 0, g: 0, t: 0
};
for c in dna {
match c {
'A' => nucl_counter.a += 1,
'C' => nucl_counter.c += 1,
'G' => nucl_counter.g += 1,
'T' => nucl_counter.t += 1,
_ => panic!("Error! There is an unvalid letter."),
}
}
nucl_counter
}
pub fn dna_complement(dna: &[char]) -> Vec<char> {
let mut vec = Vec::new();
for c in dna {
match c {
'A' => vec.push('T'),
'C' => vec.push('G' ),
'G' => vec.push('C'),
'T' => vec.push('A'),
_ => panic!("Error! There is an unvalid letter."),
}
}
vec
}
pub fn reverse_rna_complement(dna: &[char]) -> Vec<char> {
let mut rna = Vec::new();
for c in dna {
match c {
'A' => rna.push('U'),
'C' => rna.push('G' ),
'G' => rna.push('C'),
'T' => rna.push('A'),
_ => panic!("Error! There is an unvalid letter."),
}
}
rna.reverse();
rna
}

Лог от изпълнението

Compiling solution v0.1.0 (/tmp/d20220112-2706256-816f5m/solution)
    Finished test [unoptimized + debuginfo] target(s) in 5.52s
     Running tests/solution_test.rs (target/debug/deps/solution_test-4c880d3f0adaac34)

running 12 tests
test solution_test::test_counts_basic ... ok
test solution_test::test_counts_big ... ok
test solution_test::test_counts_panic1 - should panic ... ok
test solution_test::test_counts_panic2 - should panic ... ok
test solution_test::test_counts_zero ... ok
test solution_test::test_dna_complement_big ... ok
test solution_test::test_dna_complement_empty ... ok
test solution_test::test_dna_complement_panic - should panic ... ok
test solution_test::test_reverse_rna_complement_big ... ok
test solution_test::test_reverse_rna_complement_empty ... ok
test solution_test::test_reverse_rna_complement_panic1 - should panic ... ok
test solution_test::test_reverse_rna_complement_panic2 - should panic ... ok

test result: ok. 12 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.01s

История (1 версия и 1 коментар)