Skip to content

Commit

Permalink
Opted for C# naming conventions.
Browse files Browse the repository at this point in the history
  • Loading branch information
tacosontitan committed Feb 3, 2024
1 parent df295f6 commit 69294b2
Show file tree
Hide file tree
Showing 18 changed files with 170 additions and 31 deletions.
9 changes: 9 additions & 0 deletions Hussy.Net.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand All @@ -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
10 changes: 5 additions & 5 deletions samples/Hussy.Net.FizzBuzz/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Wh("Default (starting at 5)");
Ws();
Fz(start: 5, count: 20);
10 changes: 5 additions & 5 deletions samples/Hussy.Net.HelloWorld/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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...");
16 changes: 8 additions & 8 deletions samples/Hussy.Net.Logic/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Wh("Modulus");
Ws();
Gr(100).F(x => x.Md(3, 5)).E(W);
4 changes: 2 additions & 2 deletions samples/Hussy.Net.Output/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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");
Wh("Sample Header");
6 changes: 3 additions & 3 deletions src/Hussy.Net/Generators/Range.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static partial class Hussy
/// </summary>
/// <param name="count">The maximum value to include in the range.</param>
/// <returns>A range of values starting with <c>1</c> through the specified <paramref name="count"/> value.</returns>
public static IEnumerable<int> R(int count) =>
public static IEnumerable<int> Gr(int count) =>
Enumerable.Range(1, count);

/// <summary>
Expand All @@ -35,7 +35,7 @@ public static IEnumerable<int> R(int count) =>
/// <param name="start">The starting value for the range.</param>
/// <param name="count">The maximum value to include in the range.</param>
/// <returns>A range of values starting with <paramref name="start"/> through the specified <paramref name="count"/> value.</returns>
public static IEnumerable<int> R(int start, int count) =>
public static IEnumerable<int> Gr(int start, int count) =>
Enumerable.Range(start, count);

/// <summary>
Expand All @@ -45,7 +45,7 @@ public static IEnumerable<int> R(int start, int count) =>
/// <param name="count">The maximum value to include in the range.</param>
/// <param name="stepSize">The step value to use when generating the range.</param>
/// <returns>A range of values starting with <paramref name="start"/> through the specified <paramref name="count"/> value.</returns>
public static IEnumerable<int> R(int start, int count, int stepSize)
public static IEnumerable<int> Gr(int start, int count, int stepSize)
{
List<int> range = new(capacity: count);
for (int i = 0; i < count; i++)
Expand Down
1 change: 1 addition & 0 deletions src/Hussy.Net/Hussy.Net.csproj.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=collections/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=generators/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=input/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=iterators/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=linq/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=logic/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=modules/@EntryIndexedValue">True</s:Boolean>
Expand Down
29 changes: 29 additions & 0 deletions src/Hussy.Net/Iterators/Repeat.cs
Original file line number Diff line number Diff line change
@@ -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;

/// <summary>
/// Defines static methods for common programming tasks.
/// </summary>
public static partial class Hussy
{
public static void R<T>(Action<T> action, T input, Func<T, bool> breakCondition)
{
while (breakCondition?.Invoke(input) is not false)
action(input);
}
}
2 changes: 1 addition & 1 deletion src/Hussy.Net/Logic/Even.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ public static partial class Hussy
/// </summary>
/// <param name="source">The number to check.</param>
/// <returns>True if the number is even; otherwise, false.</returns>
public static bool EV(int source) =>
public static bool Ev(int source) =>
source % 2 == 0;
}
2 changes: 1 addition & 1 deletion src/Hussy.Net/Logic/Modulus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static partial class Hussy
/// <returns>
/// <c>true</c> if the value is divisible by all the operands; otherwise, <c>false</c>.
/// </returns>
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)
Expand Down
2 changes: 1 addition & 1 deletion src/Hussy.Net/Logic/Odd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ public static partial class Hussy
/// </summary>
/// <param name="source">The number to check.</param>
/// <returns>True if the number is odd; otherwise, false.</returns>
public static bool OD(int source) =>
public static bool Od(int source) =>
source % 2 == 1;
}
6 changes: 3 additions & 3 deletions src/Hussy.Net/Modules/FizzBuzz.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
/// </summary>
/// <param name="count">The number of values to print.</param>
public static void FZ(int count) =>
FZ(start: 1, count);
public static void Fz(int count) =>
Fz(start: 1, count);

/// <summary>
/// Creates a collection of a specified <paramref name="count"/> of numbers from a specified <paramref name="start"/> value and prints <c>FizzBuzz</c> for multiples of <c>3</c> and <c>5</c>, <c>Fizz</c> for multiples of <c>3</c>, <c>Buzz</c> for multiples of <c>5</c>, and the numeric value for any other value.
/// </summary>
/// <param name="start">The starting number.</param>
/// <param name="count">The number of values to print.</param>
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);

Expand Down
2 changes: 1 addition & 1 deletion src/Hussy.Net/Output/WriteHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ public static partial class Hussy
/// Writes the specified value to the console as a header (prefixed with two new lines).
/// </summary>
/// <param name="value">The value to be written.</param>
public static void WH<T>(T value) =>
public static void Wh<T>(T value) =>
Console.WriteLine("\n\n{0}", value);
}
2 changes: 1 addition & 1 deletion src/Hussy.Net/Output/WriteSeparator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static partial class Hussy
/// </summary>
/// <param name="character">The character used for the separator line. Default is '='.</param>
/// <param name="length">The length of the separator line. Default is 25.</param>
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);
Expand Down
50 changes: 50 additions & 0 deletions test/Hussy.Net.Tests/Generators/RangeTests.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
17 changes: 17 additions & 0 deletions test/Hussy.Net.Tests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -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;
21 changes: 21 additions & 0 deletions test/Hussy.Net.Tests/Hussy.Net.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.6.6" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Hussy.Net\Hussy.Net.csproj" />
</ItemGroup>

</Project>
12 changes: 12 additions & 0 deletions test/Hussy.Net.Tests/Linq/FilterTests.cs
Original file line number Diff line number Diff line change
@@ -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
{

}

0 comments on commit 69294b2

Please sign in to comment.