Skip to content

Commit

Permalink
docs: fix bad code in lasagna-master instructions (#839)
Browse files Browse the repository at this point in the history
* docs: fix bad code in lasagna-master instructions

* fix: align test and text

* fix: correct examples to fit docs
  • Loading branch information
vaeng authored Mar 8, 2024
1 parent fe16ecc commit 304d35f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions exercises/concept/lasagna-master/.docs/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ The result should be returned as an `amount` _struct_, which is already defined
```cpp
struct amount { int noodles; double sauce; };
needed = quantities({"sauce", "noodles", "sauce", "meat", "mozzarella", "noodles"});
amount needed{quantities({"sauce", "noodles", "sauce", "meat", "mozzarella", "noodles"})};
// needed.noodles => 100
// needed.sauce => 0.4
```
Expand Down Expand Up @@ -81,7 +81,7 @@ This means the `quantities` argument should not be modified in this function.
```cpp
std::vector<double> quantities{1.2, 3.6, 10.5};
scaledQuantities := scaleRecipe(quantities, 4);
scaleRecipe(quantities, 4);
// => { 2.4, 7.2, 21 }
```

Expand Down
2 changes: 1 addition & 1 deletion exercises/concept/lasagna-master/.meta/exemplar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void addSecretIngredient(std::vector<std::string>& myList,
myList.back() = secretIngredient;
}

std::vector<double> scaledQuantities(const std::vector<double>& quantities,
std::vector<double> scaleRecipe(const std::vector<double>& quantities,
int portions) {
std::vector<double> result(quantities);
for (auto& quantity : result) {
Expand Down
2 changes: 1 addition & 1 deletion exercises/concept/lasagna-master/.meta/exemplar.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ int preparationTime(const std::vector<std::string>& layers, int prepTime = 2);
amount quantities(const std::vector<std::string>& layers);
void addSecretIngredient(std::vector<std::string>& myList, const std::vector<std::string>& friendsList);
void addSecretIngredient(std::vector<std::string>& myList, const std::string& secretIngredient);
std::vector<double> scaledQuantities(const std::vector<double>& quantities, int portions);
std::vector<double> scaleRecipe(const std::vector<double>& quantities, int portions);

} // namespace lasagna_master
16 changes: 8 additions & 8 deletions exercises/concept/lasagna-master/lasagna_master_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,35 +122,35 @@ TEST_CASE("Adds secret vector ingredient", "[task_3]") {
REQUIRE(myList == expected);
}

TEST_CASE("scaledQuantities: scales up correctly", "[task_4]") {
TEST_CASE("scaleRecipe: scales up correctly", "[task_4]") {
const std::vector<double> input{0.5, 250, 150, 3, 0.5};
int portions{6};
std::vector<double> expected{1.5, 750, 450, 9, 1.5};
std::vector<double> scaled{scaledQuantities(input, portions)};
std::vector<double> scaled{scaleRecipe(input, portions)};
REQUIRE_VECTOR_APROX_EQUAL(expected, scaled, 0.0001)
}

TEST_CASE("scaledQuantities: scales up correctly (2)", "[task_4]") {
TEST_CASE("scaleRecipe: scales up correctly (2)", "[task_4]") {
const std::vector<double> input{0.6, 300, 1, 0.5, 50, 0.1, 100};
int portions{3};
std::vector<double> expected{0.9, 450, 1.5, 0.75, 75, 0.15, 150};
std::vector<double> scaled{scaledQuantities(input, portions)};
std::vector<double> scaled{scaleRecipe(input, portions)};
REQUIRE_VECTOR_APROX_EQUAL(expected, scaled, 0.0001)
}

TEST_CASE("scaledQuantities: scales down correctly", "[task_4]") {
TEST_CASE("scaleRecipe: scales down correctly", "[task_4]") {
const std::vector<double> input{0.5, 250, 150, 3, 0.5};
int portions{1};
std::vector<double> expected{0.25, 125, 75, 1.5, 0.25};
std::vector<double> scaled{scaledQuantities(input, portions)};
std::vector<double> scaled{scaleRecipe(input, portions)};
REQUIRE_VECTOR_APROX_EQUAL(expected, scaled, 0.0001)
}

TEST_CASE("scaledQuantities: empty recipe", "[task_4]") {
TEST_CASE("scaleRecipe: empty recipe", "[task_4]") {
const std::vector<double> input{};
int portions{100};
std::vector<double> expected{};
std::vector<double> scaled{scaledQuantities(input, portions)};
std::vector<double> scaled{scaleRecipe(input, portions)};
REQUIRE_VECTOR_APROX_EQUAL(expected, scaled, 0.0001)
}

Expand Down

0 comments on commit 304d35f

Please sign in to comment.