Skip to content

Commit

Permalink
🚧Process all warnings (#18)
Browse files Browse the repository at this point in the history
* Start work for issue #17

* refactor: change code to follow project coding standards

* ide: add word to rider dictionary

* deps: add fluent assertions v6.11.0 nuget package

* tests: refactor code to use fluent assertions

* refactor: clean code

* refactor: fix value comparison

* refactor: rename props

* cleanup: cleanup of test code and remove unused file

* tests: add and improve tests

* refactor: remove ParticleColor class and replace with Drawing.Color
  • Loading branch information
CalvinWilkinson authored Aug 9, 2023
1 parent eaa2356 commit 2764064
Show file tree
Hide file tree
Showing 40 changed files with 636 additions and 2,105 deletions.
1 change: 1 addition & 0 deletions Plazma.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public void Ctor_WithNull$PARAM_1$Param_ThrowsException()
private $OBJECT_TYPE$ CreateSystemUnderTest()
=&gt; new ($END$);</s:String>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Cornsilk/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=csharpsquid/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Gainsboro/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Kinson/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Plazma/@EntryIndexedValue">True</s:Boolean>
Expand Down
34 changes: 15 additions & 19 deletions Plazma/Behaviors/BehaviorFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,30 @@ public class BehaviorFactory : IBehaviorFactory
/// <exception cref="ArgumentNullException">Thrown if the <paramref name="settings"/> parameter is null.</exception>
public IBehavior[] CreateBehaviors(BehaviorSettings[] settings, IRandomizerService randomizerService)
{
if (settings is null)
{
throw new ArgumentNullException(nameof(settings), "The parameter must not be null.");
}
ArgumentNullException.ThrowIfNull(settings);
ArgumentNullException.ThrowIfNull(randomizerService);

var behaviors = new List<IBehavior>();

// Creates all of the behaviors using the given settings
foreach (var setting in settings)
{
if (setting is EasingRandomBehaviorSettings easingRandomBehaviorSettings)
{
behaviors.Add(new EasingRandomBehavior(easingRandomBehaviorSettings, randomizerService));
}
else if (setting is ColorTransitionBehaviorSettings clrTransitionBehaviorSettings)
{
behaviors.Add(new ColorTransitionBehavior(clrTransitionBehaviorSettings));
}
else if (setting is RandomChoiceBehaviorSettings randomChoiceBehaviorSettings)
{
behaviors.Add(new RandomColorBehavior(randomChoiceBehaviorSettings, randomizerService));
}
else
switch (setting)
{
throw new Exception($"Unknown behavior settings of type '{setting.GetType()}'");
case EasingRandomBehaviorSettings easingRandomBehaviorSettings:
behaviors.Add(new EasingRandomBehavior(easingRandomBehaviorSettings, randomizerService));
break;
case ColorTransitionBehaviorSettings clrTransitionBehaviorSettings:
behaviors.Add(new ColorTransitionBehavior(clrTransitionBehaviorSettings));
break;
case RandomChoiceBehaviorSettings randomChoiceBehaviorSettings:
behaviors.Add(new RandomColorBehavior(randomChoiceBehaviorSettings, randomizerService));
break;
default:
throw new Exception($"Unknown behavior settings of type '{setting.GetType().Name}'.");
}
}

return behaviors.ToArray();
}
}
}
4 changes: 2 additions & 2 deletions Plazma/Behaviors/BehaviorSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public abstract class BehaviorSettings
/// <returns>True if the specified object is equal to the current object; otherwise, false.</returns>
public override bool Equals(object? obj)
{
if (!(obj is BehaviorSettings setting))
if (obj is not BehaviorSettings setting)
{
return false;
}
Expand All @@ -38,4 +38,4 @@ public override bool Equals(object? obj)
/// <returns>A hash code for the current object.</returns>
[ExcludeFromCodeCoverage]
public override int GetHashCode() => HashCode.Combine(ApplyToAttribute);
}
}
8 changes: 5 additions & 3 deletions Plazma/Behaviors/ColorTransitionBehaviorSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Plazma.Behaviors;

using System.Drawing;

/// <summary>
/// Transitions from one color to another over a specific amount of time
/// using an easing function.
Expand All @@ -28,12 +30,12 @@ public class ColorTransitionBehaviorSettings : BehaviorSettings, IEasingCapable
/// <summary>
/// Gets or sets the color that the transition will start from.
/// </summary>
public ParticleColor StartColor { get; set; } = new ParticleColor(255, 255, 255, 255);
public Color StartColor { get; set; } = Color.White;

