3 add occupancy bson endpoint in backend

This commit is contained in:
survellow
2024-05-23 22:47:52 +02:00
parent d73f7e284b
commit 114a309e8b
9 changed files with 740 additions and 4 deletions

View File

@@ -0,0 +1,27 @@
//Calendar implementation for the HTWK Leipzig timetable. Evaluation and display of the individual dates in iCal format.
//Copyright (C) 2024 HTWKalender support@htwkalender.de
//This program is free software: you can redistribute it and/or modify
//it under the terms of the GNU Affero General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU Affero General Public License for more details.
//You should have received a copy of the GNU Affero General Public License
//along with this program. If not, see <https://www.gnu.org/licenses/>.
package functions
// function to filter an array
func Filter[T any](ss []T, test func(T) bool) (ret []T) {
for _, s := range ss {
if test(s) {
ret = append(ret, s)
}
}
return
}

View File

@@ -0,0 +1,103 @@
//Calendar implementation for the HTWK Leipzig timetable. Evaluation and display of the individual dates in iCal format.
//Copyright (C) 2024 HTWKalender support@htwkalender.de
//This program is free software: you can redistribute it and/or modify
//it under the terms of the GNU Affero General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU Affero General Public License for more details.
//You should have received a copy of the GNU Affero General Public License
//along with this program. If not, see <https://www.gnu.org/licenses/>.
package functions
import (
"reflect"
"strings"
"testing"
)
func Test_Filter_number(t *testing.T) {
type args struct {
ss []int
test func(int) bool
}
tests := []struct {
name string
args args
wantRet []int
}{
{
"filter even numbers",
args{
[]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
func(i int) bool {
return i%2 == 0
},
},
[]int{2, 4, 6, 8, 10},
},
{
"filter smaller than 5",
args{
[]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
func(i int) bool {
return i < 5
},
},
[]int{1, 2, 3, 4},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if gotRet := Filter(tt.args.ss, tt.args.test); !reflect.DeepEqual(gotRet, tt.wantRet) {
t.Errorf("filter() = %v, want %v", gotRet, tt.wantRet)
}
})
}
}
func Test_Filter_string(t *testing.T) {
type args struct {
ss []string
test func(string) bool
}
tests := []struct {
name string
args args
wantRet []string
}{
{
"filter contains a",
args{
[]string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"},
func(i string) bool {
return strings.Contains(i, "a")
},
},
[]string{"a"},
},
{
"filter starts with prefix 'a'",
args{
[]string{"alpha", "beta", "a", "ab", "ac", "delta"},
func(i string) bool {
return strings.HasPrefix(i, "a")
},
},
[]string{"alpha", "a", "ab", "ac"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if gotRet := Filter(tt.args.ss, tt.args.test); !reflect.DeepEqual(gotRet, tt.wantRet) {
t.Errorf("filter() = %v, want %v", gotRet, tt.wantRet)
}
})
}
}