-
Code fn price(servings: u32, price: u32) -> u32 { let mut cost = servings * price; if servings > 0 { cost += 1 } cost }
Test Cases fn test_case() { assert_eq!(price(2, 3), 7); assert_eq!(price(4, 5), 21); assert_eq!(price(0, 10), 0); }
Output:
-
Code def price(servings, price):if servings >0:cost = servings * price- fn price(servings: u32, price: u32) -> u32 {
- let mut cost = servings * price;
- if servings > 0 {
- cost += 1
return costelse:return 0- }
- cost
- }
Test Cases import codewars_test as testfrom solution import price@test.describe("Kaju bakery")def _():@test.it("Basic tests")def test_case():test.assert_equals(price(2, 3), 7)test.assert_equals(price(4, 5), 21)test.assert_equals(price(0, 10), 0)test.assert_equals(price(-1, 5), 0)- #[test]
- fn test_case() {
- assert_eq!(price(2, 3), 7);
- assert_eq!(price(4, 5), 21);
- assert_eq!(price(0, 10), 0);
- }
- All
- {{group.name}} ({{group.count}})
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}