Browse Source

Exercism: Lucians Luscious Lasagna

master
Julio Biason 3 years ago
parent
commit
75805c7b95
  1. 24
      csharp/lucians-luscious-lasagna/.exercism/config.json
  2. 1
      csharp/lucians-luscious-lasagna/.exercism/metadata.json
  3. 39
      csharp/lucians-luscious-lasagna/HELP.md
  4. 38
      csharp/lucians-luscious-lasagna/HINTS.md
  5. 18
      csharp/lucians-luscious-lasagna/LuciansLusciousLasagna.cs
  6. 14
      csharp/lucians-luscious-lasagna/LuciansLusciousLasagna.csproj
  7. 47
      csharp/lucians-luscious-lasagna/LuciansLusciousLasagnaTests.cs
  8. 119
      csharp/lucians-luscious-lasagna/README.md

24
csharp/lucians-luscious-lasagna/.exercism/config.json

@ -0,0 +1,24 @@
{
"blurb": "Learn about the basics of C# by following a lasagna recipe.",
"icon": "lasagna",
"contributors": [
"yzAlvin"
],
"authors": [
"ErikSchierboom"
],
"forked_from": [
"fsharp/lucians-luscious-lasagna"
],
"files": {
"solution": [
"LuciansLusciousLasagna.cs"
],
"test": [
"LuciansLusciousLasagnaTests.cs"
],
"exemplar": [
".meta/Exemplar.cs"
]
}
}

1
csharp/lucians-luscious-lasagna/.exercism/metadata.json

@ -0,0 +1 @@
{"track":"csharp","exercise":"lucians-luscious-lasagna","id":"4a034520eedc4be3a410268f8f334993","url":"https://exercism.org/tracks/csharp/exercises/lucians-luscious-lasagna","handle":"JBiason","is_requester":true,"auto_approve":false}

39
csharp/lucians-luscious-lasagna/HELP.md

