Skip to content

Commit

Permalink
feat: 實作圓形面積計算邏輯。調整測試個案中PI的小數進位問題。
Browse files Browse the repository at this point in the history
  • Loading branch information
LilyLin395135 committed Apr 9, 2023
1 parent 7088bce commit 29ceca7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
17 changes: 17 additions & 0 deletions AreaOfShapeCalulations/Circle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace AreaOfShapeCalulations
{
public class Circle : IShape
{
private double _radius;

public Circle(double radius)
{
_radius = radius;
}

public double Area()
{
return Math.Round(Math.PI * _radius * _radius,2);
}
}
}
9 changes: 9 additions & 0 deletions AreaOfShapeCalulationsTests/CalculateAreaTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ public void CalculateSquareArea()
TotalAreaShouldBe(9, square);
}

[TestMethod]
public void CalculateCircleArea()
{
//Arrange:準備測試資料(物件)
var circle = new Circle(4d);

TotalAreaShouldBe(50.27, circle);
}

private void TotalAreaShouldBe(double expected, IShape shape)
{
//Act:用Calculator
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Feature: Calculate the area of different shapes.
Scenario: Calculate Circle
Given There is a circle, and radius is 4 cm
When Calculate area
Then The area is 50.24 square cm
Then The area is 50.27 square cm
Scenario: Calculate Triangle
Given There is a triangle, height is 4 cm, and base-side is 5 cm
Expand Down

0 comments on commit 29ceca7

Please sign in to comment.