From c015a1804785836543eaca40dc71172b4e22e7ea Mon Sep 17 00:00:00 2001 From: Rob Myers Date: Tue, 28 Feb 2023 13:51:21 -0800 Subject: [PATCH] Added Account project, Account & Lot classes, and first of two tests. --- LunExLab/Account/Account.cs | 18 +++++++++++++++++ LunExLab/Account/Account.csproj | 9 +++++++++ LunExLab/Account/Lot.cs | 18 +++++++++++++++++ LunExLab/AccountTests/AccountTests.csproj | 22 +++++++++++++++++++++ LunExLab/AccountTests/TotalGainTests.cs | 24 +++++++++++++++++++++++ LunExLab/LunExLab.sln | 12 ++++++++++++ 6 files changed, 103 insertions(+) create mode 100644 LunExLab/Account/Account.cs create mode 100644 LunExLab/Account/Account.csproj create mode 100644 LunExLab/Account/Lot.cs create mode 100644 LunExLab/AccountTests/AccountTests.csproj create mode 100644 LunExLab/AccountTests/TotalGainTests.cs diff --git a/LunExLab/Account/Account.cs b/LunExLab/Account/Account.cs new file mode 100644 index 0000000..2e04399 --- /dev/null +++ b/LunExLab/Account/Account.cs @@ -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); + } +} \ No newline at end of file diff --git a/LunExLab/Account/Account.csproj b/LunExLab/Account/Account.csproj new file mode 100644 index 0000000..eb2460e --- /dev/null +++ b/LunExLab/Account/Account.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/LunExLab/Account/Lot.cs b/LunExLab/Account/Lot.cs new file mode 100644 index 0000000..17ce5e6 --- /dev/null +++ b/LunExLab/Account/Lot.cs @@ -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; + } +} \ No newline at end of file diff --git a/LunExLab/AccountTests/AccountTests.csproj b/LunExLab/AccountTests/AccountTests.csproj new file mode 100644 index 0000000..8ecf500 --- /dev/null +++ b/LunExLab/AccountTests/AccountTests.csproj @@ -0,0 +1,22 @@ + + + + net6.0 + enable + enable + + false + + + + + + + + + + + + + + diff --git a/LunExLab/AccountTests/TotalGainTests.cs b/LunExLab/AccountTests/TotalGainTests.cs new file mode 100644 index 0000000..3c491d4 --- /dev/null +++ b/LunExLab/AccountTests/TotalGainTests.cs @@ -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)); + } +} \ No newline at end of file diff --git a/LunExLab/LunExLab.sln b/LunExLab/LunExLab.sln index e0bc31a..841997a 100644 --- a/LunExLab/LunExLab.sln +++ b/LunExLab/LunExLab.sln @@ -2,6 +2,10 @@ Microsoft Visual Studio Solution File, Format Version 12.00 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LunExService", "LunExService\LunExService.csproj", "{CCFD3F57-923D-4665-AAAC-3475217E9ADB}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AccountTests", "AccountTests\AccountTests.csproj", "{E0E46080-7AAA-4D15-96DD-26A40CBA3DFA}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Account", "Account\Account.csproj", "{F09891BE-9441-4234-8A61-9587D8221F42}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -12,5 +16,13 @@ Global {CCFD3F57-923D-4665-AAAC-3475217E9ADB}.Debug|Any CPU.Build.0 = Debug|Any CPU {CCFD3F57-923D-4665-AAAC-3475217E9ADB}.Release|Any CPU.ActiveCfg = Release|Any CPU {CCFD3F57-923D-4665-AAAC-3475217E9ADB}.Release|Any CPU.Build.0 = Release|Any CPU + {E0E46080-7AAA-4D15-96DD-26A40CBA3DFA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E0E46080-7AAA-4D15-96DD-26A40CBA3DFA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E0E46080-7AAA-4D15-96DD-26A40CBA3DFA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E0E46080-7AAA-4D15-96DD-26A40CBA3DFA}.Release|Any CPU.Build.0 = Release|Any CPU + {F09891BE-9441-4234-8A61-9587D8221F42}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F09891BE-9441-4234-8A61-9587D8221F42}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F09891BE-9441-4234-8A61-9587D8221F42}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F09891BE-9441-4234-8A61-9587D8221F42}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal