Created
April 5, 2023 03:25
-
-
Save berdoezt/e38309183cefb5d27bcd488d8f50a1ea to your computer and use it in GitHub Desktop.
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 | |
// input | |
// process(input) = result | |
// expected | |
// result == expected | |
// 90 | |
// B | |
// A | |
func Grading(score int) string { | |
if score > 90 { | |
score = 90 | |
} else if score < 60 { | |
score += 5 | |
} | |
var grade string | |
if score > 90 { | |
grade = "A" | |
} else if score > 80 { | |
grade = "B" | |
} else if score > 70 { | |
grade = "C" | |
} else if score > 60 { | |
grade = "D" | |
} else { | |
grade = "E" | |
} | |
return grade | |
} | |
type Person struct { | |
Name string | |
} | |
func (p *Person) Walk() string { | |
return "tap tap dor" | |
} |
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 ( | |
"testing" | |
"github.com/stretchr/testify/assert" | |
) | |
func TestGrading(t *testing.T) { | |
testcases := []struct { | |
name string | |
input int | |
expected string | |
}{ | |
{ | |
name: ` | |
Given score more than / equal 90 | |
When do grading | |
Then should get grade B`, | |
input: 90, | |
expected: "B", | |
}, | |
{ | |
input: 60, | |
expected: "E", | |
}, | |
} | |
for _, tc := range testcases { | |
t.Run(tc.name, func(t *testing.T) { | |
result := Grading(tc.input) | |
assert.Equal(t, tc.expected, result) | |
}) | |
} | |
} | |
func TestPerson_Walk(t *testing.T) { | |
type fields struct { | |
Name string | |
} | |
tests := []struct { | |
name string | |
fields fields | |
want string | |
}{ | |
{ | |
name: "Case #1. Person Walk", | |
want: "tap tap", | |
}, | |
} | |
for _, tt := range tests { | |
t.Run(tt.name, func(t *testing.T) { | |
p := &Person{ | |
Name: tt.fields.Name, | |
} | |
result := p.Walk() | |
assert.Equal(t, tt.want, result) | |
// if got := p.Walk(); got != tt.want { | |
// t.Errorf("Person.Walk() = %v, want %v", got, tt.want) | |
// } | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment