From 73fb6b9160608305e8738d2e05bdcd03f9b86d3c Mon Sep 17 00:00:00 2001 From: Fuflick Date: Thu, 28 Sep 2023 16:57:34 +0300 Subject: [PATCH 01/22] CodeWars tasks and tests for whem --- CourseApp.Tests/CamalCaseTest.cs | 13 ++++++ CourseApp.Tests/CodeWarsTests.UnitTest.csproj | 29 +++++++++++++ CourseApp.Tests/DuplicatesEncoderTest.cs | 42 +++++++++++++++++++ CourseApp.Tests/FindMissingLetter.Test.cs | 18 ++++++++ CourseApp.Tests/GlobalUsings.cs | 1 + CourseApp.Tests/Merge.Tests.cs | 13 ++++++ CourseApp.Tests/SumOfDigigts.cs | 9 ++++ CourseApp.Tests/TowerTest.cs | 26 ++++++++++++ CourseApp/DigitalRootClass.cs | 9 ++++ CourseApp/DuplicatesEncoder.cs | 16 +++++++ CourseApp/FibNums.cs | 20 +++++++++ CourseApp/Merge.cs | 35 ++++++++++++++++ CourseApp/MissingLetter.cs | 24 +++++++++++ CourseApp/StrToCamelCase.cs | 25 +++++++++++ CourseApp/TicTakToe.cs | 39 +++++++++++++++++ CourseApp/Towerbuild.cs | 18 ++++++++ CourseApp/Zeroes.cs | 6 +++ 17 files changed, 343 insertions(+) create mode 100644 CourseApp.Tests/CamalCaseTest.cs create mode 100644 CourseApp.Tests/CodeWarsTests.UnitTest.csproj create mode 100644 CourseApp.Tests/DuplicatesEncoderTest.cs create mode 100644 CourseApp.Tests/FindMissingLetter.Test.cs create mode 100644 CourseApp.Tests/GlobalUsings.cs create mode 100644 CourseApp.Tests/Merge.Tests.cs create mode 100644 CourseApp.Tests/SumOfDigigts.cs create mode 100644 CourseApp.Tests/TowerTest.cs create mode 100644 CourseApp/DigitalRootClass.cs create mode 100644 CourseApp/DuplicatesEncoder.cs create mode 100644 CourseApp/FibNums.cs create mode 100644 CourseApp/Merge.cs create mode 100644 CourseApp/MissingLetter.cs create mode 100644 CourseApp/StrToCamelCase.cs create mode 100644 CourseApp/TicTakToe.cs create mode 100644 CourseApp/Towerbuild.cs create mode 100644 CourseApp/Zeroes.cs diff --git a/CourseApp.Tests/CamalCaseTest.cs b/CourseApp.Tests/CamalCaseTest.cs new file mode 100644 index 0000000..c185ca0 --- /dev/null +++ b/CourseApp.Tests/CamalCaseTest.cs @@ -0,0 +1,13 @@ +using CodeWarsTests; +using CodWearsTests; + +namespace CodeWarsTests.UnitTest; + +public class CamalCaseTest +{ + [Fact] + public void Test1() + { + Assert.Equal("theStealthWarrior", StrToCamelCase.ToCamelCase("the_stealth_warrior")); + } +} \ No newline at end of file diff --git a/CourseApp.Tests/CodeWarsTests.UnitTest.csproj b/CourseApp.Tests/CodeWarsTests.UnitTest.csproj new file mode 100644 index 0000000..baf3035 --- /dev/null +++ b/CourseApp.Tests/CodeWarsTests.UnitTest.csproj @@ -0,0 +1,29 @@ + + + + net7.0 + enable + enable + + false + true + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + diff --git a/CourseApp.Tests/DuplicatesEncoderTest.cs b/CourseApp.Tests/DuplicatesEncoderTest.cs new file mode 100644 index 0000000..303fba8 --- /dev/null +++ b/CourseApp.Tests/DuplicatesEncoderTest.cs @@ -0,0 +1,42 @@ +using CodWearsTests; + +namespace CodeWarsTests.UnitTest; + +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); + } +} \ No newline at end of file diff --git a/CourseApp.Tests/FindMissingLetter.Test.cs b/CourseApp.Tests/FindMissingLetter.Test.cs new file mode 100644 index 0000000..8ad42bc --- /dev/null +++ b/CourseApp.Tests/FindMissingLetter.Test.cs @@ -0,0 +1,18 @@ +using CodWearsTests; + +namespace CodeWarsTests.UnitTest; + +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' })); + } +} \ No newline at end of file diff --git a/CourseApp.Tests/GlobalUsings.cs b/CourseApp.Tests/GlobalUsings.cs new file mode 100644 index 0000000..8c927eb --- /dev/null +++ b/CourseApp.Tests/GlobalUsings.cs @@ -0,0 +1 @@ +global using Xunit; \ No newline at end of file diff --git a/CourseApp.Tests/Merge.Tests.cs b/CourseApp.Tests/Merge.Tests.cs new file mode 100644 index 0000000..5adf8f4 --- /dev/null +++ b/CourseApp.Tests/Merge.Tests.cs @@ -0,0 +1,13 @@ +using CodeWarsTests; +using CodWearsTests; + +namespace CodeWarsTests.UnitTest; + +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" })); + } +} \ No newline at end of file diff --git a/CourseApp.Tests/SumOfDigigts.cs b/CourseApp.Tests/SumOfDigigts.cs new file mode 100644 index 0000000..9e02887 --- /dev/null +++ b/CourseApp.Tests/SumOfDigigts.cs @@ -0,0 +1,9 @@ +namespace CodeWarsTests.UnitTest; + +public class SumOfDigigts +{ + public int DigitalRoot(long n) + { + return 0; + } +} \ No newline at end of file diff --git a/CourseApp.Tests/TowerTest.cs b/CourseApp.Tests/TowerTest.cs new file mode 100644 index 0000000..3f5707c --- /dev/null +++ b/CourseApp.Tests/TowerTest.cs @@ -0,0 +1,26 @@ +using CodeWarsTests; +using CodWearsTests; + +namespace CodeWarsTests.UnitTest; + +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))); + } +} \ No newline at end of file diff --git a/CourseApp/DigitalRootClass.cs b/CourseApp/DigitalRootClass.cs new file mode 100644 index 0000000..486687d --- /dev/null +++ b/CourseApp/DigitalRootClass.cs @@ -0,0 +1,9 @@ +namespace CodWearsTests; + +public class DigitalRootClass +{ + public static int DigitalRoot(long n) + { + return 0; + } +} \ No newline at end of file diff --git a/CourseApp/DuplicatesEncoder.cs b/CourseApp/DuplicatesEncoder.cs new file mode 100644 index 0000000..4e9d912 --- /dev/null +++ b/CourseApp/DuplicatesEncoder.cs @@ -0,0 +1,16 @@ +namespace CodWearsTests; + +public class DuplicatesEncoder +{ + public static string DuplicateEncode(string word) + { + var mass = new List(); + word = word.ToLower(); + foreach (var sym in word) + { + mass.Add(word.Count(x => x == sym) != 1 ? ")" : "("); + } + + return string.Join("", mass); + } +} \ No newline at end of file diff --git a/CourseApp/FibNums.cs b/CourseApp/FibNums.cs new file mode 100644 index 0000000..c134937 --- /dev/null +++ b/CourseApp/FibNums.cs @@ -0,0 +1,20 @@ +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) }; + } + +} \ No newline at end of file diff --git a/CourseApp/Merge.cs b/CourseApp/Merge.cs new file mode 100644 index 0000000..08b3e7c --- /dev/null +++ b/CourseApp/Merge.cs @@ -0,0 +1,35 @@ +namespace CodWearsTests; + +public class Merge +{ + public static string[] MergeArrays(string[] arr1, string[] arr2) + { + var res = new List(); + 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(); + } +} \ No newline at end of file diff --git a/CourseApp/MissingLetter.cs b/CourseApp/MissingLetter.cs new file mode 100644 index 0000000..d976c55 --- /dev/null +++ b/CourseApp/MissingLetter.cs @@ -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]; + } +} \ No newline at end of file diff --git a/CourseApp/StrToCamelCase.cs b/CourseApp/StrToCamelCase.cs new file mode 100644 index 0000000..6fd93a0 --- /dev/null +++ b/CourseApp/StrToCamelCase.cs @@ -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; + } +} \ No newline at end of file diff --git a/CourseApp/TicTakToe.cs b/CourseApp/TicTakToe.cs new file mode 100644 index 0000000..98d47bf --- /dev/null +++ b/CourseApp/TicTakToe.cs @@ -0,0 +1,39 @@ +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; + } +} \ No newline at end of file diff --git a/CourseApp/Towerbuild.cs b/CourseApp/Towerbuild.cs new file mode 100644 index 0000000..410feff --- /dev/null +++ b/CourseApp/Towerbuild.cs @@ -0,0 +1,18 @@ +namespace CodWearsTests; + +public class Towerbuild +{ + public static string[] TowerBuilder(int nFloors) + { + var tower = new List(); + + for (int i = 0; i < nFloors; i++) + { + var padding = new string(' ', nFloors - i - 1); + var sharps = new string('*', i * 2 + 1); + tower.Add($"{padding}{sharps}{padding}"); + } + + return tower.ToArray(); + } +} \ No newline at end of file diff --git a/CourseApp/Zeroes.cs b/CourseApp/Zeroes.cs new file mode 100644 index 0000000..1ca5731 --- /dev/null +++ b/CourseApp/Zeroes.cs @@ -0,0 +1,6 @@ +namespace CodWearsTests; + +public class Zeroes +{ + public static int[] MoveZeroes(int[] array) => array.OrderBy(x => x == 0).ToArray(); +} \ No newline at end of file From f693ff4bcf6be6ca283d7435510df35f879d3fa1 Mon Sep 17 00:00:00 2001 From: Fuflick Date: Wed, 11 Oct 2023 09:17:23 +0300 Subject: [PATCH 02/22] CodeWars, dog class, fix linter --- .../{ => CodeWarsUnitTests}/CamalCaseTest.cs | 5 +-- .../{ => CodeWarsUnitTests}/DemoTest.cs | 0 .../DuplicatesEncoderTest.cs | 12 +++--- .../FindMissingLetter.Test.cs | 4 +- .../{ => CodeWarsUnitTests}/Merge.Tests.cs | 5 +-- .../{ => CodeWarsUnitTests}/SumOfDigigts.cs | 0 .../{ => CodeWarsUnitTests}/TowerTest.cs | 8 ++-- CourseApp.Tests/CourseApp.Tests.csproj | 1 + CourseApp.Tests/GlobalUsings.cs | 4 +- CourseApp/{ => CodeWars}/DigitalRootClass.cs | 0 CourseApp/{ => CodeWars}/DuplicatesEncoder.cs | 5 ++- CourseApp/{ => CodeWars}/FibNums.cs | 1 - CourseApp/{ => CodeWars}/Merge.cs | 2 + CourseApp/{ => CodeWars}/MissingLetter.cs | 0 CourseApp/{ => CodeWars}/StrToCamelCase.cs | 0 CourseApp/{ => CodeWars}/TicTakToe.cs | 3 -- CourseApp/{ => CodeWars}/Towerbuild.cs | 4 +- CourseApp/{ => CodeWars}/Zeroes.cs | 2 + CourseApp/CourseApp.csproj | 2 + CourseApp/DogClass/Dog.cs | 34 +++++++++++++++++ CourseApp/Phone.cs | 38 ------------------- CourseApp/Program.cs | 25 ++++-------- Dockerfile | 2 +- 23 files changed, 75 insertions(+), 82 deletions(-) rename CourseApp.Tests/{ => CodeWarsUnitTests}/CamalCaseTest.cs (76%) rename CourseApp.Tests/{ => CodeWarsUnitTests}/DemoTest.cs (100%) rename CourseApp.Tests/{ => CodeWarsUnitTests}/DuplicatesEncoderTest.cs (91%) rename CourseApp.Tests/{ => CodeWarsUnitTests}/FindMissingLetter.Test.cs (84%) rename CourseApp.Tests/{ => CodeWarsUnitTests}/Merge.Tests.cs (82%) rename CourseApp.Tests/{ => CodeWarsUnitTests}/SumOfDigigts.cs (100%) rename CourseApp.Tests/{ => CodeWarsUnitTests}/TowerTest.cs (77%) rename CourseApp/{ => CodeWars}/DigitalRootClass.cs (100%) rename CourseApp/{ => CodeWars}/DuplicatesEncoder.cs (75%) rename CourseApp/{ => CodeWars}/FibNums.cs (97%) rename CourseApp/{ => CodeWars}/Merge.cs (95%) rename CourseApp/{ => CodeWars}/MissingLetter.cs (100%) rename CourseApp/{ => CodeWars}/StrToCamelCase.cs (100%) rename CourseApp/{ => CodeWars}/TicTakToe.cs (98%) rename CourseApp/{ => CodeWars}/Towerbuild.cs (80%) rename CourseApp/{ => CodeWars}/Zeroes.cs (87%) create mode 100644 CourseApp/DogClass/Dog.cs delete mode 100644 CourseApp/Phone.cs diff --git a/CourseApp.Tests/CamalCaseTest.cs b/CourseApp.Tests/CodeWarsUnitTests/CamalCaseTest.cs similarity index 76% rename from CourseApp.Tests/CamalCaseTest.cs rename to CourseApp.Tests/CodeWarsUnitTests/CamalCaseTest.cs index c185ca0..df54908 100644 --- a/CourseApp.Tests/CamalCaseTest.cs +++ b/CourseApp.Tests/CodeWarsUnitTests/CamalCaseTest.cs @@ -1,7 +1,6 @@ -using CodeWarsTests; -using CodWearsTests; +namespace CodeWarsTests.UnitTest; -namespace CodeWarsTests.UnitTest; +using CodWearsTests; public class CamalCaseTest { diff --git a/CourseApp.Tests/DemoTest.cs b/CourseApp.Tests/CodeWarsUnitTests/DemoTest.cs similarity index 100% rename from CourseApp.Tests/DemoTest.cs rename to CourseApp.Tests/CodeWarsUnitTests/DemoTest.cs diff --git a/CourseApp.Tests/DuplicatesEncoderTest.cs b/CourseApp.Tests/CodeWarsUnitTests/DuplicatesEncoderTest.cs similarity index 91% rename from CourseApp.Tests/DuplicatesEncoderTest.cs rename to CourseApp.Tests/CodeWarsUnitTests/DuplicatesEncoderTest.cs index 303fba8..0266319 100644 --- a/CourseApp.Tests/DuplicatesEncoderTest.cs +++ b/CourseApp.Tests/CodeWarsUnitTests/DuplicatesEncoderTest.cs @@ -1,13 +1,13 @@ -using CodWearsTests; - namespace CodeWarsTests.UnitTest; +using CodWearsTests; + public class DuplicatesEncoderTest { [Fact] public void Test1() { - //Act + // Act var res = DuplicatesEncoder.DuplicateEncode("din"); Assert.Equal("(((", res); @@ -16,7 +16,7 @@ public void Test1() [Fact] public void Test2() { - //Act + // Act var res = DuplicatesEncoder.DuplicateEncode("recede"); Assert.Equal("()()()", res); @@ -25,7 +25,7 @@ public void Test2() [Fact] public void Test3() { - //Act + // Act var res = DuplicatesEncoder.DuplicateEncode("Success"); Assert.Equal(")())())", res); @@ -34,7 +34,7 @@ public void Test3() [Fact] public void Test4() { - //Act + // Act var res = DuplicatesEncoder.DuplicateEncode("(( @"); Assert.Equal("))((", res); diff --git a/CourseApp.Tests/FindMissingLetter.Test.cs b/CourseApp.Tests/CodeWarsUnitTests/FindMissingLetter.Test.cs similarity index 84% rename from CourseApp.Tests/FindMissingLetter.Test.cs rename to CourseApp.Tests/CodeWarsUnitTests/FindMissingLetter.Test.cs index 8ad42bc..a1863a3 100644 --- a/CourseApp.Tests/FindMissingLetter.Test.cs +++ b/CourseApp.Tests/CodeWarsUnitTests/FindMissingLetter.Test.cs @@ -1,6 +1,6 @@ -using CodWearsTests; +namespace CodeWarsTests.UnitTest; -namespace CodeWarsTests.UnitTest; +using CodWearsTests; public class FindMissingLetter_Test { diff --git a/CourseApp.Tests/Merge.Tests.cs b/CourseApp.Tests/CodeWarsUnitTests/Merge.Tests.cs similarity index 82% rename from CourseApp.Tests/Merge.Tests.cs rename to CourseApp.Tests/CodeWarsUnitTests/Merge.Tests.cs index 5adf8f4..3406d43 100644 --- a/CourseApp.Tests/Merge.Tests.cs +++ b/CourseApp.Tests/CodeWarsUnitTests/Merge.Tests.cs @@ -1,7 +1,6 @@ -using CodeWarsTests; -using CodWearsTests; +namespace CodeWarsTests.UnitTest; -namespace CodeWarsTests.UnitTest; +using CodWearsTests; public class Merge_Tests { diff --git a/CourseApp.Tests/SumOfDigigts.cs b/CourseApp.Tests/CodeWarsUnitTests/SumOfDigigts.cs similarity index 100% rename from CourseApp.Tests/SumOfDigigts.cs rename to CourseApp.Tests/CodeWarsUnitTests/SumOfDigigts.cs diff --git a/CourseApp.Tests/TowerTest.cs b/CourseApp.Tests/CodeWarsUnitTests/TowerTest.cs similarity index 77% rename from CourseApp.Tests/TowerTest.cs rename to CourseApp.Tests/CodeWarsUnitTests/TowerTest.cs index 3f5707c..6dc681d 100644 --- a/CourseApp.Tests/TowerTest.cs +++ b/CourseApp.Tests/CodeWarsUnitTests/TowerTest.cs @@ -1,7 +1,6 @@ -using CodeWarsTests; -using CodWearsTests; +namespace CodeWarsTests.UnitTest; -namespace CodeWarsTests.UnitTest; +using CodWearsTests; public class TowerTest { @@ -20,7 +19,8 @@ public void Test2() [Fact] public void Test3() { - Assert.Equal(string.Join(",", new[] { " * ", " *** ", "*****" }), + Assert.Equal( + string.Join(",", new[] { " * ", " *** ", "*****" }), string.Join(",", Towerbuild.TowerBuilder(3))); } } \ No newline at end of file diff --git a/CourseApp.Tests/CourseApp.Tests.csproj b/CourseApp.Tests/CourseApp.Tests.csproj index e43252f..fd9ce61 100644 --- a/CourseApp.Tests/CourseApp.Tests.csproj +++ b/CourseApp.Tests/CourseApp.Tests.csproj @@ -29,4 +29,5 @@ + diff --git a/CourseApp.Tests/GlobalUsings.cs b/CourseApp.Tests/GlobalUsings.cs index 8c927eb..69cdbf8 100644 --- a/CourseApp.Tests/GlobalUsings.cs +++ b/CourseApp.Tests/GlobalUsings.cs @@ -1 +1,3 @@ -global using Xunit; \ No newline at end of file +#pragma warning disable SA1200 +global using Xunit; +#pragma warning restore SA1200 diff --git a/CourseApp/DigitalRootClass.cs b/CourseApp/CodeWars/DigitalRootClass.cs similarity index 100% rename from CourseApp/DigitalRootClass.cs rename to CourseApp/CodeWars/DigitalRootClass.cs diff --git a/CourseApp/DuplicatesEncoder.cs b/CourseApp/CodeWars/DuplicatesEncoder.cs similarity index 75% rename from CourseApp/DuplicatesEncoder.cs rename to CourseApp/CodeWars/DuplicatesEncoder.cs index 4e9d912..e0ffd80 100644 --- a/CourseApp/DuplicatesEncoder.cs +++ b/CourseApp/CodeWars/DuplicatesEncoder.cs @@ -1,5 +1,8 @@ namespace CodWearsTests; +using System.Linq; +using System.Collections.Generic; + public class DuplicatesEncoder { public static string DuplicateEncode(string word) @@ -11,6 +14,6 @@ public static string DuplicateEncode(string word) mass.Add(word.Count(x => x == sym) != 1 ? ")" : "("); } - return string.Join("", mass); + return string.Join(string.Empty, mass); } } \ No newline at end of file diff --git a/CourseApp/FibNums.cs b/CourseApp/CodeWars/FibNums.cs similarity index 97% rename from CourseApp/FibNums.cs rename to CourseApp/CodeWars/FibNums.cs index c134937..63c7ea9 100644 --- a/CourseApp/FibNums.cs +++ b/CourseApp/CodeWars/FibNums.cs @@ -16,5 +16,4 @@ public static ulong[] ProductFib(ulong prod) return new ulong[] { a, b, (ulong)(a * b == prod ? 1 : 0) }; } - } \ No newline at end of file diff --git a/CourseApp/Merge.cs b/CourseApp/CodeWars/Merge.cs similarity index 95% rename from CourseApp/Merge.cs rename to CourseApp/CodeWars/Merge.cs index 08b3e7c..0a5973e 100644 --- a/CourseApp/Merge.cs +++ b/CourseApp/CodeWars/Merge.cs @@ -1,5 +1,7 @@ namespace CodWearsTests; +using System.Collections.Generic; + public class Merge { public static string[] MergeArrays(string[] arr1, string[] arr2) diff --git a/CourseApp/MissingLetter.cs b/CourseApp/CodeWars/MissingLetter.cs similarity index 100% rename from CourseApp/MissingLetter.cs rename to CourseApp/CodeWars/MissingLetter.cs diff --git a/CourseApp/StrToCamelCase.cs b/CourseApp/CodeWars/StrToCamelCase.cs similarity index 100% rename from CourseApp/StrToCamelCase.cs rename to CourseApp/CodeWars/StrToCamelCase.cs diff --git a/CourseApp/TicTakToe.cs b/CourseApp/CodeWars/TicTakToe.cs similarity index 98% rename from CourseApp/TicTakToe.cs rename to CourseApp/CodeWars/TicTakToe.cs index 98d47bf..81f398c 100644 --- a/CourseApp/TicTakToe.cs +++ b/CourseApp/CodeWars/TicTakToe.cs @@ -4,7 +4,6 @@ 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) @@ -15,7 +14,6 @@ public int IsSolved(int[,] board) { 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)) { @@ -33,7 +31,6 @@ public int IsSolved(int[,] board) } } - return 0; } } \ No newline at end of file diff --git a/CourseApp/Towerbuild.cs b/CourseApp/CodeWars/Towerbuild.cs similarity index 80% rename from CourseApp/Towerbuild.cs rename to CourseApp/CodeWars/Towerbuild.cs index 410feff..3818ac4 100644 --- a/CourseApp/Towerbuild.cs +++ b/CourseApp/CodeWars/Towerbuild.cs @@ -1,5 +1,7 @@ namespace CodWearsTests; +using System.Collections.Generic; + public class Towerbuild { public static string[] TowerBuilder(int nFloors) @@ -9,7 +11,7 @@ public static string[] TowerBuilder(int nFloors) for (int i = 0; i < nFloors; i++) { var padding = new string(' ', nFloors - i - 1); - var sharps = new string('*', i * 2 + 1); + var sharps = new string('*', (i * 2) + 1); tower.Add($"{padding}{sharps}{padding}"); } diff --git a/CourseApp/Zeroes.cs b/CourseApp/CodeWars/Zeroes.cs similarity index 87% rename from CourseApp/Zeroes.cs rename to CourseApp/CodeWars/Zeroes.cs index 1ca5731..b55bb08 100644 --- a/CourseApp/Zeroes.cs +++ b/CourseApp/CodeWars/Zeroes.cs @@ -1,5 +1,7 @@ namespace CodWearsTests; +using System.Linq; + public class Zeroes { public static int[] MoveZeroes(int[] array) => array.OrderBy(x => x == 0).ToArray(); diff --git a/CourseApp/CourseApp.csproj b/CourseApp/CourseApp.csproj index eb22147..1702179 100644 --- a/CourseApp/CourseApp.csproj +++ b/CourseApp/CourseApp.csproj @@ -19,4 +19,6 @@ + + diff --git a/CourseApp/DogClass/Dog.cs b/CourseApp/DogClass/Dog.cs new file mode 100644 index 0000000..c2e9e78 --- /dev/null +++ b/CourseApp/DogClass/Dog.cs @@ -0,0 +1,34 @@ +namespace DefaultNamespace; + +public class Dog +{ + private int _age; + + private string _name; + + public string Name + { + get + { + return _name; + } + + set + { + _name = value; + } + } + + public int Age + { + get + { + return _age; + } + + set + { + _age = value; + } + } +} \ No newline at end of file diff --git a/CourseApp/Phone.cs b/CourseApp/Phone.cs deleted file mode 100644 index 1c8e407..0000000 --- a/CourseApp/Phone.cs +++ /dev/null @@ -1,38 +0,0 @@ -namespace CourseApp -{ - using System; - - public class Phone - { - private float diaonal; - - public Phone(string name, float diagonal) - { - Name = name; - Diagonal = diagonal; - } - - public string Name { get; set; } - - public float Diagonal - { - get - { - return diaonal; - } - - set - { - if (value > 0 && value < 20) - { - this.diaonal = value; - } - } - } - - public void Show() - { - Console.WriteLine($"{Name} with diagonal {diaonal}"); - } - } -} \ No newline at end of file diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index 030f047..96510c4 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -1,26 +1,15 @@ -namespace CourseApp -{ - using System; +namespace CourseApp; + +using DefaultNamespace; public class Program { public static void Main(string[] args) { - Phone phone1 = new Phone("iPhone", -7); - phone1.Show(); - phone1.Diagonal = 7; - phone1.Show(); - phone1.Diagonal = -16; - phone1.Show(); + var dog = new Dog(); + dog.Age = 15; + System.Console.WriteLine(dog.Age); - Phone tablet = new Phone("Android", 6); - tablet.Diagonal = 6; - tablet.Show(); - tablet.Diagonal = -10; - tablet.Show(); - tablet.Diagonal = 8; - tablet.Show(); - Console.WriteLine("Hello World"); + System.Console.WriteLine(dog); } } -} diff --git a/Dockerfile b/Dockerfile index b2a2650..ccf8562 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,4 +14,4 @@ RUN dotnet publish -c Release -o out FROM mcr.microsoft.com/dotnet/core/aspnet:5.0 WORKDIR /app COPY --from=build-env /app/out . -ENTRYPOINT ["dotnet", "CourseApp.dll"] \ No newline at end of file +ENTRYPOINT ["dotnet", "CourseApp.dll"]~ \ No newline at end of file From 4539a92a8ae044f059c068aa651fd1efabb46329 Mon Sep 17 00:00:00 2001 From: Fuflick Date: Wed, 11 Oct 2023 09:21:10 +0300 Subject: [PATCH 03/22] Fix dotnetcore.yml --- .github/workflows/dotnetcore.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index dffe441..872ebf0 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - dotnet: [ '2.1', '5.0.x', '6.0.x' ] + dotnet: [ '2.1' ] steps: - uses: actions/checkout@v2 From 32b8d992a1d7c17a50caf7a5162ffbf98320aad6 Mon Sep 17 00:00:00 2001 From: Fuflick Date: Wed, 11 Oct 2023 09:24:40 +0300 Subject: [PATCH 04/22] try to fix problem on gh --- .github/workflows/dotnetcore.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 872ebf0..2d5b201 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - dotnet: [ '2.1' ] + dotnet: [ '7.0.x' ] steps: - uses: actions/checkout@v2 From 40666ed6978ff011837829304166c9f96acecaaf Mon Sep 17 00:00:00 2001 From: Fuflick Date: Wed, 11 Oct 2023 09:33:40 +0300 Subject: [PATCH 05/22] fix checkout and setup-doynet to @v3 --- .github/workflows/dotnetcore.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 2d5b201..2505934 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -11,9 +11,9 @@ jobs: 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 From 6b97f7bedf037e87bc2715c83dbccbcce60e151b Mon Sep 17 00:00:00 2001 From: Fuflick Date: Tue, 24 Oct 2023 09:07:27 +0300 Subject: [PATCH 06/22] Try to fix conflict --- .github/workflows/dotnetcore.yml | 4 ++-- CourseApp/CourseApp.csproj | 1 + CourseApp/RpgSaga/IHero.cs | 18 ++++++++++++++++++ CourseApp/RpgSaga/Warior.cs | 15 +++++++++++++++ 4 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 CourseApp/RpgSaga/IHero.cs create mode 100644 CourseApp/RpgSaga/Warior.cs diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 2505934..21b7b2e 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - dotnet: [ '7.0.x' ] + dotnet: [ '6.0.x' ] steps: - uses: actions/checkout@v3 @@ -23,5 +23,5 @@ jobs: dotnet build --configuration Release - name: Run tests run: | - cd CourseApp.Tests + cd CourseApp.Tests/CourseApp.Tests.csproj dotnet test diff --git a/CourseApp/CourseApp.csproj b/CourseApp/CourseApp.csproj index 1702179..1ae6793 100644 --- a/CourseApp/CourseApp.csproj +++ b/CourseApp/CourseApp.csproj @@ -21,4 +21,5 @@ + diff --git a/CourseApp/RpgSaga/IHero.cs b/CourseApp/RpgSaga/IHero.cs new file mode 100644 index 0000000..918edb9 --- /dev/null +++ b/CourseApp/RpgSaga/IHero.cs @@ -0,0 +1,18 @@ +namespace CourseApp.RpgSaga; + +using System; + +public interface IHero +{ + public string Name; + + public int Strength; + + public int Health; + + public Random Rand = new Random(); + + public int SetValue(); + + public void Atack(IHero person); +} \ No newline at end of file diff --git a/CourseApp/RpgSaga/Warior.cs b/CourseApp/RpgSaga/Warior.cs new file mode 100644 index 0000000..22c32fd --- /dev/null +++ b/CourseApp/RpgSaga/Warior.cs @@ -0,0 +1,15 @@ +namespace CourseApp.RpgSaga; + +public class Warior : IHero +{ + public int SetValue() + { + throw new System.NotImplementedException(); + } + + public void Atack(IHero person) + { + } + + +} \ No newline at end of file From 0272fd88c35def13b6afa6340a1f61a7c68f46a9 Mon Sep 17 00:00:00 2001 From: Fuflick Date: Tue, 24 Oct 2023 09:08:53 +0300 Subject: [PATCH 07/22] Try to fix again --- CourseApp/RpgSaga/IHero.cs | 18 ------------------ CourseApp/RpgSaga/Warior.cs | 15 --------------- 2 files changed, 33 deletions(-) delete mode 100644 CourseApp/RpgSaga/IHero.cs delete mode 100644 CourseApp/RpgSaga/Warior.cs diff --git a/CourseApp/RpgSaga/IHero.cs b/CourseApp/RpgSaga/IHero.cs deleted file mode 100644 index 918edb9..0000000 --- a/CourseApp/RpgSaga/IHero.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace CourseApp.RpgSaga; - -using System; - -public interface IHero -{ - public string Name; - - public int Strength; - - public int Health; - - public Random Rand = new Random(); - - public int SetValue(); - - public void Atack(IHero person); -} \ No newline at end of file diff --git a/CourseApp/RpgSaga/Warior.cs b/CourseApp/RpgSaga/Warior.cs deleted file mode 100644 index 22c32fd..0000000 --- a/CourseApp/RpgSaga/Warior.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace CourseApp.RpgSaga; - -public class Warior : IHero -{ - public int SetValue() - { - throw new System.NotImplementedException(); - } - - public void Atack(IHero person) - { - } - - -} \ No newline at end of file From 434fcb47b97a23916b5e62944ad825366ac182c3 Mon Sep 17 00:00:00 2001 From: Fuflick Date: Tue, 24 Oct 2023 09:12:27 +0300 Subject: [PATCH 08/22] Try number 3 --- .github/workflows/dotnetcore.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 21b7b2e..d54a717 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -23,5 +23,5 @@ jobs: dotnet build --configuration Release - name: Run tests run: | - cd CourseApp.Tests/CourseApp.Tests.csproj + cd CourseApp.Tests dotnet test From 547f3f08652573f829c103f817d8ff1b0023861e Mon Sep 17 00:00:00 2001 From: Fuflick Date: Tue, 24 Oct 2023 09:14:06 +0300 Subject: [PATCH 09/22] =?UTF-8?q?Try=20=E2=84=964?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/dotnetcore.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index d54a717..88ded27 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -23,5 +23,5 @@ jobs: dotnet build --configuration Release - name: Run tests run: | - cd CourseApp.Tests + cd CourseApp.Tests/CodeWarsUnitTests dotnet test From bccc7355035725b96066ddc7d781dda22ae8058a Mon Sep 17 00:00:00 2001 From: Fuflick Date: Tue, 24 Oct 2023 09:27:00 +0300 Subject: [PATCH 10/22] Fix num 5 --- .github/workflows/dotnetcore.yml | 4 ++-- CourseApp.Tests/CourseApp.Tests.csproj | 2 +- CourseApp/CourseApp.csproj | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 88ded27..2505934 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - dotnet: [ '6.0.x' ] + dotnet: [ '7.0.x' ] steps: - uses: actions/checkout@v3 @@ -23,5 +23,5 @@ jobs: dotnet build --configuration Release - name: Run tests run: | - cd CourseApp.Tests/CodeWarsUnitTests + cd CourseApp.Tests dotnet test diff --git a/CourseApp.Tests/CourseApp.Tests.csproj b/CourseApp.Tests/CourseApp.Tests.csproj index fd9ce61..fd8366d 100644 --- a/CourseApp.Tests/CourseApp.Tests.csproj +++ b/CourseApp.Tests/CourseApp.Tests.csproj @@ -1,7 +1,7 @@  - net6.0 + net7.0 True false diff --git a/CourseApp/CourseApp.csproj b/CourseApp/CourseApp.csproj index 1ae6793..580345d 100644 --- a/CourseApp/CourseApp.csproj +++ b/CourseApp/CourseApp.csproj @@ -2,7 +2,7 @@ Exe - net6.0 + net7.0 True From b846f801874b7d6351b4044f96aecbb445aab31a Mon Sep 17 00:00:00 2001 From: Fuflick Date: Tue, 24 Oct 2023 09:30:13 +0300 Subject: [PATCH 11/22] Fix num 6 --- .github/workflows/dotnetcore.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 2505934..5177a07 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -24,4 +24,4 @@ jobs: - name: Run tests run: | cd CourseApp.Tests - dotnet test + dotnet test CodeWearsTests.csproj From 39e5b216a6d966ce5477036aeab6a4e650302833 Mon Sep 17 00:00:00 2001 From: Fuflick Date: Tue, 24 Oct 2023 09:33:10 +0300 Subject: [PATCH 12/22] Fix num 7 --- .github/workflows/dotnetcore.yml | 2 +- CourseApp.Tests/CodeWarsTests.UnitTest.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 5177a07..c5a357c 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -24,4 +24,4 @@ jobs: - name: Run tests run: | cd CourseApp.Tests - dotnet test CodeWearsTests.csproj + dotnet test diff --git a/CourseApp.Tests/CodeWarsTests.UnitTest.csproj b/CourseApp.Tests/CodeWarsTests.UnitTest.csproj index baf3035..b064bc8 100644 --- a/CourseApp.Tests/CodeWarsTests.UnitTest.csproj +++ b/CourseApp.Tests/CodeWarsTests.UnitTest.csproj @@ -23,7 +23,7 @@ - + From b7c156eeacff6ce4f361c2f6bd7ca2ebec66f0aa Mon Sep 17 00:00:00 2001 From: Fuflick Date: Tue, 24 Oct 2023 09:35:20 +0300 Subject: [PATCH 13/22] Try 8 --- .github/workflows/dotnetcore.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index c5a357c..31bf755 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -24,4 +24,4 @@ jobs: - name: Run tests run: | cd CourseApp.Tests - dotnet test + dotnet test CodeWarsTests.UnitTests.csproj From 1009acc157ea0b56f1e9b0e9e0aca7732e132474 Mon Sep 17 00:00:00 2001 From: Fuflick Date: Tue, 24 Oct 2023 09:36:56 +0300 Subject: [PATCH 14/22] Try 9 --- .github/workflows/dotnetcore.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 31bf755..8882245 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -24,4 +24,4 @@ jobs: - name: Run tests run: | cd CourseApp.Tests - dotnet test CodeWarsTests.UnitTests.csproj + dotnet test CourseApp.Tests.csproj From 7bbad36cb430ef5d12502ea6a8fed45c2a01adc3 Mon Sep 17 00:00:00 2001 From: Fuflick Date: Tue, 24 Oct 2023 12:58:40 +0300 Subject: [PATCH 15/22] Add func and List to the Dog class --- .github/workflows/dotnetcore.yml | 2 +- CourseApp/DogClass/Dog.cs | 38 ++++++++++++++++++++------------ CourseApp/Program.cs | 10 +++++++-- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 8882245..ba3625e 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -24,4 +24,4 @@ jobs: - name: Run tests run: | cd CourseApp.Tests - dotnet test CourseApp.Tests.csproj + dotnet test CourseAppTest.cs diff --git a/CourseApp/DogClass/Dog.cs b/CourseApp/DogClass/Dog.cs index c2e9e78..3c3f785 100644 --- a/CourseApp/DogClass/Dog.cs +++ b/CourseApp/DogClass/Dog.cs @@ -1,34 +1,44 @@ namespace DefaultNamespace; +using System; +using System.Collections.Generic; + public class Dog { private int _age; private string _name; + private List _flock; + public string Name { - get - { - return _name; - } + get => _name; - set - { - _name = value; - } + set => _name = value; } public int Age { - get - { - return _age; - } + get => _age; - set + set => _age = value; + } + + public List Flock + { + get => _flock; + + set => _flock = value; + } + + public void PrintInfo() + { + Console.WriteLine($"Dog name is {this._name}, {this._name}'s age is {this._age}."); + Console.WriteLine("Flock contains:"); + foreach (var friend in this._flock) { - _age = value; + Console.WriteLine($"{friend._name} {friend._age}"); } } } \ No newline at end of file diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index 96510c4..257f7fc 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -1,5 +1,7 @@ namespace CourseApp; +using System.Collections.Generic; + using DefaultNamespace; public class Program @@ -7,9 +9,13 @@ public class Program public static void Main(string[] args) { var dog = new Dog(); + dog.Name = "Sam"; dog.Age = 15; - System.Console.WriteLine(dog.Age); + dog.Flock = new List + { + new Dog() { Name = "Steve", Age = 4 }, + }; - System.Console.WriteLine(dog); + dog.PrintInfo(); } } From d517a4ae525ae2675274d81e682f438bd7f4c7c3 Mon Sep 17 00:00:00 2001 From: Fuflick Date: Tue, 24 Oct 2023 13:00:17 +0300 Subject: [PATCH 16/22] Fix workflows --- .github/workflows/dotnetcore.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index ba3625e..7b348a7 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -24,4 +24,4 @@ jobs: - name: Run tests run: | cd CourseApp.Tests - dotnet test CourseAppTest.cs + dotnet test CourseApp.Test.csproj From e2771915e9c049849d6ff60dcf57a6259d6a51ad Mon Sep 17 00:00:00 2001 From: Fuflick Date: Tue, 24 Oct 2023 13:02:22 +0300 Subject: [PATCH 17/22] add letter to the end of file dotnetcore.yml --- .github/workflows/dotnetcore.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 7b348a7..8882245 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -24,4 +24,4 @@ jobs: - name: Run tests run: | cd CourseApp.Tests - dotnet test CourseApp.Test.csproj + dotnet test CourseApp.Tests.csproj From ef396b73361a9860078d0c5dec4a1f05153aa4b4 Mon Sep 17 00:00:00 2001 From: Fuflick Date: Wed, 8 Nov 2023 10:45:57 +0300 Subject: [PATCH 18/22] Rpg saga --- CourseApp/CourseApp.csproj | 1 + CourseApp/Program.cs | 20 ++++---- CourseApp/RpgSaga/Archer.cs | 29 ++++++++++++ CourseApp/RpgSaga/Hero.cs | 91 ++++++++++++++++++++++++++++++++++++ CourseApp/RpgSaga/Magican.cs | 31 ++++++++++++ CourseApp/RpgSaga/Warrior.cs | 31 ++++++++++++ 6 files changed, 195 insertions(+), 8 deletions(-) create mode 100644 CourseApp/RpgSaga/Archer.cs create mode 100644 CourseApp/RpgSaga/Hero.cs create mode 100644 CourseApp/RpgSaga/Magican.cs create mode 100644 CourseApp/RpgSaga/Warrior.cs diff --git a/CourseApp/CourseApp.csproj b/CourseApp/CourseApp.csproj index 580345d..46ff5a1 100644 --- a/CourseApp/CourseApp.csproj +++ b/CourseApp/CourseApp.csproj @@ -17,6 +17,7 @@ + diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index 257f7fc..9b8ebde 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -1,21 +1,25 @@ namespace CourseApp; +using System; using System.Collections.Generic; - -using DefaultNamespace; +using RpgSaga; public class Program { public static void Main(string[] args) { - var dog = new Dog(); - dog.Name = "Sam"; - dog.Age = 15; - dog.Flock = new List + var rnd = new Random(); + var list = new List() { - new Dog() { Name = "Steve", Age = 4 }, + new Archer(), + new Magican(), + new Warrior(), }; - dog.PrintInfo(); + Hero visor = new Magican(); + while (true) + { + visor.Fight(list[rnd.Next(0, 2)], list[rnd.Next(0, 2)]); + } } } diff --git a/CourseApp/RpgSaga/Archer.cs b/CourseApp/RpgSaga/Archer.cs new file mode 100644 index 0000000..36ebb91 --- /dev/null +++ b/CourseApp/RpgSaga/Archer.cs @@ -0,0 +1,29 @@ +namespace CourseApp.RpgSaga; + +using System; + +public class Archer : Hero +{ + public Archer() + : base() + { + Type = "Archer"; + } + + protected override Hero Attack(Hero enemy) + { + if (!SpellUsed) + { + Console.WriteLine($"{Type} {Name} use spell and attack {enemy.Type}, damage = {Damage + 2}"); + SpellUsed = true; + enemy.Health -= Damage; + } + else + { + enemy.Health -= Damage + 2; + Console.WriteLine($"{Type} {Name} attack {enemy.Type}, damage = {Damage + 2}"); + } + + return enemy; + } +} \ No newline at end of file diff --git a/CourseApp/RpgSaga/Hero.cs b/CourseApp/RpgSaga/Hero.cs new file mode 100644 index 0000000..11ced3f --- /dev/null +++ b/CourseApp/RpgSaga/Hero.cs @@ -0,0 +1,91 @@ +namespace CourseApp.RpgSaga; + +using System; +using System.Threading; + +public abstract class Hero +{ + private string[] names = new string[] + { + "Stan", + "Artur", + "Igor", + "Gerald", + "Samuel", + }; + + private Random _rand = new Random(); + + private string _name; + + private int _health; + + private int _damage; + + private bool _spellUsed; + + private string _type; + + public string Type + { + get => _type; + + set => _type = value; + } + + public bool SpellUsed + { + get => _spellUsed; + + set => _spellUsed = value; + } + + public string Name + { + get => _name; + + set => _name = value; + } + + public int Damage + { + get => _damage; + + set => _damage = value; + } + + public int Health + { + get => _health; + + set => _health = value; + } + +#pragma warning disable SA1201 + public Hero() +#pragma warning restore SA1201 + { + _name = names[_rand.Next(0, 4)]; + _health = _rand.Next(10, 100); + _damage = _rand.Next(5, 30); + _spellUsed = false; + } + + public void Fight(Hero person1, Hero person2) + { + while (true) + { + while (person1._health > 0 || person2._health > 0) + { + person2 = person1.Attack(person2); + Thread.Sleep(1000); + person1 = person2.Attack(person1); + Thread.Sleep(1000); + } + + Thread.Sleep(3000); + } + } + + protected abstract Hero Attack(Hero enemy); +} \ No newline at end of file diff --git a/CourseApp/RpgSaga/Magican.cs b/CourseApp/RpgSaga/Magican.cs new file mode 100644 index 0000000..8284c0f --- /dev/null +++ b/CourseApp/RpgSaga/Magican.cs @@ -0,0 +1,31 @@ +namespace CourseApp.RpgSaga; + +using System; + +public class Magican : Hero +{ + public Magican() + : base() + { + Type = "Magican"; + } + + protected override Hero Attack(Hero enemy) + { + if (!SpellUsed) + { + Console.WriteLine($"{Type} {Name} use spell and attack {enemy.Type}, damage = {Damage}."); + Console.WriteLine($"{enemy.Type} {enemy.Name} attack {Type}, but damage = 0"); + Console.WriteLine($"{Type} {Name} attack {enemy.Type}, damage = {Damage}"); + enemy.Health -= Convert.ToByte(Damage * 2); + SpellUsed = true; + } + else + { + enemy.Health -= Damage; + Console.WriteLine($"{Type} {Name} attack {enemy.Type}, damage = {Damage}"); + } + + return enemy; + } +} \ No newline at end of file diff --git a/CourseApp/RpgSaga/Warrior.cs b/CourseApp/RpgSaga/Warrior.cs new file mode 100644 index 0000000..72dab3d --- /dev/null +++ b/CourseApp/RpgSaga/Warrior.cs @@ -0,0 +1,31 @@ +namespace CourseApp.RpgSaga; + +using System; + +public class Warrior : Hero +{ + public Warrior() + : base() + { + Type = "Warrior"; + } + + public byte UseSpell() => (byte)Math.Round(Damage * 1.3); + + protected override Hero Attack(Hero enemy) + { + if (!SpellUsed) + { + enemy.Health -= UseSpell(); + Console.WriteLine($"{Type} {Name} use spell and attack {enemy.Type}, damage = {Damage}, {enemy.Type} health = {enemy.Health - Damage}"); + SpellUsed = true; + } + else + { + enemy.Health -= Damage; + Console.WriteLine($"{Type} {Name} attack {enemy.Type}, damage = {Damage}, {enemy.Type} health = {enemy.Health - Damage}"); + } + + return enemy; + } +} \ No newline at end of file From 0fcb999e51c96c7a784a8bea6712b6642a929c24 Mon Sep 17 00:00:00 2001 From: Fuflick Date: Sat, 25 Nov 2023 21:00:09 +0300 Subject: [PATCH 19/22] Fix pragma's exception with global using in CourseApp.Tests/CodeWarsUnitTests/* --- CourseApp.Tests/CodeWarsUnitTests/CamalCaseTest.cs | 1 + CourseApp.Tests/CodeWarsUnitTests/DuplicatesEncoderTest.cs | 1 + CourseApp.Tests/CodeWarsUnitTests/FindMissingLetter.Test.cs | 1 + CourseApp.Tests/CodeWarsUnitTests/Merge.Tests.cs | 1 + CourseApp.Tests/CodeWarsUnitTests/TowerTest.cs | 1 + CourseApp.Tests/GlobalUsings.cs | 3 --- 6 files changed, 5 insertions(+), 3 deletions(-) delete mode 100644 CourseApp.Tests/GlobalUsings.cs diff --git a/CourseApp.Tests/CodeWarsUnitTests/CamalCaseTest.cs b/CourseApp.Tests/CodeWarsUnitTests/CamalCaseTest.cs index df54908..c482151 100644 --- a/CourseApp.Tests/CodeWarsUnitTests/CamalCaseTest.cs +++ b/CourseApp.Tests/CodeWarsUnitTests/CamalCaseTest.cs @@ -1,6 +1,7 @@ namespace CodeWarsTests.UnitTest; using CodWearsTests; +using Xunit; public class CamalCaseTest { diff --git a/CourseApp.Tests/CodeWarsUnitTests/DuplicatesEncoderTest.cs b/CourseApp.Tests/CodeWarsUnitTests/DuplicatesEncoderTest.cs index 0266319..e9e2925 100644 --- a/CourseApp.Tests/CodeWarsUnitTests/DuplicatesEncoderTest.cs +++ b/CourseApp.Tests/CodeWarsUnitTests/DuplicatesEncoderTest.cs @@ -1,6 +1,7 @@ namespace CodeWarsTests.UnitTest; using CodWearsTests; +using Xunit; public class DuplicatesEncoderTest { diff --git a/CourseApp.Tests/CodeWarsUnitTests/FindMissingLetter.Test.cs b/CourseApp.Tests/CodeWarsUnitTests/FindMissingLetter.Test.cs index a1863a3..51f9a61 100644 --- a/CourseApp.Tests/CodeWarsUnitTests/FindMissingLetter.Test.cs +++ b/CourseApp.Tests/CodeWarsUnitTests/FindMissingLetter.Test.cs @@ -1,6 +1,7 @@ namespace CodeWarsTests.UnitTest; using CodWearsTests; +using Xunit; public class FindMissingLetter_Test { diff --git a/CourseApp.Tests/CodeWarsUnitTests/Merge.Tests.cs b/CourseApp.Tests/CodeWarsUnitTests/Merge.Tests.cs index 3406d43..0dc4829 100644 --- a/CourseApp.Tests/CodeWarsUnitTests/Merge.Tests.cs +++ b/CourseApp.Tests/CodeWarsUnitTests/Merge.Tests.cs @@ -1,6 +1,7 @@ namespace CodeWarsTests.UnitTest; using CodWearsTests; +using Xunit; public class Merge_Tests { diff --git a/CourseApp.Tests/CodeWarsUnitTests/TowerTest.cs b/CourseApp.Tests/CodeWarsUnitTests/TowerTest.cs index 6dc681d..e1500c3 100644 --- a/CourseApp.Tests/CodeWarsUnitTests/TowerTest.cs +++ b/CourseApp.Tests/CodeWarsUnitTests/TowerTest.cs @@ -1,6 +1,7 @@ namespace CodeWarsTests.UnitTest; using CodWearsTests; +using Xunit; public class TowerTest { diff --git a/CourseApp.Tests/GlobalUsings.cs b/CourseApp.Tests/GlobalUsings.cs deleted file mode 100644 index 69cdbf8..0000000 --- a/CourseApp.Tests/GlobalUsings.cs +++ /dev/null @@ -1,3 +0,0 @@ -#pragma warning disable SA1200 -global using Xunit; -#pragma warning restore SA1200 From ba45d722cd84d937fc797678c25288433fe7793f Mon Sep 17 00:00:00 2001 From: Fuflick Date: Sat, 25 Nov 2023 21:18:17 +0300 Subject: [PATCH 20/22] make Dog's age property uint --- CourseApp/DogClass/Dog.cs | 4 ++-- CourseApp/Program.cs | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CourseApp/DogClass/Dog.cs b/CourseApp/DogClass/Dog.cs index 3c3f785..35ea345 100644 --- a/CourseApp/DogClass/Dog.cs +++ b/CourseApp/DogClass/Dog.cs @@ -5,7 +5,7 @@ namespace DefaultNamespace; public class Dog { - private int _age; + private uint _age; private string _name; @@ -18,7 +18,7 @@ public string Name set => _name = value; } - public int Age + public uint Age { get => _age; diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index 9b8ebde..0369358 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -3,12 +3,13 @@ using System; using System.Collections.Generic; using RpgSaga; +using DefaultNamespace; public class Program { public static void Main(string[] args) { - var rnd = new Random(); + /*var rnd = new Random(); var list = new List() { new Archer(), @@ -20,6 +21,6 @@ public static void Main(string[] args) while (true) { visor.Fight(list[rnd.Next(0, 2)], list[rnd.Next(0, 2)]); - } + }*/ } } From 7cdb82123b5cef62806beadd7d2596fe0ea9170a Mon Sep 17 00:00:00 2001 From: Fuflick Date: Sat, 25 Nov 2023 21:21:28 +0300 Subject: [PATCH 21/22] delete '~' from Dockerfile (I don't know, how his got here.) --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index ccf8562..b2a2650 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,4 +14,4 @@ RUN dotnet publish -c Release -o out FROM mcr.microsoft.com/dotnet/core/aspnet:5.0 WORKDIR /app COPY --from=build-env /app/out . -ENTRYPOINT ["dotnet", "CourseApp.dll"]~ \ No newline at end of file +ENTRYPOINT ["dotnet", "CourseApp.dll"] \ No newline at end of file From 506310b3b74287d9e50038c6ff79a1d66fffe9b4 Mon Sep 17 00:00:00 2001 From: Fuflick Date: Sat, 25 Nov 2023 23:06:58 +0300 Subject: [PATCH 22/22] Some changes in RpgSaga --- CourseApp/DogClass/Dog.cs | 3 +-- CourseApp/Program.cs | 29 +++++++++++++++++------------ CourseApp/RpgSaga/Archer.cs | 4 ++-- CourseApp/RpgSaga/Hero.cs | 17 +++++++---------- CourseApp/RpgSaga/Magican.cs | 8 ++++---- CourseApp/RpgSaga/Warrior.cs | 6 +++--- 6 files changed, 34 insertions(+), 33 deletions(-) diff --git a/CourseApp/DogClass/Dog.cs b/CourseApp/DogClass/Dog.cs index 35ea345..c6c4813 100644 --- a/CourseApp/DogClass/Dog.cs +++ b/CourseApp/DogClass/Dog.cs @@ -1,8 +1,7 @@ -namespace DefaultNamespace; +namespace CourseApp.DogClass; using System; using System.Collections.Generic; - public class Dog { private uint _age; diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index 0369358..c88a02e 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -3,24 +3,29 @@ using System; using System.Collections.Generic; using RpgSaga; -using DefaultNamespace; - public class Program +public class Program { public static void Main(string[] args) { - /*var rnd = new Random(); - var list = new List() - { - new Archer(), - new Magican(), - new Warrior(), - }; + var rnd = new Random(); Hero visor = new Magican(); - while (true) + for (int i = 0; i < 1000; i++) { - visor.Fight(list[rnd.Next(0, 2)], list[rnd.Next(0, 2)]); - }*/ + var list = new List() + { + new Archer(), + new Magican(), + new Warrior(), + }; + var hero1 = list[rnd.Next(0, 3)]; + var hero2 = list[rnd.Next(0, 3)]; + if (hero1 != hero2) + { + visor.Fight(hero1, hero2); + Console.WriteLine("Fight finish \n\n"); + } + } } } diff --git a/CourseApp/RpgSaga/Archer.cs b/CourseApp/RpgSaga/Archer.cs index 36ebb91..9b914cf 100644 --- a/CourseApp/RpgSaga/Archer.cs +++ b/CourseApp/RpgSaga/Archer.cs @@ -14,14 +14,14 @@ protected override Hero Attack(Hero enemy) { if (!SpellUsed) { - Console.WriteLine($"{Type} {Name} use spell and attack {enemy.Type}, damage = {Damage + 2}"); + Console.WriteLine($"{Type} {Name} use spell and attack {enemy.Type} {enemy.Name}, damage = {Damage + 2}, {enemy.Type} {enemy.Name} health = {enemy.Health - Damage}"); SpellUsed = true; enemy.Health -= Damage; } else { enemy.Health -= Damage + 2; - Console.WriteLine($"{Type} {Name} attack {enemy.Type}, damage = {Damage + 2}"); + Console.WriteLine($"{this.Type} {this.Name} attack {enemy.Type} {enemy.Name}, damage = {Damage + 2}, {enemy.Type} {enemy.Name} health = {enemy.Health - Damage}"); } return enemy; diff --git a/CourseApp/RpgSaga/Hero.cs b/CourseApp/RpgSaga/Hero.cs index 11ced3f..5ffad7c 100644 --- a/CourseApp/RpgSaga/Hero.cs +++ b/CourseApp/RpgSaga/Hero.cs @@ -73,18 +73,15 @@ public Hero() public void Fight(Hero person1, Hero person2) { - while (true) + if ((person1._health > 0) || (person2._health > 0)) { - while (person1._health > 0 || person2._health > 0) - { - person2 = person1.Attack(person2); - Thread.Sleep(1000); - person1 = person2.Attack(person1); - Thread.Sleep(1000); - } - - Thread.Sleep(3000); + person2 = person1.Attack(person2); + Thread.Sleep(1000); + person1 = person2.Attack(person1); + Thread.Sleep(1000); } + + Thread.Sleep(3000); } protected abstract Hero Attack(Hero enemy); diff --git a/CourseApp/RpgSaga/Magican.cs b/CourseApp/RpgSaga/Magican.cs index 8284c0f..74b1ff5 100644 --- a/CourseApp/RpgSaga/Magican.cs +++ b/CourseApp/RpgSaga/Magican.cs @@ -14,16 +14,16 @@ protected override Hero Attack(Hero enemy) { if (!SpellUsed) { - Console.WriteLine($"{Type} {Name} use spell and attack {enemy.Type}, damage = {Damage}."); + Console.WriteLine($"{this.Type} {this.Name} use spell and attack {enemy.Type} {enemy.Name}, damage = {this.Damage}, {enemy.Type} {enemy.Name} health = {enemy.Health - Damage}."); Console.WriteLine($"{enemy.Type} {enemy.Name} attack {Type}, but damage = 0"); - Console.WriteLine($"{Type} {Name} attack {enemy.Type}, damage = {Damage}"); + Console.WriteLine($"{this.Type} {this.Name} attack {enemy.Type} {enemy.Name}, damage = {this.Damage}, {enemy.Type} {enemy.Name} health = {enemy.Health - Damage}"); enemy.Health -= Convert.ToByte(Damage * 2); SpellUsed = true; } else { - enemy.Health -= Damage; - Console.WriteLine($"{Type} {Name} attack {enemy.Type}, damage = {Damage}"); + enemy.Health -= this.Damage; + Console.WriteLine($"{this.Type} {this.Name} attack {enemy.Type} {enemy.Name}, damage = {this.Damage}, {enemy.Type} {enemy.Name} health = {enemy.Health - Damage}"); } return enemy; diff --git a/CourseApp/RpgSaga/Warrior.cs b/CourseApp/RpgSaga/Warrior.cs index 72dab3d..f28783d 100644 --- a/CourseApp/RpgSaga/Warrior.cs +++ b/CourseApp/RpgSaga/Warrior.cs @@ -16,14 +16,14 @@ protected override Hero Attack(Hero enemy) { if (!SpellUsed) { + Console.WriteLine($"{this.Type} {this.Name} use spell and attack {enemy.Type}, damage = {this.Damage}, {enemy.Type} {enemy.Name} health = {enemy.Health - UseSpell()}"); enemy.Health -= UseSpell(); - Console.WriteLine($"{Type} {Name} use spell and attack {enemy.Type}, damage = {Damage}, {enemy.Type} health = {enemy.Health - Damage}"); SpellUsed = true; } else { - enemy.Health -= Damage; - Console.WriteLine($"{Type} {Name} attack {enemy.Type}, damage = {Damage}, {enemy.Type} health = {enemy.Health - Damage}"); + enemy.Health -= this.Damage; + Console.WriteLine($"{this.Type} {this.Name} attack {enemy.Type}, damage = {this.Damage}, {enemy.Type} {enemy.Name} health = {enemy.Health - Damage}"); } return enemy;