Решение на Code Identifier от Александър Каракушев

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

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

Резултати

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

Код

/// Необходимо е CodeIdentifier да имплементира Debug, за да можем да го
/// използваме в тестови assertion-и.
///
#[derive(Debug)]
pub struct CodeIdentifier {
// Каквито полета ви трябват
data: Option<String>
}
impl CodeIdentifier {
/// Функцията ще върне Option<CodeIdentifier>, което ще бъде:
/// - None: ако входа не е валиден идентификатор. Вижте горе за това
/// какво значи "валиден идентификатор".
/// - Some(code_identifier): Ако входа е валиден.
///
pub fn new(identifier: &str) -> Option<Self>
{
let chek_one = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
let chek_two = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";

В условието описахме, че проверката е дали символа е is_alphabetic(), и това включва доста повече от латинската азбука. А и щеше да е по-лесно да го имплементираш с викане на този метод, вместо да изброиш азбуката и да викаш contains :).

let cv: Vec<char> = identifier.chars().collect();
let mut k = 0;
if cv.is_empty()
{
return None;
}
if chek_one.contains(cv[k])
{
k = k + 1;
while k < cv.capacity()
{
if !chek_two.contains(cv[k])
{
return None;
}
k = k + 1;
}
}
return Some(CodeIdentifier
{
data: Some(identifier.to_string()),
})
//unimplemented!()
}
/// Конвертира идентификатора до camelcased вариант.
/// - Примерен вход: "some_var"
/// - Примерен изход: "someVar"
///
pub fn camelcase(&self) -> String {
unimplemented!()
}
/// Конвертира идентификатора до titlecased вариант (camelcased с първа заглавна буква).
/// - Примерен вход: "some_var"
/// - Примерен изход: "SomeVar"
///
pub fn titlecase(&self) -> String {
unimplemented!()
}
/// Конвертира идентификатора до kebabcased вариант.
/// - Примерен вход: "some_var"
/// - Примерен изход: "some-var"
///
pub fn kebabcase(&self) -> String {
unimplemented!()
}
/// Конвертира идентификатора до underscored вариант.
/// - Примерен вход: "some_var"
/// - Примерен изход: "some_var"
///
/// - Примерен вход: "Some_Var"
/// - Примерен изход: "some_var"
///
pub fn underscore(&self) -> String {
unimplemented!()
}
/// Конвертира идентификатора до screaming-snakecased вариант.
/// - Примерен вход: "some_var"
/// - Примерен изход: "SOME_VAR"
///
pub fn screaming_snakecase(&self) -> String
{
/*let caps = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
let caps_v: Vec<char> = caps.chars().collect();
let ncaps = "abcdefghijklmnopqrstuvwxyz";
let ncaps_v: Vec<char> = ncaps.chars().collect();
let d = match &self.data
{
Some(val) => val,
None => "",
};
let c: Vec<char> = d.chars().collect();
let mut k = 0;
while k < 26
{
let mut i = 0;
while i < c.capacity()
{
//if
i = i + 1;
}
}*/
unimplemented!()
}
/*pub fn convertion_of_sym(to_conv: &str) -> String
{
let caps = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
let caps_v: Vec<char> = caps.chars().collect();
let ncaps = "abcdefghijklmnopqrstuvwxyz";
let ncaps_v: Vec<char> = ncaps.chars().collect();
let c: Vec<char> = to_conv.chars().collect();
let mut k = 0;
while k < 26
{
}
unimplemented!()
}*/
}
fn main()
{
}

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

Compiling solution v0.1.0 (/tmp/d20190123-22631-clxyk8/solution)
warning: function is never used: `main`
   --> src/lib.rs:124:1
    |
124 | fn main()
    | ^^^^^^^^^
    |
    = note: #[warn(dead_code)] on by default

    Finished dev [unoptimized + debuginfo] target(s) in 4.67s
     Running target/debug/deps/solution-2e785d603b538f71

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-29808948fb50ed3a

