Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CodeWars, Dog class #16

Open
wants to merge 22 commits into
base: Belov_Stepan_Maksimovich
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/dotnetcore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
dotnet: [ '2.1', '5.0.x', '6.0.x' ]
dotnet: [ '7.0.x' ]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ matrix.dotnet-version }}
include-prerelease: true
Expand All @@ -24,4 +24,4 @@ jobs:
- name: Run tests
run: |
cd CourseApp.Tests
dotnet test
dotnet test CourseApp.Tests.csproj
29 changes: 29 additions & 0 deletions CourseApp.Tests/CodeWarsTests.UnitTest.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0"/>
<PackageReference Include="xunit" Version="2.4.2"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.2.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\CodeWarsTests\CodeWarsTests.csproj" />
</ItemGroup>

</Project>
12 changes: 12 additions & 0 deletions CourseApp.Tests/CodeWarsUnitTests/CamalCaseTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace CodeWarsTests.UnitTest;

using CodWearsTests;

public class CamalCaseTest
{
[Fact]
public void Test1()
{
Assert.Equal("theStealthWarrior", StrToCamelCase.ToCamelCase("the_stealth_warrior"));
}
}
42 changes: 42 additions & 0 deletions CourseApp.Tests/CodeWarsUnitTests/DuplicatesEncoderTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
namespace CodeWarsTests.UnitTest;

using CodWearsTests;

public class DuplicatesEncoderTest
{
[Fact]
public void Test1()
{
// Act
var res = DuplicatesEncoder.DuplicateEncode("din");

Assert.Equal("(((", res);
}

[Fact]
public void Test2()
{
// Act
var res = DuplicatesEncoder.DuplicateEncode("recede");

Assert.Equal("()()()", res);
}

[Fact]
public void Test3()
{
// Act
var res = DuplicatesEncoder.DuplicateEncode("Success");

Assert.Equal(")())())", res);
}

[Fact]
public void Test4()
{
// Act
var res = DuplicatesEncoder.DuplicateEncode("(( @");

Assert.Equal("))((", res);
}
}
18 changes: 18 additions & 0 deletions CourseApp.Tests/CodeWarsUnitTests/FindMissingLetter.Test.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace CodeWarsTests.UnitTest;

using CodWearsTests;

public class FindMissingLetter_Test
{
[Fact]
public void Test1()
{
Assert.Equal('e', MissingLetter.FindMissingLetter(new[] { 'a', 'b', 'c', 'd', 'f' }));
}

[Fact]
public void Test2()
{
Assert.Equal('P', MissingLetter.FindMissingLetter(new[] { 'O', 'Q', 'R', 'S' }));
}
}
12 changes: 12 additions & 0 deletions CourseApp.Tests/CodeWarsUnitTests/Merge.Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace CodeWarsTests.UnitTest;

using CodWearsTests;

public class Merge_Tests
{
[Fact]
public void Test1()
{
Assert.Equal(new string[] { "a", "1", "b", "2", "c", "3", "d", "e" }, Merge.MergeArrays(new string[] { "a", "b", "c", "d", "e" }, new string[] { "1", "2", "3" }));
}
}
9 changes: 9 additions & 0 deletions CourseApp.Tests/CodeWarsUnitTests/SumOfDigigts.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace CodeWarsTests.UnitTest;

public class SumOfDigigts
{
public int DigitalRoot(long n)
{
return 0;
}
}
26 changes: 26 additions & 0 deletions CourseApp.Tests/CodeWarsUnitTests/TowerTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace CodeWarsTests.UnitTest;

using CodWearsTests;

public class TowerTest
{
[Fact]
public void Test1()
{
Assert.Equal(string.Join(",", new[] { "*" }), string.Join(",", Towerbuild.TowerBuilder(1)));
}

[Fact]
public void Test2()
{
Assert.Equal(string.Join(",", new[] { " * ", "***" }), string.Join(",", Towerbuild.TowerBuilder(2)));
}

[Fact]
public void Test3()
{
Assert.Equal(
string.Join(",", new[] { " * ", " *** ", "*****" }),
string.Join(",", Towerbuild.TowerBuilder(3)));
}
}
3 changes: 2 additions & 1 deletion CourseApp.Tests/CourseApp.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<IsPackable>false</IsPackable>
</PropertyGroup>
Expand Down Expand Up @@ -29,4 +29,5 @@
<AdditionalFiles Include="../_stylecop/stylecop.json" />
</ItemGroup>


