Move History

Fork Selected
  • Code
    fn price(servings: u32, price: u32) -> u32 {
        let mut cost = servings * price;
        if servings > 0 {
            cost += 1
        }
        cost
    }
    
    Test Cases
    #[test]
    fn test_case() {
        assert_eq!(price(2, 3), 7);
        assert_eq!(price(4, 5), 21);
        assert_eq!(price(0, 10), 0);
    }
  • 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 cost
    • else:
    • return 0
    • }
    • cost
    • }
    Test Cases
    • import codewars_test as test
    • from 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);
    • }