-
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 #55 from larien/ponteiros-e-erros
Ponteiros e erros
- Loading branch information
Showing
21 changed files
with
955 additions
and
960 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,25 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
// Bitcoin representa o número de Bitcoins | ||
type Bitcoin int | ||
|
||
func (b Bitcoin) String() string { | ||
return fmt.Sprintf("%d BTC", b) | ||
} | ||
|
||
// Carteira armazena o número de bitcoins que uma pessoa tem | ||
type Carteira struct { | ||
saldo Bitcoin | ||
} | ||
|
||
// Depositar vai adicionar Bitcoins à carteira | ||
func (c *Carteira) Depositar(quantidade Bitcoin) { | ||
c.saldo += quantidade | ||
} | ||
|
||
// Saldo retorna o número de Bitcoins que uma carteira tem | ||
func (c *Carteira) Saldo() Bitcoin { | ||
return c.saldo | ||
} |
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,19 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestCarteira(t *testing.T) { | ||
carteira := Carteira{} | ||
|
||
carteira.Depositar(Bitcoin(10)) | ||
|
||
resultado := carteira.Saldo() | ||
|
||
esperado := Bitcoin(10) | ||
|
||
if resultado != esperado { | ||
t.Errorf("resultado %s, esperado %s", resultado, esperado) | ||
} | ||
} |
Oops, something went wrong.