-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #77 from larien/traducao/estruturas-metodos-e-inte…
…rfaces Traducao/estruturas metodos e interfaces
- Loading branch information
Showing
38 changed files
with
1,041 additions
and
1,058 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
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
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
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,6 @@ | ||
package main | ||
|
||
// Perimetro retorna o perímetro de um retângulo | ||
func Perimetro(largura float64, altura float64) float64 { | ||
return 2 * (largura + altura) | ||
} |
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,12 @@ | ||
package main | ||
|
||
import "testing" | ||
|
||
func TestPerimetro(t *testing.T) { | ||
resultado := Perimetro(10.0, 10.0) | ||
esperado := 40.0 | ||
|
||
if resultado != esperado { | ||
t.Errorf("resultado %.2f, esperado %.2f", resultado, esperado) | ||
} | ||
} |
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,11 @@ | ||
package main | ||
|
||
// Perimetro retorna o perímetro de um retângulo | ||
func Perimetro(largura float64, altura float64) float64 { | ||
return 2 * (largura + altura) | ||
} | ||
|
||
// Area retorna a área de um retângulo | ||
func Area(largura float64, altura float64) float64 { | ||
return largura * altura | ||
} |
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,21 @@ | ||
package main | ||
|
||
import "testing" | ||
|
||
func TestPerimetro(t *testing.T) { | ||
resultado := Perimetro(10.0, 10.0) | ||
esperado := 40.0 | ||
|
||
if resultado != esperado { | ||
t.Errorf("resultado %.2f, esperado %.2f", resultado, esperado) | ||
} | ||
} | ||
|
||
func TestArea(t *testing.T) { | ||
resultado := Area(12.0, 6.0) | ||
esperado := 72.0 | ||
|
||
if resultado != esperado { | ||
t.Errorf("resultado %.2f, esperado %.2f", resultado, esperado) | ||
} | ||
} |
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,17 @@ | ||
package main | ||
|
||
// Retangulo tem as dimensões de um retângulo | ||
type Retangulo struct { | ||
Largura float64 | ||
Altura float64 | ||
} | ||
|
||
// Perimetro retorna o perímetro de um retângulo | ||
func Perimetro(retangulo Retangulo) float64 { | ||
return 2 * (retangulo.Largura + retangulo.Altura) | ||
} | ||
|
||
// Area retorna a área de um retângulo | ||
func Area(retangulo Retangulo) float64 { | ||
return retangulo.Largura * retangulo.Altura | ||
} |
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,23 @@ | ||
package main | ||
|
||
import "testing" | ||
|
||
func TestPerimetro(t *testing.T) { | ||
retangulo := Retangulo{10.0, 10.0} | ||
resultado := Perimetro(retangulo) | ||
esperado := 40.0 | ||
|
||
if resultado != esperado { | ||
t.Errorf("resultado %.2f, esperado %.2f", resultado, esperado) | ||
} | ||
} | ||
|
||
func TestArea(t *testing.T) { | ||
retangulo := Retangulo{12.0, 6.0} | ||
resultado := Area(retangulo) | ||
esperado := 72.0 | ||
|
||
if resultado != esperado { | ||
t.Errorf("resultado %.2f, esperado %.2f", resultado, esperado) | ||
} | ||
} |
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,29 @@ | ||
package main | ||
|
||
import "math" | ||
|
||
// Retangulo tem as dimensões de um retângulo | ||
type Retangulo struct { | ||
Largura float64 | ||
Altura float64 | ||
} | ||
|
||
// Area retorna a área de um retângulo | ||
func (r Retangulo) Area() float64 { | ||
return r.Largura * r.Altura | ||
} | ||
|
||
// Perimetro retorna o perímetro de um retângulo | ||
func Perimetro(retangulo Retangulo) float64 { | ||
return 2 * (retangulo.Largura + retangulo.Altura) | ||
} | ||
|
||
// Circulo representa um círculo. | ||
type Circulo struct { | ||
Raio float64 | ||
} | ||
|
||
// Area retorna a área de um círculo | ||
func (c Circulo) Area() float64 { | ||
return math.Pi * c.Raio * c.Raio | ||
} |
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,37 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestPerimetro(t *testing.T) { | ||
retangulo := Retangulo{10.0, 10.0} | ||
resultado := Perimetro(retangulo) | ||
esperado := 40.0 | ||
|
||
if resultado != esperado { | ||
t.Errorf("resultado %.2f, esperado %.2f", resultado, esperado) | ||
} | ||
} | ||
|
||
func TestArea(t *testing.T) { | ||
t.Run("retângulos", func(t *testing.T) { | ||
retangulo := Retangulo{12.0, 6.0} | ||
resultado := retangulo.Area() | ||
esperado := 72.0 | ||
|
||
if resultado != esperado { | ||
t.Errorf("resultado %.2f, esperado %.2f", resultado, esperado) | ||
} | ||
}) | ||
|
||
t.Run("círculos", func(t *testing.T) { | ||
circulo := Circulo{10} | ||
resultado := circulo.Area() | ||
esperado := 314.1592653589793 | ||
|
||
if resultado != esperado { | ||
t.Errorf("resultado %.2f, esperado %.2f", resultado, esperado) | ||
} | ||
}) | ||
} |
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,34 @@ | ||
package main | ||
|
||
import "math" | ||
|
||
// Forma é implementado por qualquer coisa que possa dizer qual é sua área | ||
type Forma interface { | ||
Area() float64 | ||
} | ||
|
||
// Retangulo tem as dimensões de um retângulo | ||
type Retangulo struct { | ||
Largura float64 | ||
Altura float64 | ||
} | ||
|
||
// Area retorna a área de um retângulo | ||
func (r Retangulo) Area() float64 { | ||
return r.Largura * r.Altura | ||
} | ||
|
||
// Perimetro retorna o perímetro de um retângulo | ||
func Perimetro(retangulo Retangulo) float64 { | ||
return 2 * (retangulo.Largura + retangulo.Altura) | ||
} | ||
|
||
// Circulo representa um círculo. | ||
type Circulo struct { | ||
Raio float64 | ||
} | ||
|
||
// Area retorna a área de um círculo | ||
func (c Circulo) Area() float64 { | ||
return math.Pi * c.Raio * c.Raio | ||
} |
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,36 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestPerimetro(t *testing.T) { | ||
retangulo := Retangulo{10.0, 10.0} | ||
resultado := Perimetro(retangulo) | ||
esperado := 40.0 | ||
|
||
if resultado != esperado { | ||
t.Errorf("resultado %.2f, esperado %.2f", resultado, esperado) | ||
} | ||
} | ||
|
||
func TestArea(t *testing.T) { | ||
verificaArea := func(t *testing.T, forma Forma, esperado float64) { | ||
t.Helper() | ||
resultado := forma.Area() | ||
|
||
if resultado != esperado { | ||
t.Errorf("resultado %.2f, esperado %.2f", resultado, esperado) | ||
} | ||
} | ||
|
||
t.Run("retângulos", func(t *testing.T) { | ||
retangulo := Retangulo{12.0, 6.0} | ||
verificaArea(t, retangulo, 72.0) | ||
}) | ||
|
||
t.Run("círculos", func(t *testing.T) { | ||
circulo := Circulo{10} | ||
verificaArea(t, circulo, 314.1592653589793) | ||
}) | ||
} |
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,34 @@ | ||
package main | ||
|
||
import "math" | ||
|
||
// Forma é implementado por qualquer coisa que possa dizer qual é sua área | ||
type Forma interface { | ||
Area() float64 | ||
} | ||
|
||
// Retangulo tem as dimensões de um retângulo | ||
type Retangulo struct { | ||
Largura float64 | ||
Altura float64 | ||
} | ||
|
||
// Area retorna a área de um retângulo | ||
func (r Retangulo) Area() float64 { | ||
return r.Largura * r.Altura | ||
} | ||
|
||
// Perimetro retorna o perímetro de um retângulo | ||
func Perimetro(retangulo Retangulo) float64 { | ||
return 2 * (retangulo.Largura + retangulo.Altura) | ||
} | ||
|
||
// Circulo representa um círculo. | ||
type Circulo struct { | ||
Raio float64 | ||
} | ||
|
||
// Area retorna a área de um círculo | ||
func (c Circulo) Area() float64 { | ||
return math.Pi * c.Raio * c.Raio | ||
} |
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,32 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestPerimetro(t *testing.T) { | ||
retangulo := Retangulo{10.0, 10.0} | ||
resultado := Perimetro(retangulo) | ||
esperado := 40.0 | ||
|
||
if resultado != esperado { | ||
t.Errorf("resultado %.2f, esperado %.2f", resultado, esperado) | ||
} | ||
} | ||
|
||
func TestArea(t *testing.T) { | ||
testesArea := []struct { | ||
forma Forma | ||
esperado float64 | ||
}{ | ||
{Retangulo{12, 6}, 72.0}, | ||
{Circulo{10}, 314.1592653589793}, | ||
} | ||
|
||
for _, tt := range testesArea { | ||
resultado := tt.forma.Area() | ||
if resultado != tt.esperado { | ||
t.Errorf("resultado %.2f, esperado %.2f", resultado, tt.esperado) | ||
} | ||
} | ||
} |
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,45 @@ | ||
package main | ||
|
||
import "math" | ||
|
||
// Forma é implementado por qualquer coisa que possa dizer qual é sua área | ||
type Forma interface { | ||
Area() float64 | ||
} | ||
|
||
// Retangulo tem as dimensões de um retângulo | ||
type Retangulo struct { | ||
Largura float64 | ||
Altura float64 | ||
} | ||
|
||
// Area retorna a área de um retângulo | ||
func (r Retangulo) Area() float64 { | ||
return r.Largura * r.Altura | ||
} | ||
|
||
// Perimetro retorna o perímetro de um retângulo | ||
func Perimetro(retangulo Retangulo) float64 { | ||
return 2 * (retangulo.Largura + retangulo.Altura) | ||
} | ||
|
||
// Circulo representa um círculo. | ||
type Circulo struct { | ||
Raio float64 | ||
} | ||
|
||
// Area retorna a área de um círculo | ||
func (c Circulo) Area() float64 { | ||
return math.Pi * c.Raio * c.Raio | ||
} | ||
|
||
// Triangulo representa as dimensões de um triângulo | ||
type Triangulo struct { | ||
Base float64 | ||
Altura float64 | ||
} | ||
|
||
// Area retorna a área de um triângulo | ||
func (t Triangulo) Area() float64 { | ||
return (t.Base * t.Altura) * 0.5 | ||
} |
Oops, something went wrong.