Skip to content

Instantly share code, notes, and snippets.

@bolilla
Created June 8, 2015 06:56
Show Gist options
  • Save bolilla/54f72cf7467e038e633f to your computer and use it in GitHub Desktop.
Save bolilla/54f72cf7467e038e633f to your computer and use it in GitHub Desktop.
GoPadawan CompoInterfaces Test
package main
import "fmt"
type motor struct {
ruido string
}
func (m motor) hacerRuido() string {
return fmt.Sprintf("Este motor hace: %s", m.ruido)
}
type ruidoso interface {
hacerRuido() string
}
type mockMotor string
func (mm mockMotor) hacerRuido() string {
return string(mm)
}
func main() {
var miMotor = motor{"¡Brrroum!"}
var ruidoResultante = mockMotor("Este motor hace: ¡Brrroum!")
fmt.Println("Probando ruido del motor")
if ejercitarRuido(miMotor) == ejercitarRuido(ruidoResultante) {
fmt.Println("Todo OK")
} else {
fmt.Println("Este motor no suena bien")
}
}
func ejercitarRuido(r ruidoso) string {
return r.hacerRuido()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment