Pour tout problème contactez-nous par mail : support@froggit.fr | La FAQ :grey_question: | Rejoignez-nous sur le Chat :speech_balloon:

Skip to content
Snippets Groups Projects
Commit c3e42346 authored by Edouard Mangel's avatar Edouard Mangel
Browse files

Move prod code to business logic project

parent 0f2653be
No related branches found
No related tags found
No related merge requests found
Showing
with 108 additions and 36 deletions
No preview for this file type
File added
File added
File added
File deleted
No preview for this file type
......@@ -10,5 +10,23 @@
<ShowIgnoredTestsMenuOption>false</ShowIgnoredTestsMenuOption>
</TestsWindowMenuOptions>
<TestsWindowSplitterDistance>50%</TestsWindowSplitterDistance>
<TestsWindowTreeLayout>
<Column>
<Name>Name</Name>
<Width>1168</Width>
</Column>
<Column>
<Name>Status</Name>
<Width>92</Width>
</Column>
<Column>
<Name>LastExecutionTime</Name>
<Width>301</Width>
</Column>
<Column>
<Name>GridNode</Name>
<Width>270</Width>
</Column>
</TestsWindowTreeLayout>
</Settings>
</SolutionConfiguration>
\ No newline at end of file
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
namespace UnitTests;
namespace Credit;
public record Amount
{
public Amount(double value, Currency currency)
{
Currency = currency;
Value = (int)(value * Math.Pow(10, currency.Precision));
Value = (int)(Math.Round(value, Currency.Precision) * Math.Pow(10, currency.Precision));
}
public Amount(double value)
{
Currency = Currencies.Euro;
Value = (int)(Math.Round( value, Currency.Precision, MidpointRounding.AwayFromZero) * Math.Pow(10, Currency.Precision));
}
public Amount(int value)
{
Value = value;
Currency = new Currency("Euro", "EUR", 2);
Currency = Currencies.Euro;
}
public Amount(int value, Currency currency )
{
Value = value;
Currency = currency ?? new Currency("Euro", "EUR", 2);
Currency = currency ;
}
public int Value { get; init; }
......@@ -29,6 +36,12 @@ public record Amount
}
public static class Currencies
{
public static Currency Euro => new Currency("Euro", "EUR", 2);
}
public record Currency
{
public Currency(string name = "Euro", string isoAlpha = "EUR", int precision = 2)
......
namespace Credit;
public class MortgageSimulator
{
public static Amount ComputeMonthlyPayment(Amount borrowedAmount, int durationInMonth, decimal rate)
{
if (borrowedAmount.Value * (int) Math.Pow(10, borrowedAmount.Currency.Precision) < 5000000) {
throw new ArgumentOutOfRangeException(nameof(borrowedAmount), "Can't borrow so little capital.");
}
double numerator = (double)(borrowedAmount * rate / 12);
double denominator = 1 - Math.Pow((double)(1 + rate / 12), - durationInMonth);
double value = numerator / denominator;
return new Amount(value, borrowedAmount.Currency);
}
}
\ No newline at end of file
// <auto-generated/>
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;
File added
namespace UnitTests;
public class CreditSimulator
{
public static Amount ComputeMonthlyPayment(Amount borrowedAmount, int durationInMonth, double rate)
{
double numerator = borrowedAmount * rate / 12;
double denominator = 1 - Math.Pow((1 + rate / 12), -durationInMonth);
double value = numerator / denominator;
return new Amount(value, borrowedAmount.Currency);
}
}
\ No newline at end of file
using Credit;
using NFluent;
namespace UnitTests;
public class CreditSimulatorTest
{
[Theory]
[InlineData(50000, 250, 0.03d, 269.21d)]
[InlineData(100000, 200, 0.02d, 588.37d)]
[InlineData(150000, 240, 0.01d, 689.84d)]
public void ShouldComputeMensuality(int initalAmount, int durationInMonth, decimal rate, double expectedValue)
{
Amount borrowedAmount = new Amount( initalAmount);
var result = MortgageSimulator.ComputeMonthlyPayment(borrowedAmount, durationInMonth, rate);
Check.That(new Amount(Math.Round(expectedValue, 2, MidpointRounding.AwayFromZero))).IsEqualTo(result);
}
[Fact]
public void ShouldNotBeInferiorTo50k()
{
Check.ThatCode(() => MortgageSimulator.ComputeMonthlyPayment(borrowedAmount: 49999, 55, 1))
.Throws<ArgumentOutOfRangeException>()
.WithMessage("Can't borrow so little capital. (Parameter 'borrowedAmount')");
}
}
\ No newline at end of file
using NFluent;
namespace UnitTests;
public class CreditSimulatorTest
{
[Theory]
[InlineData(50000, 250, 0.03d, 26921)]
[InlineData(100000, 200, 0.02d, 58836)]
[InlineData(5000, 12, 0.01d, 41892)]
public void ShouldComputeMensuality(int initalAmount, int durationInMonth, double rate, int expectedValue)
{
Amount borrowedAmount = new Amount( initalAmount, new Currency("Euro", "EUR", 2));
var result = CreditSimulator.ComputeMonthlyPayment(borrowedAmount, durationInMonth, rate);
Check.That(result).IsEqualTo(new Amount(expectedValue, borrowedAmount.Currency));
}
}
\ No newline at end of file
......@@ -22,4 +22,8 @@
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Credit\Credit.csproj" />
</ItemGroup>
</Project>
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
// <auto-generated/>
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;
File added
// <auto-generated/>
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment