Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exercício: Capítulo 24, Exercício 5 (Nível: 11) #77

Open
vkorbes opened this issue Sep 30, 2020 · 1 comment
Open

Exercício: Capítulo 24, Exercício 5 (Nível: 11) #77

vkorbes opened this issue Sep 30, 2020 · 1 comment

Comments

@vkorbes
Copy link
Owner

vkorbes commented Sep 30, 2020

Exercício: Capítulo 24, Exercício 5 (Nível: 11)

Link para o vídeo:

Use esta thread para compartilhar sua solução, discutir o exercício com os colegas e pedir ajuda caso tenha dificuldades!

@an4kein
Copy link

an4kein commented Mar 24, 2021

https://play.golang.org/p/POLA4_aFZn_0

package main

import (
	"fmt"
	"testing"
)

/* - Nos capítulos seguintes, uma das coisas que veremos é testes.
- Para testar sua habilidade de se virar por conta própria... desafio:
    - Utilizando as seguintes fontes: https://godoc.org/testing​ & http://www.golang-book.com/books/intr...​
    - Tente descobrir por conta própria como funcionam testes em Go.
    - Pode usar tradutor automático, pode rodar código na sua máquina, pode procurar no Google. Vale tudo.
    - O exercício é: crie um teste simples de uma função ou método ou pedaço qualquer de código. */

func Mostra(x int) int {
	total := (x + 100)
	fmt.Println(total)
	return x
}

func TestMostra(t *testing.T) {
	v := Mostra(5)
	if v != 4 {
		t.Errorf("Mostra(4) -> Valor inserido: %d ; Precisa de: 4", v)
	}
}

Output FAIL

=== RUN   TestMostra
105
    prog.go:24: Mostra(4) -> Valor inserido: 5 ; Precisa de: 4
--- FAIL: TestMostra (0.00s)
FAIL

1 test failed.

Output PASS

=== RUN   TestMostra
104
--- PASS: TestMostra (0.00s)
PASS

All tests passed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants