Skip to content
Open
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
3 changes: 3 additions & 0 deletions shape/circle.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ package shape

import "math"

// Circle is a round thing
type Circle struct {
Radius float64
}

//CalculateArea is a function to calculate ... hmm let's see Area
func (circle Circle) CalculateArea() float64 {
return math.Pi * circle.Radius
}

// CalculatePerimeter is a function that does the geometric math for a permiter
func (circle Circle) CalculatePerimeter() float64 {
return 2 * math.Pi * circle.Radius
}
3 changes: 3 additions & 0 deletions shape/rectangle.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package shape

// Rectangle is a sqaure like thingy
type Rectangle struct {
Width float64
Height float64
}

//CalculateArea is a function to calculate ... hmm let's see Area
func (rectangle Rectangle) CalculateArea() float64 {
return rectangle.Width * rectangle.Height
}

// CalculatePerimeter is a function that does the geometric math for a permiter
func (rectangle Rectangle) CalculatePerimeter() float64 {
return rectangle.Width*2 + rectangle.Height*2
}
2 changes: 2 additions & 0 deletions shape/triangle.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package shape

// Triangle has three points of fun
type Triangle struct {
Base float64
Height float64
}

// CalculateArea is a function to calculate ... hmm let's see Area
func (triangle Triangle) CalculateArea() float64 {
return triangle.Height * triangle.Base / 2.0
}
10 changes: 5 additions & 5 deletions shape_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ func TestPerimeter(t *testing.T) {
}

t.Run("rectangles", func(t *testing.T) {
rectangle := shape.Rectangle{10.0, 10.0}
rectangle := shape.Rectangle{Width: 10.0, Height:10.0}
checkPerimeter(t, rectangle, 40.0)
})

t.Run("circles", func(t *testing.T) {
circle := shape.Circle{10.0}
circle := shape.Circle{Radius: 10.0}
checkPerimeter(t, circle, 62.83185307179586)
})
}
Expand All @@ -35,17 +35,17 @@ func TestArea(t *testing.T) {
}

t.Run("rectangles", func(t *testing.T) {
rectangle := shape.Rectangle{12, 6}
rectangle := shape.Rectangle{Width:12, Height:6}
checkArea(t, rectangle, 72.0)
})

t.Run("circles", func(t *testing.T) {
circle := shape.Circle{10.0}
circle := shape.Circle{Radius:10.0}
checkArea(t, circle, 31.41592653589793)
})

t.Run("triangles", func(t *testing.T) {
triangle := shape.Triangle{10.0, 10.0}
triangle := shape.Triangle{Base:10.0, Height:10.0}
checkArea(t, triangle, 50)
})
}