/// <summary>
/// Gets or sets the desired color to transition to.
/// </summary>
public ParticleColor StopColor { get; set; } = new ParticleColor(255, 255, 255, 255);
public Color StopColor { get; set; } = Color.White;

/// <summary>
/// Gets or sets the amount of time the behavior will run.
Expand All @@ -59,4 +61,4 @@ public class ColorTransitionBehaviorSettings : BehaviorSettings, IEasingCapable
/// Gets the amount of change to apply over time to the blue color component.
/// </summary>
internal int BlueChangeAmount => StopColor.B - StartColor.B;
}
}
37 changes: 1 addition & 36 deletions Plazma/Behaviors/EasingRandomBehaviorSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,39 +71,4 @@ public class EasingRandomBehaviorSettings : BehaviorSettings, IEasingCapable
/// </summary>
/// <remarks>A value less then or equal to 0 will result in the behavior not working.</remarks>
public float TotalTimeMax { get; set; }

/// <summary>
/// Determines whether the specified object is equal to the current object.
/// </summary>
/// <param name="obj">The object to compare with the current object.</param>
/// <returns>True if the specified object is equal to the current object; otherwise, false.</returns>
public override bool Equals(object? obj)
{
if (!(obj is EasingRandomBehaviorSettings setting))
{
return false;
}

return ApplyToAttribute == setting.ApplyToAttribute &&
StartMin == setting.StartMin &&
StartMax == setting.StartMax &&
ChangeMin == setting.ChangeMin &&
ChangeMax == setting.ChangeMax &&
TotalTimeMin == setting.TotalTimeMin &&
TotalTimeMax == setting.TotalTimeMax;
}

/// <summary>
/// Serves as the default hash function.
/// </summary>
/// <returns>A hash code for the current object.</returns>
public override int GetHashCode() =>
HashCode.Combine(
ApplyToAttribute,
StartMin,
StartMax,
ChangeMin,
ChangeMax,
TotalTimeMin,
TotalTimeMax);
}
}
4 changes: 2 additions & 2 deletions Plazma/Behaviors/IBehaviorFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ namespace Plazma.Behaviors;
public interface IBehaviorFactory
{
/// <summary>
/// Creates all of the behaviors using the given <paramref name="settings"/> and <paramref name="randomizerService"/>.
/// Creates all of the behaviors using the given <paramref name="settings"/> and <paramref name="randomService"/>.
/// </summary>
/// <param name="settings">The list of settings used to create each behavior.</param>
/// <param name="randomService">Used to generate random values from the given <paramref name="settings"/> parameter.</param>
/// <returns>A list of behaviors.</returns>
IBehavior[] CreateBehaviors(BehaviorSettings[] settings, IRandomizerService randomService);
}
}
26 changes: 0 additions & 26 deletions Plazma/Behaviors/RandomChoiceBehaviorSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

namespace Plazma.Behaviors;

using System;
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;

/// <summary>
/// Various settings for behaviors that choose values randomly from a list of choices.
Expand All @@ -29,28 +27,4 @@ public RandomChoiceBehaviorSettings()
/// Gets or sets the amount of time that the behavior should be enabled.
/// </summary>
public double LifeTime { get; set; }

/// <summary>
/// Determines whether the specified object is equal to the current object.
/// </summary>
/// <param name="obj">The object to compare with the current object.</param>
/// <returns>True if the specified object is equal to the current object; otherwise, false.</returns>
public override bool Equals(object? obj)
{
if (!(obj is RandomChoiceBehaviorSettings setting))
{
return false;
}

return !(Data is null) && !(setting.Data is null) && Data.ItemsAreEqual(setting.Data) &&
LifeTime == setting.LifeTime &&
ApplyToAttribute == setting.ApplyToAttribute;
}

/// <summary>
/// Serves as the default hash function.
/// </summary>
/// <returns>A hash code for the current object.</returns>
[ExcludeFromCodeCoverage]
public override int GetHashCode() => HashCode.Combine(Data);
}
67 changes: 17 additions & 50 deletions Plazma/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Plazma;
/// </summary>
public static class ExtensionMethods
{
private static readonly char[] ValidNumChars = new char[] { '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
private static readonly char[] ValidNumChars = { '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };

/// <summary>
/// Returns a random value between the given <paramref name="minValue"/> and <paramref name="maxValue"/>.
Expand Down Expand Up @@ -45,22 +45,6 @@ public static float Next(this Random random, float minValue, float maxValue)
return randomResult / 1000f;
}

/// <summary>
/// Returns a true/false value that represents the flip of a coin.
/// </summary>
/// <param name="random">The random instance to use.</param>
/// <returns>A random value between 0 and 1. 50% chance.</returns>
[ExcludeFromCodeCoverage]
public static bool FlipCoin(this Random random)
{
if (random is null)
{
throw new ArgumentNullException(nameof(random), "The parameter must not be null.");
}

return random.NextDouble() <= 0.5f;
}

/// <summary>
/// Adds the given <paramref name="pointB"/>'s X and Y components to this point and returns the result.
/// </summary>
Expand Down Expand Up @@ -97,7 +81,8 @@ public static PointF Mult(this PointF point, double scalar)
/// <param name="items">The list of items to count based on the predicate.</param>
/// <param name="predicate">The predicate that when returns true, counts the item.</param>
/// <returns>The number of items that match the predicate..</returns>
public static int Count<T>(this List<T> items, Predicate<T> predicate)
[SuppressMessage("csharpsquid", "S3267", Justification = "Not needed.")]
public static int Count<T>(this List<T>? items, Predicate<T> predicate)
{
if (items is null)
{
Expand All @@ -111,9 +96,9 @@ public static int Count<T>(this List<T> items, Predicate<T> predicate)

var result = 0;

for (var i = 0; i < items.Count; i++)
foreach (var t in items)
{
if (predicate(items[i]))
if (predicate(t))
{
result++;
}
Expand All @@ -129,7 +114,8 @@ public static int Count<T>(this List<T> items, Predicate<T> predicate)
/// <param name="items">The list of items to count based on the predicate.</param>
/// <param name="predicate">The predicate that when returns true, counts the item.</param>
/// <returns>The number of items that match the predicate..</returns>
public static int Count<T>(this T[] items, Predicate<T> predicate)
[SuppressMessage("csharpsquid", "S3267", Justification = "Not needed.")]
public static int Count<T>(this T[]? items, Predicate<T> predicate)
{
if (items is null)
{
Expand All @@ -143,9 +129,9 @@ public static int Count<T>(this T[] items, Predicate<T> predicate)

var result = 0;

for (var i = 0; i < items.Length; i++)
foreach (var t in items)
{
if (predicate(items[i]))
if (predicate(t))
{
result++;
}
Expand All @@ -159,15 +145,8 @@ public static int Count<T>(this T[] items, Predicate<T> predicate)
/// </summary>
/// <param name="value">The value to check.</param>
/// <returns>True if the string contains non number characters.</returns>
public static bool ContainsNonNumberCharacters(this string value)
{
if (string.IsNullOrEmpty(value))
{
return false;
}

return value.ToCharArray().Any(c => !ValidNumChars.Contains(c));
}
public static bool ContainsNonNumberCharacters(this string value) =>
!string.IsNullOrEmpty(value) && Array.Exists(value.ToCharArray(), c => !ValidNumChars.Contains(c));

/// <summary>
/// Returns a value indicating if each item in a given list position is
Expand All @@ -177,32 +156,20 @@ public static bool ContainsNonNumberCharacters(this string value)
/// <param name="items">The current instance of <see cref="IEnumerable{T}"/> items.</param>
/// <param name="compareItems">The items to compare to the this list of items.</param>
/// <returns>True if each arrays are equal.</returns>
public static bool ItemsAreEqual<T>(this IEnumerable<T> items, IEnumerable<T> compareItems)
public static bool ItemsAreEqual<T>(this IEnumerable<T>? items, IEnumerable<T>? compareItems)
where T : class
{
if (items is null && compareItems is null)
{
return true;
}

if (items is null && !(compareItems is null))
{
return false;
}

if (!(items is null) && compareItems is null)
{
return false;
}
var enumeratedItems = items is null ? Array.Empty<T>() : items.ToArray();
var enumeratedCompareItems = compareItems is null ? Array.Empty<T>() : compareItems.ToArray();

if (items.Count() != compareItems.Count())
if (enumeratedItems.Length != enumeratedCompareItems.Length)
{
return false;
}

for (var i = 0; i < items.Count(); i++)
for (var i = 0; i < enumeratedItems.Length; i++)
{
if (!items.ElementAt(i).Equals(compareItems.ElementAt(i)))
if (!enumeratedItems[i].Equals(enumeratedCompareItems[i]))
{
return false;
}
Expand Down
Loading

0 comments on commit 2764064

Please sign in to comment.