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 all 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>
13 changes: 13 additions & 0 deletions CourseApp.Tests/CodeWarsUnitTests/CamalCaseTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace CodeWarsTests.UnitTest;

using CodWearsTests;
using Xunit;

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

using CodWearsTests;
using Xunit;

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);
}
}
19 changes: 19 additions & 0 deletions CourseApp.Tests/CodeWarsUnitTests/FindMissingLetter.Test.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace CodeWarsTests.UnitTest;

using CodWearsTests;
using Xunit;

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' }));
}
}
13 changes: 13 additions & 0 deletions CourseApp.Tests/CodeWarsUnitTests/Merge.Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace CodeWarsTests.UnitTest;

using CodWearsTests;
using Xunit;

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;
}
}
27 changes: 27 additions & 0 deletions CourseApp.Tests/CodeWarsUnitTests/TowerTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace CodeWarsTests.UnitTest;

using CodWearsTests;
using Xunit;

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>
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