Skip to content

Commit

Permalink
june
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre Susantin committed Jun 22, 2024
1 parent 3efb9c7 commit 1e03fb6
Show file tree
Hide file tree
Showing 22 changed files with 704 additions and 68 deletions.
27 changes: 27 additions & 0 deletions circular-buffer/.exercism/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"authors": [
"ErikSchierboom"
],
"contributors": [
"j2jensen",
"robkeim",
"wolf99"
],
"files": {
"solution": [
"CircularBuffer.cs"
],
"test": [
"CircularBufferTests.cs"
],
"example": [
".meta/Example.cs"
],
"invalidator": [
"CircularBuffer.csproj"
]
},
"blurb": "A data structure that uses a single, fixed-size buffer as if it were connected end-to-end.",
"source": "Wikipedia",
"source_url": "https://en.wikipedia.org/wiki/Circular_buffer"
}
2 changes: 1 addition & 1 deletion circular-buffer/.exercism/metadata.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"track":"csharp","exercise":"circular-buffer","id":"63710780b34a48898f11e31386975e9e","url":"https://exercism.io/my/solutions/63710780b34a48898f11e31386975e9e","handle":"dynamo-patch","is_requester":true,"auto_approve":false}
{"track":"csharp","exercise":"circular-buffer","id":"63710780b34a48898f11e31386975e9e","url":"https://exercism.org/tracks/csharp/exercises/circular-buffer","handle":"dynamo-patch","is_requester":true,"auto_approve":false}
7 changes: 2 additions & 5 deletions circular-buffer/CircularBuffer.csproj
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Compile Remove="Example.cs" />
</ItemGroup>

<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>
31 changes: 15 additions & 16 deletions circular-buffer/CircularBufferTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// This file was auto-generated based on version 1.2.0 of the canonical data.

using System;
using Xunit;

Expand All @@ -12,15 +10,15 @@ public void Reading_empty_buffer_should_fail()
Assert.Throws<InvalidOperationException>(() => buffer.Read());
}


[Fact(Skip = "Remove this Skip property to run this test")]
public void Can_read_an_item_just_written()
{
var buffer = new CircularBuffer<int>(capacity: 1);
buffer.Write(1);
Assert.Equal(1, buffer.Read());
}


[Fact(Skip = "Remove this Skip property to run this test")]
public void Each_item_may_only_be_read_once()
{
var buffer = new CircularBuffer<int>(capacity: 1);
Expand All @@ -29,7 +27,7 @@ public void Each_item_may_only_be_read_once()
Assert.Throws<InvalidOperationException>(() => buffer.Read());
}


[Fact(Skip = "Remove this Skip property to run this test")]
public void Items_are_read_in_the_order_they_are_written()
{
var buffer = new CircularBuffer<int>(capacity: 2);
Expand All @@ -39,15 +37,15 @@ public void Items_are_read_in_the_order_they_are_written()
Assert.Equal(2, buffer.Read());
}


[Fact(Skip = "Remove this Skip property to run this test")]
public void Full_buffer_cant_be_written_to()
{
var buffer = new CircularBuffer<int>(capacity: 1);
buffer.Write(1);
Assert.Throws<InvalidOperationException>(() => buffer.Write(2));
}


[Fact(Skip = "Remove this Skip property to run this test")]
public void A_read_frees_up_capacity_for_another_write()
{
var buffer = new CircularBuffer<int>(capacity: 1);
Expand All @@ -57,7 +55,7 @@ public void A_read_frees_up_capacity_for_another_write()
Assert.Equal(2, buffer.Read());
}


[Fact(Skip = "Remove this Skip property to run this test")]
public void Read_position_is_maintained_even_across_multiple_writes()
{
var buffer = new CircularBuffer<int>(capacity: 3);
Expand All @@ -69,16 +67,17 @@ public void Read_position_is_maintained_even_across_multiple_writes()
Assert.Equal(3, buffer.Read());
}


