-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Account project, Account & Lot classes, and first of two tests.
- Loading branch information
1 parent
1bffdfe
commit c015a18
Showing
6 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
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,18 @@ | ||
namespace Accounts; | ||
|
||
// import LunExService.LunEx; | ||
|
||
public class Account { | ||
|
||
public long TotalGain(Lot[] lots, int currentPrice) { | ||
long total = 0; | ||
foreach (Lot nextLot in lots) { | ||
total += GainForLot(nextLot, currentPrice); | ||
} | ||
return total; | ||
} | ||
|
||
private long GainForLot(Lot lot, int currentPrice) { | ||
return lot.GainAt(currentPrice); | ||
} | ||
} |
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,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
namespace Accounts; | ||
|
||
public class Lot | ||
{ | ||
private int shares; | ||
private long cost; | ||
|
||
public Lot(int shares, long cost) | ||
{ | ||
this.shares = shares; | ||
this.cost = cost; | ||
} | ||
|
||
public long GainAt(int currentPrice) | ||
{ | ||
return (shares * currentPrice) - cost; | ||
} | ||
} |
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,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" /> | ||
<PackageReference Include="coverlet.collector" Version="3.1.2" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Account\Account.csproj" /> | ||
</ItemGroup> | ||
|
||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
using Accounts; | ||
|
||
namespace AccountTests; | ||
|
||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
|
||
[TestClass] | ||
public class TotalGainTests | ||
{ | ||
[TestMethod] | ||
public void WhenUsingInteger() | ||
{ | ||
// given | ||
var firstLot = new Lot(100, 3000L); | ||
var latestLot = new Lot(10, 400L); | ||
Lot[] lots = { firstLot, latestLot }; | ||
Account account = new Account(); | ||
|
||
// when/then | ||
Assert.AreEqual(1220L, account.TotalGain(lots, 42)); | ||
} | ||
} |
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