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

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

Към профила на Петър Ангелов

Резултати

  • 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 base in dna {
match base {
'A' => counter.a += 1,
'C' => counter.c += 1,
'G' => counter.g += 1,
'T' => counter.t += 1,
_ => panic!("Грешка, грешка, обърках вратата"),
}
}
counter
}
fn na_complement(dna: &[char], timin_uracil: char) -> Vec<char> {
let mut complement: Vec<char> = Vec::with_capacity(dna.len());
for base in dna {
complement.push(match base {
'A' => timin_uracil,
'C' => 'G',
'G' => 'C',
maybe if maybe == &timin_uracil => 'A',
_ => panic!("Грешка, грешка, обърках вратата"),
});
}
complement
}
pub fn dna_complement(dna: &[char]) -> Vec<char> {
na_complement(dna, 'T')
}
pub fn reverse_rna_complement(dna: &[char]) -> Vec<char> {
let mut compl = na_complement(dna, 'U');
compl.reverse();
compl
}

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

Compiling solution v0.1.0 (/tmp/d20220112-2706256-8yyuhu/solution)
    Finished test [unoptimized + debuginfo] target(s) in 5.75s
     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:35:18

---- 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 коментар)

Петър качи първо решение на 24.10.2021 22:29 (преди почти 4 години)

Добро решение. Не съм сигурен за името maybe, не е от най-комуникативните 😅. Може би "base"? С shadowing мисля че ще е ок. Може да обмислиш и примерно:

'A' => timin_uracil,
'C' => 'G',
'G' => 'C',
_ => {
    if base == &timin_uracil {
        'A'
    } else {
        panic!("Грешка, грешка, обърках вратата")
    }
}