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

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

Към профила на Николай Петков

Резултати

  • 17 точки от тестове
  • 0 бонус точки
  • 17 точки общо
  • 10 успешни тест(а)
  • 2 неуспешни тест(а)

Код

pub struct NucleotideCounter {
pub a: usize,
pub c: usize,
pub g: usize,
pub t: usize,
}
pub fn counts(dna: &[char]) -> NucleotideCounter {
let mut counter = NucleotideCounter{
a: 0,
c: 0,
g: 0,
t: 0,
};
for char in dna {
match char {
'A' => counter.a += 1,
'C' => counter.c += 1,
'G' => counter.g += 1,
'T' => counter.t += 1,
_ => {panic!("Грешка, грешка, обърках вратата")},
}
}
counter
}
pub fn dna_complement(dna: &[char]) -> Vec<char> {
let mut result = Vec::new();
for char in dna {
match char {
'A' => result.push('T'),
'C' => result.push('G'),
'G' => result.push('C'),
'T' => result.push('A'),
_ => {panic!("Грешка, грешка, обърках вратата")},
}
}
result
}
pub fn reverse_rna_complement(dna: &[char]) -> Vec<char> {
let mut result = Vec::new();
for char in dna {
match char {
'A' => result.push('U'),
'C' => result.push('G'),
'G' => result.push('C'),
'U' => result.push('A'),
_ => {panic!("Грешка, грешка, обърках вратата")},
}
}
result.reverse();
result
}

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

Compiling solution v0.1.0 (/tmp/d20220112-2706256-r6jman/solution)
    Finished test [unoptimized + debuginfo] target(s) in 5.67s
     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 ... FAILED
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 ... FAILED

failures:

---- solution_test::test_reverse_rna_complement_big stdout ----
thread 'main' panicked at 'Грешка, грешка, обърках вратата', src/lib.rs:51:19

---- solution_test::test_reverse_rna_complement_panic2 stdout ----
note: test did not panic as expected

failures:
    solution_test::test_reverse_rna_complement_big
    solution_test::test_reverse_rna_complement_panic2

test result: FAILED. 10 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

error: test failed, to rerun pass '--test solution_test'

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

Николай качи първо решение на 20.10.2021 18:44 (преди почти 4 години)