Une collection organisée de snippets de code pour accélérer votre développement. Parcourez, recherchez et copiez en un clic.
func BenchmarkAddition(b *testing.B) {
for i := 0; i < b.N; i++ {
addition(1, 2)
}
}
func TestAddition(t *testing.T) {
resultat := addition(2, 3)
if resultat != 5 {
t.Errorf("Addition(2, 3) = %d; attendu 5", resultat)
}
}
var tests = []struct { a, b, attendu int }{ {1, 2, 3}, {4, 5, 9} }
for _, tt := range tests {
if res := addition(tt.a, tt.b); res != tt.attendu {
t.Errorf("Erreur...")
}
}