Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions exercises/concept/hyperia-forex/.meta/Exemplar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ public CurrencyAmount(decimal amount, string currency)

public static bool operator !=(CurrencyAmount @this, CurrencyAmount other)
{
return @this != other;
if (@this.currency != other.currency)
{
throw new ArgumentException();
}

return @this.amount != other.amount;
}

public static bool operator >(CurrencyAmount @this, CurrencyAmount other)
Expand Down Expand Up @@ -82,11 +87,6 @@ public CurrencyAmount(decimal amount, string currency)
return new CurrencyAmount(@this.amount / divisor, @this.currency);
}

public static CurrencyAmount operator /(decimal divisor, CurrencyAmount @this)
{
return new CurrencyAmount(@this.amount / divisor, @this.currency);
}

public static explicit operator double(CurrencyAmount @this)
{
return (double)@this.amount;
Expand Down
21 changes: 5 additions & 16 deletions exercises/concept/hyperia-forex/.meta/config.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
{
"blurb": "Learn about operator overloading by introducing a new currency to a bank.",
"contributors": [
"ErikSchierboom",
"yzAlvin"
],
"authors": [
"mikedamay"
],
"contributors": ["ErikSchierboom", "yzAlvin", "sanderploegsma"],
"authors": ["mikedamay"],
"files": {
"solution": [
"HyperiaForex.cs"
],
"test": [
"HyperiaForexTests.cs"
],
"exemplar": [
".meta/Exemplar.cs"
]
"solution": ["HyperiaForex.cs"],
"test": ["HyperiaForexTests.cs"],
"exemplar": [".meta/Exemplar.cs"]
}
}
2 changes: 2 additions & 0 deletions exercises/concept/hyperia-forex/HyperiaForex.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FsCheck" Version="2.16.3" />
<PackageReference Include="FsCheck.Xunit" Version="2.16.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
Expand Down
161 changes: 150 additions & 11 deletions exercises/concept/hyperia-forex/HyperiaForexTests.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,163 @@
using System;
using Xunit;
using Exercism.Tests;
using FsCheck.Xunit;
using FsCheck;

public class OperatorOverloadingTests
public class HyperiaForexTests
{
[Fact]
public void Equality_true()
[Property]
public void Equality_with_same_currency(decimal value)
{
Assert.True(new CurrencyAmount(55, "HD") == new CurrencyAmount(55, "HD"));
var amount1 = new CurrencyAmount(value, "HD");
var amount2 = new CurrencyAmount(value, "HD");

Assert.True(amount1 == amount2);
}

[Property(Skip = "Remove this Skip property to run this test")]
public void Equality_with_different_currency(decimal value)
{
var amount1 = new CurrencyAmount(value, "HD");
var amount2 = new CurrencyAmount(value, "USD");

Assert.Throws<ArgumentException>(() => amount1 == amount2);
}

[Property(Skip = "Remove this Skip property to run this test")]
public Property Inequality_with_same_currency(decimal value1, decimal value2)
{
var amount1 = new CurrencyAmount(value1, "HD");
var amount2 = new CurrencyAmount(value2, "HD");

return Prop.When(value1 != value2, () => Assert.True(amount1 != amount2));
}

[Property(Skip = "Remove this Skip property to run this test")]
public void Inequality_with_different_currency(decimal value1, decimal value2)
{
var amount1 = new CurrencyAmount(value1, "HD");
var amount2 = new CurrencyAmount(value2, "USD");

Assert.Throws<ArgumentException>(() => amount1 != amount2);
}

[Property(Skip = "Remove this Skip property to run this test")]
public Property LessThan_with_same_currency(decimal value1, decimal value2)
{
var amount1 = new CurrencyAmount(value1, "HD");
var amount2 = new CurrencyAmount(value2, "HD");

return Prop.When(value1 < value2, () => Assert.True(amount1 < amount2));
}

[Property(Skip = "Remove this Skip property to run this test")]
public void LessThan_with_different_currency(decimal value1, decimal value2)
{
var amount1 = new CurrencyAmount(value1, "HD");
var amount2 = new CurrencyAmount(value2, "USD");

Assert.Throws<ArgumentException>(() => amount1 < amount2);
}

[Property(Skip = "Remove this Skip property to run this test")]
public Property GreaterThan_with_same_currency(decimal value1, decimal value2)
{
var amount1 = new CurrencyAmount(value1, "HD");
var amount2 = new CurrencyAmount(value2, "HD");

return Prop.When(value1 > value2, () => Assert.True(amount1 > amount2));
}

[Property(Skip = "Remove this Skip property to run this test")]
public void GreaterThan_with_different_currency(decimal value1, decimal value2)
{
var amount1 = new CurrencyAmount(value1, "HD");
var amount2 = new CurrencyAmount(value2, "USD");

Assert.Throws<ArgumentException>(() => amount1 > amount2);
}

[Property(Skip = "Remove this Skip property to run this test")]
public void Addition_with_same_currency(decimal value1, decimal value2)
{
var amount1 = new CurrencyAmount(value1, "HD");
var amount2 = new CurrencyAmount(value2, "HD");
var expected = new CurrencyAmount(value1 + value2, "HD");

Assert.Equal(expected, amount1 + amount2);
}

[Property(Skip = "Remove this Skip property to run this test")]
public void Addition_is_commutative(decimal value1, decimal value2)
{
var amount1 = new CurrencyAmount(value1, "HD");
var amount2 = new CurrencyAmount(value2, "HD");

Assert.Equal(amount1 + amount2, amount2 + amount1);
}

[Property(Skip = "Remove this Skip property to run this test")]
public void Addition_with_different_currency(decimal value1, decimal value2)
{
var amount1 = new CurrencyAmount(value1, "HD");
var amount2 = new CurrencyAmount(value2, "USD");

Assert.Throws<ArgumentException>(() => amount1 + amount2);
}

[Property(Skip = "Remove this Skip property to run this test")]
public void Subtraction_with_same_currency(decimal value1, decimal value2)
{
var amount1 = new CurrencyAmount(value1, "HD");
var amount2 = new CurrencyAmount(value2, "HD");
var expected = new CurrencyAmount(value1 - value2, "HD");

Assert.Equal(expected, amount1 - amount2);
}

[Property(Skip = "Remove this Skip property to run this test")]
public void Subtraction_with_different_currency(decimal value1, decimal value2)
{
var amount1 = new CurrencyAmount(value1, "HD");
var amount2 = new CurrencyAmount(value2, "USD");

Assert.Throws<ArgumentException>(() => amount1 - amount2);
}

[Property(Skip = "Remove this Skip property to run this test")]
public void Multiplication(decimal value, decimal factor)
{
Assert.Equal(new CurrencyAmount(factor * value, "HD"),
factor * new CurrencyAmount(value, "HD"));
}

[Property(Skip = "Remove this Skip property to run this test")]
public void Multiplication_is_commutative(decimal value, decimal factor)
{
var amount = new CurrencyAmount(value, "HD");

Assert.Equal(amount * factor, factor * amount);
}

[Property(Skip = "Remove this Skip property to run this test")]
public Property Division(decimal value, decimal divisor)
{
return Prop.When(
divisor != 0,
() => Assert.True(new CurrencyAmount(value, "HD") / divisor ==
new CurrencyAmount(value / divisor, "HD")));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Equality_false()
[Property(Skip = "Remove this Skip property to run this test")]
public void Cast_to_double(decimal value)
{
Assert.False(new CurrencyAmount(55, "HD") == new CurrencyAmount(60, "HD"));
Assert.Equal(Convert.ToDouble(value), (double)new CurrencyAmount(value, "HD"));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Equality_bad()
[Property(Skip = "Remove this Skip property to run this test")]
public void Cast_to_decimal(decimal value)
{
Assert.Throws<ArgumentException>(() => new CurrencyAmount(55, "HD") == new CurrencyAmount(60, "USD"));
decimal actual = new CurrencyAmount(value, "HD");
Assert.Equal(value, actual);
}
}