-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8cc8016
commit 0c278ee
Showing
6 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Grade an Exam | ||
|
||
Write a small function that returns the numerical grade of an exam based on the percentage of points reached. | ||
|
||
Use this table for grading: | ||
|
||
| PERCENT | GRADE | | ||
| ------------------------- | ---------------------- | | ||
| {{index . "percents" 0}}+ | {{index . "grades" 0}} | | ||
| {{index . "percents" 1}}+ | {{index . "grades" 1}} | | ||
| {{index . "percents" 2}}+ | {{index . "grades" 2}} | | ||
| {{index . "percents" 3}}+ | {{index . "grades" 3}} | | ||
| otherwise | {{index . "grades" 4}} | | ||
|
||
For instance, the function should return {{index . "grades" 0}} for a percentage of 100, and {{index . "grades" 4}} for 0. | ||
|
||
Insert your code into the file `exercise.go` near the placeholder `// INSERT YOUR CODE HERE`. | ||
|
||
HINT: use the [`switch` statement](https://go.dev/tour/flowcontrol/9). |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package grades | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGradeExam(t *testing.T) { | ||
assert.Equal(t, {{index . "grades" 0}}, gradeExam(100)) | ||
assert.Equal(t, {{index . "grades" 0}}, gradeExam({{index . "percents" 0}})) | ||
assert.Equal(t, {{index . "grades" 1}}, gradeExam({{index . "percents" 1}})) | ||
assert.Equal(t, {{index . "grades" 2}}, gradeExam({{index . "percents" 2}})) | ||
assert.Equal(t, {{index . "grades" 3}}, gradeExam({{index . "percents" 3}})) | ||
assert.Equal(t, {{index . "grades" 4}}, gradeExam(0)) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# PLEASE RUN make generate |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package grades | ||
|
||
// DO NOT REMOVE THIS COMMENT | ||
//go:generate go run ../../exercises-cli.go -student-id=$STUDENT_ID generate | ||
|
||
// gradeExercise returns the grade of a given task percentage | ||
func gradeExercise(perfent float32) int { | ||
// INSERT YOUR CODE HERE | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
name: grades | ||
input: | ||
- percents: | ||
- 80 | ||
- 60 | ||
- 40 | ||
- 20 | ||
grades: | ||
- 5 | ||
- 4 | ||
- 3 | ||
- 2 | ||
- 1 | ||
- percents: | ||
- 80 | ||
- 60 | ||
- 40 | ||
- 20 | ||
grades: | ||
- 5 | ||
- 4 | ||
- 3 | ||
- 2 | ||
- 0 | ||
- percents: | ||
- 90 | ||
- 75 | ||
- 50 | ||
- 30 | ||
grades: | ||
- 5 | ||
- 4 | ||
- 3 | ||
- 2 | ||
- 1 | ||
- percents: | ||
- 90 | ||
- 75 | ||
- 50 | ||
- 30 | ||
grades: | ||
- 5 | ||
- 4 | ||
- 3 | ||
- 2 | ||
- 0 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// PLEASE RUN make generate |