Skip to content

Commit

Permalink
Add unit tests for SizeVisitor.
Browse files Browse the repository at this point in the history
  • Loading branch information
eminencegrs committed Feb 1, 2024
1 parent 7ccb899 commit 9257d11
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
36 changes: 36 additions & 0 deletions Behavioral/DesignPatterns.Visitor.UnitTests/SizeVisitorTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using DesignPatterns.Visitor.Converters;
using DesignPatterns.Visitor.Models;
using Shouldly;
using Xunit;

namespace DesignPatterns.Visitor.UnitTests;

public class SizeVisitorTests
{
[Theory]
[MemberData(nameof(TestCases))]
public void GivenSize_WhenCallVisit_ThenResultAsExpected(ISize size, ISize expectedResult)
{
var sizeVisitor = this.GetSut();
var actualResult = sizeVisitor.Visit(size);
actualResult.ShouldBeEquivalentTo(expectedResult);
}

private IVisitor<ISize, ISize> GetSut() => new SizeVisitor(
[
new KiloBytesToBytesConverter(),
new MegaBytesToBytesConverter(),
new GigaBytesToBytesConverter(),
new TeraBytesToBytesConverter(),
new PetaBytesToBytesConverter()
]);

public static IEnumerable<object[]> TestCases()
{
yield return [new SizeInKiloBytes { Value = 100 }, new SizeInBytes { Value = 102400 }];
yield return [new SizeInMegaBytes { Value = 200 }, new SizeInBytes { Value = 209715200 }];
yield return [new SizeInGigaBytes { Value = 300 }, new SizeInBytes { Value = 322122547200 }];
yield return [new SizeInTeraBytes { Value = 400 }, new SizeInBytes { Value = 439804651110400 }];
yield return [new SizeInPetaBytes { Value = 500 }, new SizeInBytes { Value = 562949953421312000 }];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ public void GivenStringValue_WhenCallVisit_ThenResultAsExpected(string inputValu
result.ShouldBeOfType(expectedType);
result.Value.ShouldBe(expectedValue);
}
}
}
2 changes: 1 addition & 1 deletion Behavioral/DesignPatterns.Visitor/ISize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace DesignPatterns.Visitor;

public interface ISize
{
double Value { get; }
long Value { get; }
string Unit { get; }
ISize Accept(IVisitor<ISize, ISize> visitor);
}
2 changes: 1 addition & 1 deletion Behavioral/DesignPatterns.Visitor/Models/Size.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace DesignPatterns.Visitor.Models;

public record class Size : ISize
{
public double Value { get; init; }
public long Value { get; init; }
public virtual string Unit { get; init; }

Check warning on line 6 in Behavioral/DesignPatterns.Visitor/Models/Size.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Unit' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 6 in Behavioral/DesignPatterns.Visitor/Models/Size.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Unit' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

public ISize Accept(IVisitor<ISize, ISize> visitor)
Expand Down

0 comments on commit 9257d11

Please sign in to comment.