Skip to content

Commit

Permalink
feat: Add 06-switch/02-grades
Browse files Browse the repository at this point in the history
  • Loading branch information
levaitamas committed Aug 26, 2024
1 parent 8cc8016 commit 0c278ee
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 0 deletions.
19 changes: 19 additions & 0 deletions 06-switch/02-grades/.README.md
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).
16 changes: 16 additions & 0 deletions 06-switch/02-grades/.exercise_test.go
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))
}
1 change: 1 addition & 0 deletions 06-switch/02-grades/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# PLEASE RUN make generate
9 changes: 9 additions & 0 deletions 06-switch/02-grades/exercise.go
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
}
46 changes: 46 additions & 0 deletions 06-switch/02-grades/exercise.yaml
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
1 change: 1 addition & 0 deletions 06-switch/02-grades/exercise_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// PLEASE RUN make generate

0 comments on commit 0c278ee

Please sign in to comment.