@ -0,0 +1,39 @@
# Help
## Running the tests
You can run the tests by opening a command prompt in the exercise's directory, and then running the [`dotnet test` command](https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-test)
Alternatively, most IDE's have built-in support for running tests, including [Visual Studio](https://docs.microsoft.com/en-us/visualstudio/test/run-unit-tests-with-test-explorer), [Rider](https://www.jetbrains.com/help/rider/Unit_Testing_in_Solution.html) and [Visual Studio code](https://github.com/OmniSharp/omnisharp-vscode/wiki/How-to-run-and-debug-unit-tests).
See the [tests page](https://exercism.io/tracks/csharp/tests) for more information.
## Skipped tests
Initially, only the first test will be enabled.
This is to encourage you to solve the exercise one step at a time.
Once you get the first test passing, remove the `Skip` property from the next test and work on getting that test passing.
## Submitting your solution
You can submit your solution using the `exercism submit LuciansLusciousLasagna.cs` command.
This command will upload your solution to the Exercism website and print the solution page's URL.
It's possible to submit an incomplete solution which allows you to:
- See how others have completed the exercise
- Request help from a mentor
## Need to get help?
If you'd like help solving the exercise, check the following pages:
- The [C# track's documentation](https://exercism.org/docs/tracks/csharp)
- [Exercism's support channel on gitter](https://gitter.im/exercism/support)
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
To get help if you're having trouble, you can use one of the following resources:
- [Gitter](https://gitter.im/exercism/xcsharp) is Exercism C# track's Gitter room; go here to get support and ask questions related to the C# track.
- [/r/csharp](https://www.reddit.com/r/csharp) is the C# subreddit.
- [StackOverflow](http://stackoverflow.com/questions/tagged/c%23) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions.

38
csharp/lucians-luscious-lasagna/HINTS.md

@ -0,0 +1,38 @@
# Hints
## General
- An [integer value][integers] can be defined as one or more consecutive digits.
## 1. Define the expected oven time in minutes
- You need to define a [method][methods] without any arguments.
- You need to return an [integer][integers].
## 2. Calculate the remaining oven time in minutes
- You need to define a [method][methods] with a single parameter.
- You have to [explicitly return an integer][return] from a method.
- The method's parameter is an [integer][integers].
- You can use the [mathematical operator for subtraction][operators] to subtract values.
## 3. Calculate the preparation time in minutes
- You need to define a [method][methods] with a single parameter.
- You have to [explicitly return an integer][return] from a method.
- The method's parameter is an [integer][integers].
- You can use the [mathematical operator for multiplicaton][operators] to multiply values.
## 4. Calculate the elapsed time in minutes
- You need to define a [method][methods] with two parameters.
- You have to [explicitly return an integer][return] from a method.
- The method's parameter is an [integer][integers].
- You can [invoke][invocation] one of the other methods you've defined previously.
- You can use the [mathematical operator for addition][operators] to add values.
[methods]: https://docs.microsoft.com/en-us/dotnet/csharp/methods
[return]: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/return
[operators]: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/arithmetic-operators#addition-operator-
[integers]: https://docs.microsoft.com/en-us/dotnet/api/system.int32?view=netcore-3.1#instantiating-an-int32-value
[invocation]: https://docs.microsoft.com/en-us/dotnet/csharp/methods#method-invocation

18
csharp/lucians-luscious-lasagna/LuciansLusciousLasagna.cs

@ -0,0 +1,18 @@
class Lasagna
{
public int ExpectedMinutesInOven() {
return 40;
}
public int RemainingMinutesInOven(int elapsed) {
return ExpectedMinutesInOven() - elapsed;
}
public int PreparationTimeInMinutes(int layers) {
return layers * 2;
}
public int ElapsedTimeInMinutes(int layers, int elapsed) {
return PreparationTimeInMinutes(layers) + elapsed;
}
}

14
csharp/lucians-luscious-lasagna/LuciansLusciousLasagna.csproj

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
<PackageReference Include="Exercism.Tests" Version="0.1.0-beta1" />
</ItemGroup>
</Project>

47
csharp/lucians-luscious-lasagna/LuciansLusciousLasagnaTests.cs

@ -0,0 +1,47 @@
using Xunit;
using Exercism.Tests;
public class LasagnaTests
{
[Fact]
[Task(1)]
public void Expected_minutes_in_oven()
{
Assert.Equal(40, new Lasagna().ExpectedMinutesInOven());
}
[Fact]
[Task(2)]
public void Remaining_minutes_in_oven()
{
Assert.Equal(15, new Lasagna().RemainingMinutesInOven(25));
}
[Fact]
[Task(3)]
public void Preparation_time_in_minutes_for_one_layer()
{
Assert.Equal(2, new Lasagna().PreparationTimeInMinutes(1));
}
[Fact]
[Task(3)]
public void Preparation_time_in_minutes_for_multiple_layers()
{
Assert.Equal(8, new Lasagna().PreparationTimeInMinutes(4));
}
[Fact]
[Task(4)]
public void Elapsed_time_in_minutes_for_one_layer()
{
Assert.Equal(32, new Lasagna().ElapsedTimeInMinutes(1, 30));
}
[Fact]
[Task(4)]
public void Elapsed_time_in_minutes_for_multiple_layers()
{
Assert.Equal(16, new Lasagna().ElapsedTimeInMinutes(4, 8));
}
}

119
csharp/lucians-luscious-lasagna/README.md

@ -0,0 +1,119 @@
# Lucian's Luscious Lasagna
Welcome to Lucian's Luscious Lasagna on Exercism's C# Track.
If you need help running the tests or submitting your code, check out `HELP.md`.
If you get stuck on the exercise, check out `HINTS.md`, but try and solve it without using those first :)
## Introduction
C# is a statically-typed language, which means that everything has a type at compile-time. Assigning a value to a name is referred to as defining a variable. A variable can be defined either by explicitly specifying its type, or by letting the C# compiler infer its type based on the assigned value (known as _type inference_). Therefore, the following two variable definitions are equivalent:
```csharp
int explicitVar = 10; // Explicitly typed
var implicitVar = 10; // Implicitly typed
```
Updating a variable's value is done through the `=` operator. Once defined, a variable's type can never change.
```csharp
var count = 1; // Assign initial value
count = 2; // Update to new value
// Compiler error when assigning different type
// count = false;
```
C# is an [object-oriented language][object-oriented-programming] and requires all functions to be defined in a _class_. The `class` keyword is used to define a class. Objects (or _instances_) are created by using the `new` keyword.
```csharp
class Calculator
{
// ...
}
var calculator = new Calculator();
```
A function within a class is referred to as a _method_. Each method can have zero or more parameters. All parameters must be explicitly typed, there is no type inference for parameters. Similarly, the return type must also be made explicit. Values are returned from methods using the `return` keyword. To allow a method to be called by code in other files, the `public` access modifier must be added.
```csharp
class Calculator
{
public int Add(int x, int y)
{
return x + y;
}
}
```
Methods are invoked using dot (`.`) syntax on an instance, specifying the method name to call and passing arguments for each of the method's parameters. Arguments can optionally specify the corresponding parameter's name.
```csharp
var calculator = new Calculator();
var sum_v1 = calculator.Add(1, 2);
var sum_v2 = calculator.Add(x: 1, y: 2);
```
Scope in C# is defined between the `{` and `}` characters.
C# supports two types of comments. Single line comments are preceded by `//` and multiline comments are inserted between `/*` and `*/`.
[object-oriented-programming]: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/object-oriented-programming
## Instructions
Lucian's girlfriend is on her way home and he hasn't cooked their anniversary dinner!
In this exercise, you're going to write some code to help Lucian cook an exquisite lasagna from his favorite cook book.
You have four tasks, all related to the time spent cooking the lasagna.
## 1. Define the expected oven time in minutes
Define the `Lasagna.ExpectedMinutesInOven()` method that does not take any parameters and returns how many minutes the lasagna should be in the oven. According to the cooking book, the expected oven time in minutes is 40:
```csharp
var lasagna = new Lasagna();
lasagna.ExpectedMinutesInOven();
// => 40
```
## 2. Calculate the remaining oven time in minutes
Define the `Lasagna.RemainingMinutesInOven()` method that takes the actual minutes the lasagna has been in the oven as a parameter and returns how many minutes the lasagna still has to remain in the oven, based on the expected oven time in minutes from the previous task.
```csharp
var lasagna = new Lasagna();
lasagna.RemainingMinutesInOven(30);
// => 10
```
## 3. Calculate the preparation time in minutes
Define the `Lasagna.PreparationTimeInMinutes()` method that takes the number of layers you added to the lasagna as a parameter and returns how many minutes you spent preparing the lasagna, assuming each layer takes you 2 minutes to prepare.
```csharp
var lasagna = new Lasagna();
lasagna.PreparationTimeInMinutes(2);
// => 4
```
## 4. Calculate the elapsed time in minutes
Define the `Lasagna.ElapsedTimeInMinutes()` method that takes two parameters: the first parameter is the number of layers you added to the lasagna, and the second parameter is the number of minutes the lasagna has been in the oven. The function should return how many minutes you've worked on cooking the lasagna, which is the sum of the preparation time in minutes, and the time in minutes the lasagna has spent in the oven at the moment.
```csharp
var lasagna = new Lasagna();
lasagna.ElapsedTimeInMinutes(3, 20);
// => 26
```
## Source
### Created by
- @ErikSchierboom
### Contributed to by
- @yzAlvin
Loading…
Cancel
Save