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

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

Към профила на Александър Каратов

Резултати

  • 12 точки от тестове
  • 1 бонус точка
  • 13 точки общо
  • 7 успешни тест(а)
  • 5 неуспешни тест(а)

Код

pub struct NucleotideCounter {
pub a: usize,
pub c: usize,
pub g: usize,
pub t: usize,
}
pub fn counts(dna: &[char]) -> NucleotideCounter
{
let mut nuclctr = NucleotideCounter {a: 0, c: 0, g: 0, t: 0};
for elem in dna
{
match *elem
{
'A' => nuclctr.a += 1,
'C' => nuclctr.c += 1,
'G' => nuclctr.g += 1,
'T' => nuclctr.t += 1,
_ =>
{ nuclctr = NucleotideCounter {a: 0, c: 0, g: 0, t: 0};
println!("System of a down says: Why`d you leave the errors on the table?");
break;
},
}
}
return nuclctr;
}
pub fn dna_complement(dna: &[char]) -> Vec<char>
{
let mut complement: Vec<char> = "".chars().collect();
for elem in dna
{
match *elem
{
'A' => complement.push('T'),
'T' => complement.push('A'),
'C' => complement.push('G'),
'G' => complement.push('C'),
_ =>
{
println!("System of a down says: Why`d you leave the errors on the table?");
complement = "".chars().collect();
break;
}
}
}
return complement;
}
pub fn reverse_rna_complement(dna: &[char]) -> Vec<char>
{
let mut complement_rna: Vec<char> = "".chars().collect();
for elem in dna
{
match *elem
{
'A' => complement_rna.push('U'),
'T' => complement_rna.push('A'),
'C' => complement_rna.push('G'),
'G' => complement_rna.push('C'),
_ =>
{
println!("System of a down says: Why`d you leave the errors on the table?");
complement_rna = "".chars().collect();
break;
}
}
}
complement_rna.reverse();
return complement_rna;
}

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

Compiling solution v0.1.0 (/tmp/d20220112-2706256-5s63t8/solution)
    Finished test [unoptimized + debuginfo] target(s) in 5.50s
     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 ... FAILED
test solution_test::test_counts_panic2 - should panic ... FAILED
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 ... FAILED
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 ... FAILED
test solution_test::test_reverse_rna_complement_panic2 - should panic ... FAILED

failures:

---- solution_test::test_counts_panic1 stdout ----
System of a down says: Why`d you leave the errors on the table?
note: test did not panic as expected
---- solution_test::test_counts_panic2 stdout ----
System of a down says: Why`d you leave the errors on the table?
note: test did not panic as expected
---- solution_test::test_dna_complement_panic stdout ----
System of a down says: Why`d you leave the errors on the table?
note: test did not panic as expected
---- solution_test::test_reverse_rna_complement_panic1 stdout ----
System of a down says: Why`d you leave the errors on the table?
note: test did not panic as expected
---- solution_test::test_reverse_rna_complement_panic2 stdout ----
System of a down says: Why`d you leave the errors on the table?
note: test did not panic as expected

failures:
    solution_test::test_counts_panic1
    solution_test::test_counts_panic2
    solution_test::test_dna_complement_panic
    solution_test::test_reverse_rna_complement_panic1
    solution_test::test_reverse_rna_complement_panic2

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

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

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

Александър качи първо решение на 23.10.2021 23:48 (преди почти 4 години)

В условието сме написали следното:

В случай, че ви подадем буквичка, която не е една от тези, ще очакваме да panic-нете.

Проблема е, че ти не си panic-нал -- ти си напечатал грешка на стандартния изход и си върнал counter с нулеви бройки. Точките ти бяха 15, защото имахме бъг в системата за проверяване, за нещастие. Вече са смъкнати на 9, сори че чак сега се случва. Давам ти 1 бонус точка за корекция като компенсация, но за второ домашно чети условието по-внимателно :)