Created
June 8, 2015 06:56
-
-
Save bolilla/54f72cf7467e038e633f to your computer and use it in GitHub Desktop.
GoPadawan CompoInterfaces Test
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
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