Решение на упр.01 задача 1 от Илиян Копривчин
Към профила на Илиян Копривчин
Резултати
- 1 точка от тестове
- 0 бонус точки
- 1 точка общо
- 1 успешни тест(а)
- 0 неуспешни тест(а)
Код
fn calc(a: i32, b: i32, op: char) -> i32 {
if op == '+' {
return a + b
} else if op == '-' {
return a - b
} else if op == '*' {
return a * b
} else if op == '/' {
if (b == 0) {
return 0
}
return a / b
} else {
42
}
}
Лог от изпълнението
Updating crates.io index
Locking 17 packages to latest compatible versions
Compiling proc-macro2 v1.0.101
Compiling unicode-ident v1.0.19
Compiling quote v1.0.41
Compiling futures-sink v0.3.31
Compiling futures-core v0.3.31
Compiling futures-channel v0.3.31
Compiling slab v0.4.11
Compiling syn v2.0.106
Compiling futures-io v0.3.31
Compiling pin-project-lite v0.2.16
Compiling pin-utils v0.1.0
Compiling futures-task v0.3.31
Compiling memchr v2.7.6
Compiling solution v0.1.0 (/tmp/d20251016-574132-1jv0lfg/solution)
warning: unnecessary parentheses around `if` condition
--> src/lib.rs:9:12
|
9 | if (b == 0) {
| ^ ^
|
= note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
|
9 - if (b == 0) {
9 + if b == 0 {
|
warning: function `calc` is never used
--> src/lib.rs:1:4
|
1 | fn calc(a: i32, b: i32, op: char) -> i32 {
| ^^^^
|
= note: `#[warn(dead_code)]` on by default
warning: `solution` (lib) generated 2 warnings (run `cargo fix --lib -p solution` to apply 1 suggestion)
Compiling futures-macro v0.3.31
Compiling futures-util v0.3.31
Compiling futures-executor v0.3.31
Compiling futures v0.3.31
warning: unnecessary parentheses around `if` condition
--> tests/../src/lib.rs:9:12
|
9 | if (b == 0) {
| ^ ^
|
= note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
|
9 - if (b == 0) {
9 + if b == 0 {
|
warning: `solution` (test "solution_test") generated 1 warning (run `cargo fix --test "solution_test"` to apply 1 suggestion)
Finished `test` profile [unoptimized + debuginfo] target(s) in 8.16s
Running tests/solution_test.rs (target/debug/deps/solution_test-80bf62783e3de781)
running 1 test
test solution_test::test_basic ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
История (3 версии и 0 коментара)
Илиян качи решение на 09.10.2025 18:51 (преди 21 дена)
fn calc(a: i32, b: i32, op: char) -> i32 {
if op == '+' {
return a + b
} else if op == '-' {
return a - b
} else if op == '*' {
return a * b
} else if op == '/' {
+ if (b == 0) {
+ return 0
+ }
return a / b
} else {
- 0
+ 42
}
}
Илиян качи решение на 09.10.2025 18:51 (преди 21 дена)
fn calc(a: i32, b: i32, op: char) -> i32 {
if op == '+' {
return a + b
} else if op == '-' {
return a - b
} else if op == '*' {
return a * b
} else if op == '/' {
if (b == 0) {
return 0
}
+
return a / b
} else {
42
}
}