</Project>
3 changes: 3 additions & 0 deletions CourseApp.Tests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma warning disable SA1200
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а это зачем?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Линтер указывает на ошибку в том, что using директивы расположены неправильно. Считает, что using должен располагаться после пространства имён. Я поправил, докинул в каждый класс с тестами "using Xuint" и удалил этот файл.
На будущее хотел бы спросить, есть ли какой-то более важный плюс у этого global, чем просто везде не указывать, одинаковые using'и?

global using Xunit;
#pragma warning restore SA1200
9 changes: 9 additions & 0 deletions CourseApp/CodeWars/DigitalRootClass.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace CodWearsTests;

public class DigitalRootClass
{
public static int DigitalRoot(long n)
{
return 0;
}
}
19 changes: 19 additions & 0 deletions CourseApp/CodeWars/DuplicatesEncoder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace CodWearsTests;

using System.Linq;
using System.Collections.Generic;

public class DuplicatesEncoder
{
public static string DuplicateEncode(string word)
{
var mass = new List<string>();
word = word.ToLower();
foreach (var sym in word)
{
mass.Add(word.Count(x => x == sym) != 1 ? ")" : "(");
}

return string.Join(string.Empty, mass);
}
}
19 changes: 19 additions & 0 deletions CourseApp/CodeWars/FibNums.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace CodWearsTests;

public class FibNums
{
public static ulong[] ProductFib(ulong prod)
{
ulong a = 0;
ulong b = 1;

while (a * b < prod)
{
ulong temp = a;
a = b;
b = temp + b;
}

return new ulong[] { a, b, (ulong)(a * b == prod ? 1 : 0) };
}
}
37 changes: 37 additions & 0 deletions CourseApp/CodeWars/Merge.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
namespace CodWearsTests;

using System.Collections.Generic;

public class Merge
{
public static string[] MergeArrays(string[] arr1, string[] arr2)
{
var res = new List<string>();
var length = arr1.Length > arr2.Length ? arr2.Length : arr1.Length;
var index = 0;

while (index < length)
{
res.Add(arr1[index]);
res.Add(arr2[index]);
index++;
}

if (arr1.Length > arr2.Length)
{
for (; index < arr1.Length; index++)
{
res.Add(arr1[index]);
}
}
else
{
for (; index < arr2.Length; index++)
{
res.Add(arr2[index]);
}
}

return res.ToArray();
}
}
24 changes: 24 additions & 0 deletions CourseApp/CodeWars/MissingLetter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace CodWearsTests;

public class MissingLetter
{
public static char FindMissingLetter(char[] chars)
{
var alphabet = "abcdefghijklmnopqrstuvwxyz";
chars.ToString();

if (char.IsUpper(chars[0]))
{
alphabet = alphabet.ToUpper();
}

var index = alphabet.IndexOf(chars[0]);

for (int i = 0; chars[i] == alphabet[index]; i++)
{
index++;
}

return alphabet[index];
}
}
25 changes: 25 additions & 0 deletions CourseApp/CodeWars/StrToCamelCase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace CodWearsTests;

public class StrToCamelCase
{
public static string ToCamelCase(string str)
{
var res = string.Empty;

str.ToCharArray();
for (int i = 0; i < str.Length; i++)
{
if (str[i] != '_' && str[i] != '-')
{
res += str[i].ToString();
}
else
{
res += str[i + 1].ToString().ToUpper();
i += 1;
}
}

return res;
}
}
36 changes: 36 additions & 0 deletions CourseApp/CodeWars/TicTakToe.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
namespace CodWearsTests;

public class TicTacToe
{
public int IsSolved(int[,] board)
{
for (int i = 0; i < 2; i++)
{
if (board[i, 0] == board[i, 1] && (board[i, 1] == board[i, 2]) && board[i, 1] != 0)
{
return board[i, 0];
}
else if (board[0, i] == board[1, i] && board[1, i] == board[2, i] && board[1, i] != 0)
{
return board[i, 0];
}
else if ((board[0, 0] == board[1, 1] && board[1, 1] == board[2, 2] && board[1, 1] != 0) ||
(board[2, 0] == board[1, 1] && board[1, 1] == board[0, 2] && board[1, 1] != 0))
{
return board[1, 1];
}
else
{
for (int k = 0; k < 2; k++)
{
if (board[i, k] == 0)
{
return -1;
}
}
}
}

return 0;
}
}
Loading
Loading