-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from polyadic/simplify-generator
Improve the generation of arbitraries and tests * Fix distribution stratgey for negative amounts of money
- Loading branch information
Showing
10 changed files
with
159 additions
and
77 deletions.
There are no files selected for viewing
14 changes: 13 additions & 1 deletion
14
Funcky.Money.SourceGenerator/Funcky.Money.SourceGenerator.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk; Microsoft.Build.CentralPackageVersions"> | ||
<PropertyGroup> | ||
<TargetFrameworks>netstandard2.0;net5.0</TargetFrameworks> | ||
<TargetFrameworks>netstandard2.0</TargetFrameworks> | ||
<LangVersion>9.0</LangVersion> | ||
<Nullable>enable</Nullable> | ||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Funcky" GeneratePathProperty="true" PrivateAssets="all" /> | ||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" PrivateAssets="all" /> | ||
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" PrivateAssets="all" /> | ||
</ItemGroup> | ||
<PropertyGroup> | ||
<GetTargetPathDependsOn>$(GetTargetPathDependsOn);GetDependencyTargetPaths</GetTargetPathDependsOn> | ||
</PropertyGroup> | ||
<Target Name="GetDependencyTargetPaths"> | ||
<ItemGroup> | ||
<TargetPathWithTargetPlatformMoniker Include="$(PkgFuncky)\lib\netstandard2.0\Funcky.dll" IncludeRuntimeDependency="false" /> | ||
</ItemGroup> | ||
</Target> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using FsCheck; | ||
|
||
namespace Funcky.Test | ||
{ | ||
internal class MoneyArbitraries | ||
{ | ||
public static Arbitrary<Currency> ArbitraryCurrency() | ||
=> Arb.From(Gen.Elements<Currency>(Currency.AllCurrencies)); | ||
|
||
public static Arbitrary<Money> ArbitraryMoney() | ||
=> GenerateMoney().ToArbitrary(); | ||
|
||
public static Arbitrary<SwissMoney> ArbitrarySwissMoney() | ||
=> GenerateSwissFranc().ToArbitrary(); | ||
|
||
private static Gen<Money> GenerateMoney() | ||
=> from currency in Arb.Generate<Currency>() | ||
from amount in Arb.Generate<int>() | ||
select new Money(Power.OfATenth(currency.MinorUnitDigits) * amount, currency); | ||
|
||
private static Gen<SwissMoney> GenerateSwissFranc() | ||
=> from amount in Arb.Generate<int>() | ||
select new SwissMoney(Money.CHF(SwissMoney.SmallestCoin * amount)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Funcky.Test | ||
{ | ||
public record SwissMoney(Money Get) | ||
{ | ||
public const decimal SmallestCoin = 0.05m; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace Funcky.Extensions | ||
{ | ||
internal static class SignExtension | ||
{ | ||
public static decimal CopySign(this decimal positiveNumber, decimal signSource) | ||
=> signSource switch | ||
{ | ||
< 0 => -positiveNumber, | ||
>= 0 => positiveNumber, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters