diff --git a/ExercisesForProgrammers/Bill.cs b/ExercisesForProgrammers/Bill.cs
index 7d44908..b7c1d4a 100644
--- a/ExercisesForProgrammers/Bill.cs
+++ b/ExercisesForProgrammers/Bill.cs
@@ -12,7 +12,7 @@ public double Subtotal {
if (this._tip == null) {
this._tip = new Tip();
}
- this.Tip.Calculate(value, this.Tip.PercentageOfSubtotal);
+ this._tip.Calculate(value, this._tip.PercentageOfSubtotal);
_subtotal = value;
}
}
@@ -25,33 +25,19 @@ public Tip Tip
return _tip;
}
set
- { //TODO: Write a test for this.
- this.Subtotal = value.Subtotal;
- this.Total = _subtotal + value.Value;
+ {
_tip = value;
- }
- }
-
- public double Total { get; private set; }
-
-
- public Bill()
- {
- this.Tip = new Tip();
+ this.Subtotal = value.Subtotal;
+ }
}
- public Bill(double subtotal, Tip tip)
- {
- this._subtotal = subtotal;
-
- if (subtotal.CompareTo(tip.Subtotal) == 0 || tip.Value.CompareTo(0D) == 0)
+ public double Total
+ {
+ get
{
- this._tip = tip;
- }
- else
- {
- throw new ArgumentException("Tip given not calculated against given subtotal");
+ return _subtotal + this._tip.Value;
}
}
+
}
}
diff --git a/ExercisesForProgrammers/Program.cs b/ExercisesForProgrammers/Program.cs
index 2900c8f..c1607a9 100644
--- a/ExercisesForProgrammers/Program.cs
+++ b/ExercisesForProgrammers/Program.cs
@@ -16,9 +16,9 @@ public static void Main(string[] args)
var newTip = new Tip(newBill.Subtotal, percentageOfSubtotal); //Assignment of subtotal is a bit odd here.
newBill.Tip = newTip;
- Console.WriteLine($"The tip is {newTip.Value}. ");
+ Console.WriteLine($"The tip is {newTip.Value.ToString("C")}. ");
- Console.WriteLine($"The total is {newBill.Total}. ");
+ Console.WriteLine($"The total is {newBill.Total.ToString("C")}. ");
Console.ReadLine(); // Wait for user to end program.
}
diff --git a/ExercisesForProgrammers/Tip.cs b/ExercisesForProgrammers/Tip.cs
index 82a5668..e3c1c00 100644
--- a/ExercisesForProgrammers/Tip.cs
+++ b/ExercisesForProgrammers/Tip.cs
@@ -42,7 +42,12 @@ public Tip(double subtotal, int percentageOfSubtotal) {
}
public double Calculate(double subtotal, int percentageOfSubtotal) {
- var result = subtotal * (percentageOfSubtotal / 100);
+ this._subtotal = subtotal;
+ this._percentageOfSubtotal = percentageOfSubtotal;
+
+ var result = ((double)percentageOfSubtotal / 100d);
+ result = subtotal * result;
+
this.Value = result;
return result;
}
diff --git a/TipCalculator.Tests/EndToEndTest.cs b/TipCalculator.Tests/EndToEndTest.cs
deleted file mode 100644
index 774d867..0000000
--- a/TipCalculator.Tests/EndToEndTest.cs
+++ /dev/null
@@ -1,13 +0,0 @@
-using System;
-using NUnit.Framework;
-
-namespace TipCalculator.Tests
-{
- [TestFixture]
- public class EndToEndTest
- {
- public EndToEndTest()
- {
- }
- }
-}
diff --git a/TipCalculator.Tests/FunctionalTests.cs b/TipCalculator.Tests/FunctionalTests.cs
new file mode 100644
index 0000000..02e6c26
--- /dev/null
+++ b/TipCalculator.Tests/FunctionalTests.cs
@@ -0,0 +1,81 @@
+using System;
+using NUnit.Framework;
+using ExercisesForProgrammers; //TipCalculator project
+
+namespace TipCalculator.Tests
+{
+ [TestFixture]
+ public class FunctionalTests
+ {
+ [Test]
+ public void BillAndTipSetupWithRealisticValues_ShouldCalculateTipAmountAndTotal()
+ {
+ //arrange
+
+ //input
+ double billAmount = 10.00; //dollars
+ int tipRate = 15; //percent (of subtotal)
+
+ double expectedTipAmount = 1.50; //dollars
+ double expectedTotalAmount = 11.50; //dollars
+
+ //act
+ var tip = new Tip();
+ double actualTipAmount = tip.Calculate(billAmount, tipRate);
+
+ var bill = new Bill() { Tip = tip };
+ var actualTotalAmount = bill.Total;
+
+ //assert
+ Assert.AreEqual(expectedTipAmount, actualTipAmount, "Actual tip amount does not equal expected tip amount.");
+ Assert.AreEqual(expectedTotalAmount, actualTotalAmount, "Actual total amount does not equal expected total amount.");
+ }
+
+ [Test]
+ public void GoodTest_OutputFormatting()
+ {
+ //arrange
+ string expectedTipFormat = "$1.50";
+ double tipAmount = 1.50d;
+
+ //act
+ var actualTipFormatted = tipAmount.ToString("C");
+
+ //assert
+ Assert.AreEqual(expectedTipFormat, actualTipFormatted);
+ }
+
+ [Test]
+ public void Test_ZeroTipPercentageInput()
+ {
+ throw new NotImplementedException();
+ }
+
+ ///
+ /// Defines the current requirement
+ /// -- might be nice to have a minimum tip in the future.
+ ///
+ [Test]
+ public void Test_ZeroSubtotalInput()
+ {
+ throw new NotImplementedException();
+ }
+
+ [Test]
+ public void BadCase_NonNumericInput_ShouldOutputErrorMessage() {
+ throw new NotImplementedException();
+ }
+
+ [Test]
+ public void BaseCase_NegativeTipPercentage_ShouldOutputErrorMessage() {
+ throw new NotImplementedException();
+ }
+
+ [Test]
+ public void BaseCase_NegativeSubtotal_ShouldOutputErrorMessage()
+ {
+ throw new NotImplementedException();
+ }
+
+ }
+}
diff --git a/TipCalculator.Tests/TipCalculator.Tests.csproj b/TipCalculator.Tests/TipCalculator.Tests.csproj
index 379d183..10519f6 100644
--- a/TipCalculator.Tests/TipCalculator.Tests.csproj
+++ b/TipCalculator.Tests/TipCalculator.Tests.csproj
@@ -33,10 +33,16 @@
-
+
+
+
+ {C1ACE25A-6829-4563-9636-E08DC4DAD01C}
+ TipCalculator
+
+
\ No newline at end of file