mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender.git
synced 2025-07-16 17:48:49 +02:00
fix:#40 added test for remove empty courses and fix bug in function
This commit is contained in:
@ -19,18 +19,19 @@ func GetAllCoursesForSemesterWithEvents(app *pocketbase.PocketBase, semester str
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
// remove empty courses
|
||||
// remove empty courses like " " or ""
|
||||
courses = removeEmptyCourses(courses)
|
||||
return courses, nil
|
||||
}
|
||||
}
|
||||
|
||||
// removeEmptyCourses removes empty courses from the list of courses
|
||||
func removeEmptyCourses(courses []string) []string {
|
||||
var filteredCourses []string
|
||||
|
||||
for index, course := range courses {
|
||||
if functions.OnlyWhitespace(course) || len(course) == 0 {
|
||||
filteredCourses = append(courses[:index], courses[index+1:]...)
|
||||
if !functions.OnlyWhitespace(course) || len(course) != 0 {
|
||||
filteredCourses = append(filteredCourses, courses[index])
|
||||
}
|
||||
}
|
||||
return filteredCourses
|
||||
|
39
backend/service/events/courseService_test.go
Normal file
39
backend/service/events/courseService_test.go
Normal file
@ -0,0 +1,39 @@
|
||||
package events
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_removeEmptyCourses(t *testing.T) {
|
||||
type args struct {
|
||||
courses []string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want []string
|
||||
}{
|
||||
{
|
||||
name: "Test remove empty courses",
|
||||
args: args{
|
||||
courses: []string{"", "test", "test2", ""},
|
||||
},
|
||||
want: []string{"test", "test2"},
|
||||
},
|
||||
{
|
||||
name: "Test remove empty courses",
|
||||
args: args{
|
||||
courses: []string{"", "test", "test2", "", "test3"},
|
||||
},
|
||||
want: []string{"test", "test2", "test3"},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := removeEmptyCourses(tt.args.courses); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("removeEmptyCourses() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user