From 69294b221de2c039e9a88952004e25ea79f3a3d1 Mon Sep 17 00:00:00 2001
From: tacosontitan <65432314+tacosontitan@users.noreply.github.com>
Date: Sat, 3 Feb 2024 12:02:01 -0600
Subject: [PATCH] Opted for C# naming conventions.
---
Hussy.Net.sln | 9 ++++
samples/Hussy.Net.FizzBuzz/Program.cs | 10 ++--
samples/Hussy.Net.HelloWorld/Program.cs | 10 ++--
samples/Hussy.Net.Logic/Program.cs | 16 +++---
samples/Hussy.Net.Output/Program.cs | 4 +-
src/Hussy.Net/Generators/Range.cs | 6 +--
src/Hussy.Net/Hussy.Net.csproj.DotSettings | 1 +
src/Hussy.Net/Iterators/Repeat.cs | 29 +++++++++++
src/Hussy.Net/Logic/Even.cs | 2 +-
src/Hussy.Net/Logic/Modulus.cs | 2 +-
src/Hussy.Net/Logic/Odd.cs | 2 +-
src/Hussy.Net/Modules/FizzBuzz.cs | 6 +--
src/Hussy.Net/Output/WriteHeader.cs | 2 +-
src/Hussy.Net/Output/WriteSeparator.cs | 2 +-
test/Hussy.Net.Tests/Generators/RangeTests.cs | 50 +++++++++++++++++++
test/Hussy.Net.Tests/GlobalUsings.cs | 17 +++++++
test/Hussy.Net.Tests/Hussy.Net.Tests.csproj | 21 ++++++++
test/Hussy.Net.Tests/Linq/FilterTests.cs | 12 +++++
18 files changed, 170 insertions(+), 31 deletions(-)
create mode 100644 src/Hussy.Net/Iterators/Repeat.cs
create mode 100644 test/Hussy.Net.Tests/Generators/RangeTests.cs
create mode 100644 test/Hussy.Net.Tests/GlobalUsings.cs
create mode 100644 test/Hussy.Net.Tests/Hussy.Net.Tests.csproj
create mode 100644 test/Hussy.Net.Tests/Linq/FilterTests.cs
diff --git a/Hussy.Net.sln b/Hussy.Net.sln
index 9bd5c76..12c2696 100644
--- a/Hussy.Net.sln
+++ b/Hussy.Net.sln
@@ -16,6 +16,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hussy.Net.FizzBuzz", "sampl
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hussy.Net.Output", "samples\Hussy.Net.Output\Hussy.Net.Output.csproj", "{8F248FF3-378D-4F9C-8A25-3ED95961A4AB}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hussy.Net.Tests", "test\Hussy.Net.Tests\Hussy.Net.Tests.csproj", "{B5087B86-C43C-43F3-B0A2-D23B0480F203}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{A9FCA40E-6E3D-408C-B5A0-429AA5F5BF6F}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -46,6 +50,10 @@ Global
{8F248FF3-378D-4F9C-8A25-3ED95961A4AB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8F248FF3-378D-4F9C-8A25-3ED95961A4AB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8F248FF3-378D-4F9C-8A25-3ED95961A4AB}.Release|Any CPU.Build.0 = Release|Any CPU
+ {B5087B86-C43C-43F3-B0A2-D23B0480F203}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {B5087B86-C43C-43F3-B0A2-D23B0480F203}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {B5087B86-C43C-43F3-B0A2-D23B0480F203}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {B5087B86-C43C-43F3-B0A2-D23B0480F203}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{14788585-4CAA-415C-8B29-B4E2BBDC9C66} = {B43C73D9-7CA0-4D59-8ABE-AFD9A3F54361}
@@ -54,5 +62,6 @@ Global
{F04046C8-5B51-46C2-8603-27E402981AF0} = {C08B73E3-E9BB-44DE-AE74-647A442780D9}
{B62492A5-ABE3-46EF-BE5F-D85A871857BD} = {C08B73E3-E9BB-44DE-AE74-647A442780D9}
{8F248FF3-378D-4F9C-8A25-3ED95961A4AB} = {C08B73E3-E9BB-44DE-AE74-647A442780D9}
+ {B5087B86-C43C-43F3-B0A2-D23B0480F203} = {A9FCA40E-6E3D-408C-B5A0-429AA5F5BF6F}
EndGlobalSection
EndGlobal
diff --git a/samples/Hussy.Net.FizzBuzz/Program.cs b/samples/Hussy.Net.FizzBuzz/Program.cs
index 81b7364..dad7d2c 100644
--- a/samples/Hussy.Net.FizzBuzz/Program.cs
+++ b/samples/Hussy.Net.FizzBuzz/Program.cs
@@ -18,10 +18,10 @@ limitations under the License.
// that by default prints a specified number
// of values starting from 1:
W("Default");
-WS();
-FZ(count: 20);
+Ws();
+Fz(count: 20);
// You can specify a custom starting point:
-WH("Default (starting at 5)");
-WS();
-FZ(start: 5, count: 20);
\ No newline at end of file
+Wh("Default (starting at 5)");
+Ws();
+Fz(start: 5, count: 20);
\ No newline at end of file
diff --git a/samples/Hussy.Net.HelloWorld/Program.cs b/samples/Hussy.Net.HelloWorld/Program.cs
index 2c09463..ce798ce 100644
--- a/samples/Hussy.Net.HelloWorld/Program.cs
+++ b/samples/Hussy.Net.HelloWorld/Program.cs
@@ -17,17 +17,17 @@ limitations under the License.
// Hussy has a built-in hello world module.
// It's default output is "Hello, world!".
W("Default");
-WS();
+Ws();
Yo();
// If you need a common variation of the output,
// then you can specify a variant ID to change it.
-WH("Default (variant)");
-WS();
+Wh("Default (variant)");
+Ws();
Yo(1);
// If a predefined variant doesn't exist,
// then you can always write it from scratch:
-WH("Custom");
-WS();
+Wh("Custom");
+Ws();
W("...hello...world...");
\ No newline at end of file
diff --git a/samples/Hussy.Net.Logic/Program.cs b/samples/Hussy.Net.Logic/Program.cs
index 85b0ad8..a49c999 100644
--- a/samples/Hussy.Net.Logic/Program.cs
+++ b/samples/Hussy.Net.Logic/Program.cs
@@ -18,21 +18,21 @@ limitations under the License.
// The function EV takes in a numeric value
// and determines if it is even or not.
W("Even");
-WS();
-R(10).F(EV).E(W);
+Ws();
+Gr(10).F(Ev).E(W);
// Print all odd numbers from 1 to 10.
// The function OD takes in a numeric value
// and determines if it is odd or not.
-WH("Odd");
-WS();
-R(10).F(OD).E(W);
+Wh("Odd");
+Ws();
+Gr(10).F(Od).E(W);
// Print all numbers between 1 and 100
// that are divisible by 3 and 5.
// The function MD extends numeric types
// determining if the instance value
// is divisible by all the specified operands.
-WH("Modulus");
-WS();
-R(100).F(x => x.MD(3, 5)).E(W);
\ No newline at end of file
+Wh("Modulus");
+Ws();
+Gr(100).F(x => x.Md(3, 5)).E(W);
\ No newline at end of file
diff --git a/samples/Hussy.Net.Output/Program.cs b/samples/Hussy.Net.Output/Program.cs
index 0ce2b7b..7b05eb9 100644
--- a/samples/Hussy.Net.Output/Program.cs
+++ b/samples/Hussy.Net.Output/Program.cs
@@ -25,7 +25,7 @@ limitations under the License.
// parameters. The default character
// is '=' and the default length is
// 25.
-WS(character: '_', length: 30);
+Ws(character: '_', length: 30);
// You can simply append to the stream
// using the A function:
@@ -36,4 +36,4 @@ limitations under the License.
// visible chunks, then the WH method
// can facilitate writing a line preceded
// by two new lines.
-WH("Sample Header");
\ No newline at end of file
+Wh("Sample Header");
\ No newline at end of file
diff --git a/src/Hussy.Net/Generators/Range.cs b/src/Hussy.Net/Generators/Range.cs
index c6369da..42a58ed 100644
--- a/src/Hussy.Net/Generators/Range.cs
+++ b/src/Hussy.Net/Generators/Range.cs
@@ -26,7 +26,7 @@ public static partial class Hussy
///
/// The maximum value to include in the range.
/// A range of values starting with 1 through the specified value.
- public static IEnumerable R(int count) =>
+ public static IEnumerable Gr(int count) =>
Enumerable.Range(1, count);
///
@@ -35,7 +35,7 @@ public static IEnumerable R(int count) =>
/// The starting value for the range.
/// The maximum value to include in the range.
/// A range of values starting with through the specified value.
- public static IEnumerable R(int start, int count) =>
+ public static IEnumerable Gr(int start, int count) =>
Enumerable.Range(start, count);
///
@@ -45,7 +45,7 @@ public static IEnumerable R(int start, int count) =>
/// The maximum value to include in the range.
/// The step value to use when generating the range.
/// A range of values starting with through the specified value.
- public static IEnumerable R(int start, int count, int stepSize)
+ public static IEnumerable Gr(int start, int count, int stepSize)
{
List range = new(capacity: count);
for (int i = 0; i < count; i++)
diff --git a/src/Hussy.Net/Hussy.Net.csproj.DotSettings b/src/Hussy.Net/Hussy.Net.csproj.DotSettings
index b6b54f6..56c265d 100644
--- a/src/Hussy.Net/Hussy.Net.csproj.DotSettings
+++ b/src/Hussy.Net/Hussy.Net.csproj.DotSettings
@@ -2,6 +2,7 @@
True
True
True
+ True
True
True
True
diff --git a/src/Hussy.Net/Iterators/Repeat.cs b/src/Hussy.Net/Iterators/Repeat.cs
new file mode 100644
index 0000000..2167782
--- /dev/null
+++ b/src/Hussy.Net/Iterators/Repeat.cs
@@ -0,0 +1,29 @@
+/*
+ Copyright 2024 tacosontitan and contributors
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+namespace Hussy.Net;
+
+///
+/// Defines static methods for common programming tasks.
+///
+public static partial class Hussy
+{
+ public static void R(Action action, T input, Func breakCondition)
+ {
+ while (breakCondition?.Invoke(input) is not false)
+ action(input);
+ }
+}
\ No newline at end of file
diff --git a/src/Hussy.Net/Logic/Even.cs b/src/Hussy.Net/Logic/Even.cs
index 43eb74c..472c9b6 100644
--- a/src/Hussy.Net/Logic/Even.cs
+++ b/src/Hussy.Net/Logic/Even.cs
@@ -26,6 +26,6 @@ public static partial class Hussy
///
/// The number to check.
/// True if the number is even; otherwise, false.
- public static bool EV(int source) =>
+ public static bool Ev(int source) =>
source % 2 == 0;
}
\ No newline at end of file
diff --git a/src/Hussy.Net/Logic/Modulus.cs b/src/Hussy.Net/Logic/Modulus.cs
index 2be28aa..f795683 100644
--- a/src/Hussy.Net/Logic/Modulus.cs
+++ b/src/Hussy.Net/Logic/Modulus.cs
@@ -29,7 +29,7 @@ public static partial class Hussy
///
/// true if the value is divisible by all the operands; otherwise, false.
///
- public static bool MD(this int value, params int[] operands)
+ public static bool Md(this int value, params int[] operands)
{
foreach (int operand in operands)
if (value % operand != 0)
diff --git a/src/Hussy.Net/Logic/Odd.cs b/src/Hussy.Net/Logic/Odd.cs
index 6261d0a..9438770 100644
--- a/src/Hussy.Net/Logic/Odd.cs
+++ b/src/Hussy.Net/Logic/Odd.cs
@@ -26,6 +26,6 @@ public static partial class Hussy
///
/// The number to check.
/// True if the number is odd; otherwise, false.
- public static bool OD(int source) =>
+ public static bool Od(int source) =>
source % 2 == 1;
}
\ No newline at end of file
diff --git a/src/Hussy.Net/Modules/FizzBuzz.cs b/src/Hussy.Net/Modules/FizzBuzz.cs
index d706623..daaddef 100644
--- a/src/Hussy.Net/Modules/FizzBuzz.cs
+++ b/src/Hussy.Net/Modules/FizzBuzz.cs
@@ -26,15 +26,15 @@ public static partial class Hussy
/// multiples of 3, "Buzz" for multiples of 5, and the numeric value for any other value.
///
/// The number of values to print.
- public static void FZ(int count) =>
- FZ(start: 1, count);
+ public static void Fz(int count) =>
+ Fz(start: 1, count);
///
/// Creates a collection of a specified of numbers from a specified value and prints FizzBuzz for multiples of 3 and 5, Fizz for multiples of 3, Buzz for multiples of 5, and the numeric value for any other value.
///
/// The starting number.
/// The number of values to print.
- public static void FZ(int start, int count) => Enumerable.Range(start, count)
+ public static void Fz(int start, int count) => Enumerable.Range(start, count)
.ToList()
.ForEach(PrintFizzBuzz);
diff --git a/src/Hussy.Net/Output/WriteHeader.cs b/src/Hussy.Net/Output/WriteHeader.cs
index d2f4de3..f623e11 100644
--- a/src/Hussy.Net/Output/WriteHeader.cs
+++ b/src/Hussy.Net/Output/WriteHeader.cs
@@ -25,6 +25,6 @@ public static partial class Hussy
/// Writes the specified value to the console as a header (prefixed with two new lines).
///
/// The value to be written.
- public static void WH(T value) =>
+ public static void Wh(T value) =>
Console.WriteLine("\n\n{0}", value);
}
\ No newline at end of file
diff --git a/src/Hussy.Net/Output/WriteSeparator.cs b/src/Hussy.Net/Output/WriteSeparator.cs
index 4ecc63d..3c1a458 100644
--- a/src/Hussy.Net/Output/WriteSeparator.cs
+++ b/src/Hussy.Net/Output/WriteSeparator.cs
@@ -26,7 +26,7 @@ public static partial class Hussy
///
/// The character used for the separator line. Default is '='.
/// The length of the separator line. Default is 25.
- public static void WS(char character = '=', int length = 25)
+ public static void Ws(char character = '=', int length = 25)
{
var separator = new string(character, length);
Console.WriteLine(separator);
diff --git a/test/Hussy.Net.Tests/Generators/RangeTests.cs b/test/Hussy.Net.Tests/Generators/RangeTests.cs
new file mode 100644
index 0000000..718dcfb
--- /dev/null
+++ b/test/Hussy.Net.Tests/Generators/RangeTests.cs
@@ -0,0 +1,50 @@
+/*
+ Copyright 2024 tacosontitan and contributors
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+namespace Hussy.Net.Tests.Generators;
+
+public class RangeTests
+{
+ [Fact]
+ public void GR_SingleParam_Generates_Correct_Range()
+ {
+ var count = 5;
+ var result = Gr(count);
+ Assert.Equal(Enumerable.Range(1, count), result);
+ }
+
+ [Fact]
+ public void GR_TwoParams_Generates_Correct_Range()
+ {
+ var start = 5;
+ var count = 5;
+
+ var result = Gr(start, count);
+ Assert.Equal(Enumerable.Range(start, count), result);
+ }
+
+ [Fact]
+ public void GR_ThreeParams_Generates_Correct_Range()
+ {
+ var start = 5;
+ var count = 5;
+ var step = 2;
+
+ var result = Gr(start, count, step);
+
+ Assert.Equal(new int[] { 5, 7, 9, 11, 13 }, result);
+ }
+}
\ No newline at end of file
diff --git a/test/Hussy.Net.Tests/GlobalUsings.cs b/test/Hussy.Net.Tests/GlobalUsings.cs
new file mode 100644
index 0000000..043560c
--- /dev/null
+++ b/test/Hussy.Net.Tests/GlobalUsings.cs
@@ -0,0 +1,17 @@
+/*
+ Copyright 2024 tacosontitan and contributors
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+global using Xunit;
\ No newline at end of file
diff --git a/test/Hussy.Net.Tests/Hussy.Net.Tests.csproj b/test/Hussy.Net.Tests/Hussy.Net.Tests.csproj
new file mode 100644
index 0000000..b51886c
--- /dev/null
+++ b/test/Hussy.Net.Tests/Hussy.Net.Tests.csproj
@@ -0,0 +1,21 @@
+
+
+
+ false
+
+
+
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/test/Hussy.Net.Tests/Linq/FilterTests.cs b/test/Hussy.Net.Tests/Linq/FilterTests.cs
new file mode 100644
index 0000000..014f1f7
--- /dev/null
+++ b/test/Hussy.Net.Tests/Linq/FilterTests.cs
@@ -0,0 +1,12 @@
+using JetBrains.Annotations;
+using Xunit;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace Hussy.Net.Tests.Linq;
+
+[TestSubject(typeof(Hussy))]
+public class FilterTests
+{
+
+}
\ No newline at end of file