[Fact(Skip = "Remove this Skip property to run this test")]
public void Items_cleared_out_of_buffer_cant_be_read()
{
var buffer = new CircularBuffer<int>(capacity: 1);
var buffer = new CircularBuffer<int>(capacity: 3);
buffer.Write(1);
buffer.Write(2);
buffer.Clear();
Assert.Throws<InvalidOperationException>(() => buffer.Read());
}


[Fact(Skip = "Remove this Skip property to run this test")]
public void Clear_frees_up_capacity_for_another_write()
{
var buffer = new CircularBuffer<int>(capacity: 1);
Expand All @@ -88,7 +87,7 @@ public void Clear_frees_up_capacity_for_another_write()
Assert.Equal(2, buffer.Read());
}


[Fact(Skip = "Remove this Skip property to run this test")]
public void Clear_does_nothing_on_empty_buffer()
{
var buffer = new CircularBuffer<int>(capacity: 1);
Expand All @@ -97,7 +96,7 @@ public void Clear_does_nothing_on_empty_buffer()
Assert.Equal(1, buffer.Read());
}


[Fact(Skip = "Remove this Skip property to run this test")]
public void Overwrite_acts_like_write_on_non_full_buffer()
{
var buffer = new CircularBuffer<int>(capacity: 2);
Expand All @@ -107,7 +106,7 @@ public void Overwrite_acts_like_write_on_non_full_buffer()
Assert.Equal(2, buffer.Read());
}


[Fact(Skip = "Remove this Skip property to run this test")]
public void Overwrite_replaces_the_oldest_item_on_full_buffer()
{
var buffer = new CircularBuffer<int>(capacity: 2);
Expand All @@ -118,7 +117,7 @@ public void Overwrite_replaces_the_oldest_item_on_full_buffer()
Assert.Equal(3, buffer.Read());
}


[Fact(Skip = "Remove this Skip property to run this test")]
public void Overwrite_replaces_the_oldest_item_remaining_in_buffer_following_a_read()
{
var buffer = new CircularBuffer<int>(capacity: 3);
Expand All @@ -133,7 +132,7 @@ public void Overwrite_replaces_the_oldest_item_remaining_in_buffer_following_a_r
Assert.Equal(5, buffer.Read());
}


[Fact(Skip = "Remove this Skip property to run this test")]
public void Initial_clear_does_not_affect_wrapping_around()
{
var buffer = new CircularBuffer<int>(capacity: 2);
Expand Down
39 changes: 39 additions & 0 deletions circular-buffer/HELP.md
Original file line number Diff line number Diff line change
@@ -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.org/docs/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 CircularBuffer.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)
- The [C# track's programming category on the forum](https://forum.exercism.org/c/programming/csharp)
- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5)
- 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:

- [/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.
85 changes: 39 additions & 46 deletions circular-buffer/README.md
Original file line number Diff line number Diff line change
@@ -1,70 +1,63 @@
# Circular Buffer

A circular buffer, cyclic buffer or ring buffer is a data structure that
uses a single, fixed-size buffer as if it were connected end-to-end.
Welcome to Circular Buffer on Exercism's C# Track.
If you need help running the tests or submitting your code, check out `HELP.md`.

A circular buffer first starts empty and of some predefined length. For
example, this is a 7-element buffer:
## Instructions

[ ][ ][ ][ ][ ][ ][ ]
A circular buffer, cyclic buffer or ring buffer is a data structure that uses a single, fixed-size buffer as if it were connected end-to-end.

Assume that a 1 is written into the middle of the buffer (exact starting
location does not matter in a circular buffer):
A circular buffer first starts empty and of some predefined length.
For example, this is a 7-element buffer:
<!-- prettier-ignore -->
[ ][ ][ ][ ][ ][ ][ ]

Assume that a 1 is written into the middle of the buffer (exact starting location does not matter in a circular buffer):
<!-- prettier-ignore -->
[ ][ ][ ][1][ ][ ][ ]

Then assume that two more elements are added — 2 & 3 — which get
appended after the 1:

Then assume that two more elements are added — 2 & 3 — which get appended after the 1:
<!-- prettier-ignore -->
[ ][ ][ ][1][2][3][ ]

If two elements are then removed from the buffer, the oldest values
inside the buffer are removed. The two elements removed, in this case,
are 1 & 2, leaving the buffer with just a 3:

If two elements are then removed from the buffer, the oldest values inside the buffer are removed.
The two elements removed, in this case, are 1 & 2, leaving the buffer with just a 3:
<!-- prettier-ignore -->
[ ][ ][ ][ ][ ][3][ ]

If the buffer has 7 elements then it is completely full:
<!-- prettier-ignore -->
[5][6][7][8][9][3][4]

[6][7][8][9][3][4][5]

When the buffer is full an error will be raised, alerting the client
that further writes are blocked until a slot becomes free.

When the buffer is full, the client can opt to overwrite the oldest
data with a forced write. In this case, two more elements — A & B —
are added and they overwrite the 3 & 4:
When the buffer is full an error will be raised, alerting the client that further writes are blocked until a slot becomes free.

[6][7][8][9][A][B][5]
When the buffer is full, the client can opt to overwrite the oldest data with a forced write.
In this case, two more elements — A & B — are added and they overwrite the 3 & 4:
<!-- prettier-ignore -->
[5][6][7][8][9][A][B]

3 & 4 have been replaced by A & B making 5 now the oldest data in the
buffer. Finally, if two elements are removed then what would be
returned is 5 & 6 yielding the buffer:
3 & 4 have been replaced by A & B making 5 now the oldest data in the buffer.
Finally, if two elements are removed then what would be returned is 5 & 6 yielding the buffer:
<!-- prettier-ignore -->
[ ][ ][7][8][9][A][B]

[ ][7][8][9][A][B][ ]
Because there is space available, if the client again uses overwrite to store C & D then the space where 5 & 6 were stored previously will be used not the location of 7 & 8.
7 is still the oldest element and the buffer is once again full.
<!-- prettier-ignore -->
[C][D][7][8][9][A][B]

Because there is space available, if the client again uses overwrite
to store C & D then the space where 5 & 6 were stored previously will
be used not the location of 7 & 8. 7 is still the oldest element and
the buffer is once again full.

[D][7][8][9][A][B][C]

## Running the tests

To run the tests, run the command `dotnet test` from within the exercise directory.
## Source

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.
Once none of the tests are skipped and they are all passing, you can submit your solution
using `exercism submit CircularBuffer.cs`
### Created by

## Further information
- @ErikSchierboom

For more detailed information about the C# track, including how to get help if
you're having trouble, please visit the exercism.io [C# language page](http://exercism.io/languages/csharp/resources).
### Contributed to by

## Source
- @j2jensen
- @robkeim
- @wolf99

Wikipedia [http://en.wikipedia.org/wiki/Circular_buffer](http://en.wikipedia.org/wiki/Circular_buffer)
### Based on

Wikipedia - https://en.wikipedia.org/wiki/Circular_buffer
20 changes: 20 additions & 0 deletions log-levels/.exercism/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"blurb": "Learn about strings by processing logs.",
"contributors": [
"yzAlvin"
],
"authors": [
"ErikSchierboom"
],
"files": {
"solution": [
"LogLevels.cs"
],
"test": [
"LogLevelsTests.cs"
],
"exemplar": [
".meta/Exemplar.cs"
]
}
}
1 change: 1 addition & 0 deletions log-levels/.exercism/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"track":"csharp","exercise":"log-levels","id":"589436fa563d43d2ac9f77e8e29d0f0e","url":"https://exercism.org/tracks/csharp/exercises/log-levels","handle":"dynamo-patch","is_requester":true,"auto_approve":false}
39 changes: 39 additions & 0 deletions log-levels/HELP.md
Original file line number Diff line number Diff line change
@@ -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 LogLevels.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.
Loading

0 comments on commit 1e03fb6

Please sign in to comment.