running 15 tests
test solution_test::test_both_static_and_dynamic_strings ... FAILED
test solution_test::test_camelcase_basic ... FAILED
test solution_test::test_cyrillic1 ... FAILED
test solution_test::test_digits1 ... FAILED
test solution_test::test_digits2 ... FAILED
test solution_test::test_digits3 ... FAILED
test solution_test::test_kebabcase_basic ... FAILED
test solution_test::test_multibyte_uppercase ... FAILED
test solution_test::test_normalize_case1 ... FAILED
test solution_test::test_normalize_case2 ... FAILED
test solution_test::test_screaming_snakecase_basic ... FAILED
test solution_test::test_titlecase_basic ... FAILED
test solution_test::test_underscore_basic ... FAILED
test solution_test::test_validity ... FAILED
test solution_test::test_whitespace ... FAILED

failures:

---- solution_test::test_both_static_and_dynamic_strings stdout ----
thread 'solution_test::test_both_static_and_dynamic_strings' panicked at 'index out of bounds: the len is 8 but the index is 8', libcore/slice/mod.rs:2448:10
note: Run with `RUST_BACKTRACE=1` for a backtrace.

---- solution_test::test_camelcase_basic stdout ----
thread 'solution_test::test_camelcase_basic' panicked at 'index out of bounds: the len is 8 but the index is 8', libcore/slice/mod.rs:2448:10

---- solution_test::test_cyrillic1 stdout ----
thread 'solution_test::test_cyrillic1' panicked at 'not yet implemented', src/lib.rs:77:9

---- solution_test::test_digits1 stdout ----
thread 'solution_test::test_digits1' panicked at 'index out of bounds: the len is 12 but the index is 12', libcore/slice/mod.rs:2448:10

---- solution_test::test_digits2 stdout ----
thread 'solution_test::test_digits2' panicked at 'index out of bounds: the len is 12 but the index is 12', libcore/slice/mod.rs:2448:10

---- solution_test::test_digits3 stdout ----
thread 'solution_test::test_digits3' panicked at 'called `Option::unwrap()` on a `None` value', libcore/option.rs:355:21

---- solution_test::test_kebabcase_basic stdout ----
thread 'solution_test::test_kebabcase_basic' panicked at 'index out of bounds: the len is 8 but the index is 8', libcore/slice/mod.rs:2448:10

---- solution_test::test_multibyte_uppercase stdout ----
thread 'solution_test::test_multibyte_uppercase' panicked at 'called `Option::unwrap()` on a `None` value', libcore/option.rs:355:21

---- solution_test::test_normalize_case1 stdout ----
thread 'solution_test::test_normalize_case1' panicked at 'index out of bounds: the len is 8 but the index is 8', libcore/slice/mod.rs:2448:10

---- solution_test::test_normalize_case2 stdout ----
thread 'solution_test::test_normalize_case2' panicked at 'index out of bounds: the len is 8 but the index is 8', libcore/slice/mod.rs:2448:10

---- solution_test::test_screaming_snakecase_basic stdout ----
thread 'solution_test::test_screaming_snakecase_basic' panicked at 'index out of bounds: the len is 8 but the index is 8', libcore/slice/mod.rs:2448:10

---- solution_test::test_titlecase_basic stdout ----
thread 'solution_test::test_titlecase_basic' panicked at 'index out of bounds: the len is 8 but the index is 8', libcore/slice/mod.rs:2448:10

---- solution_test::test_underscore_basic stdout ----
thread 'solution_test::test_underscore_basic' panicked at 'index out of bounds: the len is 8 but the index is 8', libcore/slice/mod.rs:2448:10

---- solution_test::test_validity stdout ----
thread 'solution_test::test_validity' panicked at 'assertion failed: CodeIdentifier::new("+_+").is_none()', tests/solution_test.rs:11:5

---- solution_test::test_whitespace stdout ----
thread 'solution_test::test_whitespace' panicked at 'not yet implemented', src/lib.rs:77:9


failures:
    solution_test::test_both_static_and_dynamic_strings
    solution_test::test_camelcase_basic
    solution_test::test_cyrillic1
    solution_test::test_digits1
    solution_test::test_digits2
    solution_test::test_digits3
    solution_test::test_kebabcase_basic
    solution_test::test_multibyte_uppercase
    solution_test::test_normalize_case1
    solution_test::test_normalize_case2
    solution_test::test_screaming_snakecase_basic
    solution_test::test_titlecase_basic
    solution_test::test_underscore_basic
    solution_test::test_validity
    solution_test::test_whitespace

test result: FAILED. 0 passed; 15 failed; 0 ignored; 0 measured; 0 filtered out

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

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

Александър качи първо решение на 25.10.2018 16:47 (преди над 4 години)