feat: tests and bugfix for 'lower hand'
This commit is contained in:
parent
89982d5c39
commit
517fda2512
8
go.mod
8
go.mod
|
@ -2,8 +2,14 @@ module sunshine.industries/some-automoderation
|
||||||
|
|
||||||
go 1.20
|
go 1.20
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/kr/pretty v0.3.1
|
||||||
|
github.com/redis/go-redis/v9 v9.2.1
|
||||||
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/cespare/xxhash/v2 v2.2.0 // indirect
|
github.com/cespare/xxhash/v2 v2.2.0 // indirect
|
||||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||||
github.com/redis/go-redis/v9 v9.2.1 // indirect
|
github.com/kr/text v0.2.0 // indirect
|
||||||
|
github.com/rogpeppe/go-internal v1.9.0 // indirect
|
||||||
)
|
)
|
||||||
|
|
10
go.sum
10
go.sum
|
@ -1,6 +1,16 @@
|
||||||
|
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
|
||||||
|
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
|
||||||
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
|
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
|
||||||
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||||
|
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
|
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
|
||||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
|
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
|
||||||
|
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||||
|
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||||
|
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||||
|
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||||
|
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
|
||||||
github.com/redis/go-redis/v9 v9.2.1 h1:WlYJg71ODF0dVspZZCpYmoF1+U1Jjk9Rwd7pq6QmlCg=
|
github.com/redis/go-redis/v9 v9.2.1 h1:WlYJg71ODF0dVspZZCpYmoF1+U1Jjk9Rwd7pq6QmlCg=
|
||||||
github.com/redis/go-redis/v9 v9.2.1/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M=
|
github.com/redis/go-redis/v9 v9.2.1/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M=
|
||||||
|
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
|
||||||
|
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
|
||||||
|
|
|
@ -66,7 +66,7 @@ gestureIteration:
|
||||||
startIndex := r.gestureSearchStartIndex(gesture, currentSpeakerGesture)
|
startIndex := r.gestureSearchStartIndex(gesture, currentSpeakerGesture)
|
||||||
participantsCount := len(r.Paricipants)
|
participantsCount := len(r.Paricipants)
|
||||||
for i := 1; i < participantsCount; i++ {
|
for i := 1; i < participantsCount; i++ {
|
||||||
checkIndex := startIndex + i%participantsCount
|
checkIndex := (startIndex + i) % participantsCount
|
||||||
checkPerson := r.Paricipants[checkIndex]
|
checkPerson := r.Paricipants[checkIndex]
|
||||||
checkGesture, isFound := r.ParticipantHands[checkPerson.Id]
|
checkGesture, isFound := r.ParticipantHands[checkPerson.Id]
|
||||||
if isFound && checkGesture == gesture {
|
if isFound && checkGesture == gesture {
|
||||||
|
@ -111,19 +111,22 @@ func (r *Room) gestureSearchStartIndex(gesture, curSpeakerGesture HandGesture) i
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
var personFromWhichToStartSearch PersonId
|
var personFromWhichToStartSearch PersonId = r.CurrentSpeaker
|
||||||
|
|
||||||
// if searched guesture is higher or same as current speaker, start from speaker
|
// if searched guesture is higher or same as current speaker, start from speaker
|
||||||
if gesture >= curSpeakerGesture {
|
if gesture >= curSpeakerGesture {
|
||||||
personFromWhichToStartSearch = r.CurrentSpeaker
|
personFromWhichToStartSearch = r.CurrentSpeaker
|
||||||
}
|
}
|
||||||
// if searched gesture is of lower priority from current speaker, check marks to return to, or use speaker level
|
// if searched gesture is of lower priority from current speaker, check marks to return to, or use speaker level
|
||||||
|
if gesture < curSpeakerGesture {
|
||||||
gestureMark, found := r.Marks[gesture]
|
gestureMark, found := r.Marks[gesture]
|
||||||
if found {
|
if found {
|
||||||
personFromWhichToStartSearch = gestureMark
|
personFromWhichToStartSearch = gestureMark
|
||||||
}
|
}
|
||||||
// if no mark found - count from the speaker
|
// if no mark found - count from the speaker
|
||||||
personFromWhichToStartSearch = r.CurrentSpeaker
|
}
|
||||||
|
log.Printf("> selecting person from which to start. cur speaker %s, for gestrue %s, got person %d",
|
||||||
|
curSpeakerGesture.String(), gesture.String(), personFromWhichToStartSearch)
|
||||||
|
|
||||||
indexFromWhichToStart := slices.IndexFunc(r.Paricipants, func(p Person) bool {
|
indexFromWhichToStart := slices.IndexFunc(r.Paricipants, func(p Person) bool {
|
||||||
return p.Id == personFromWhichToStartSearch
|
return p.Id == personFromWhichToStartSearch
|
||||||
|
|
|
@ -2,63 +2,228 @@ package rooms
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/kr/pretty"
|
||||||
)
|
)
|
||||||
|
|
||||||
type releaseHandTest struct {
|
type releaseHandTest struct {
|
||||||
|
testName string
|
||||||
room, expected Room
|
room, expected Room
|
||||||
releasingParticipantId PersonId
|
releasingParticipantId PersonId
|
||||||
}
|
}
|
||||||
|
|
||||||
var releaseHandTests = []releaseHandTest{
|
var releaseHandTests = []releaseHandTest{
|
||||||
singleHandActive,
|
singleHandActive,
|
||||||
|
raisingLevelFromExpandToClarifyingQ,
|
||||||
|
selectNextHigherLevel,
|
||||||
|
usingMarkToLoverLevel,
|
||||||
|
releasingNonSpeakerHand,
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRoomReleaseHand(t *testing.T) {
|
func TestRoomReleaseHand(t *testing.T) {
|
||||||
for _, test := range releaseHandTests {
|
for _, test := range releaseHandTests {
|
||||||
|
t.Run(test.testName, func(t *testing.T){
|
||||||
test.room.InitMaps()
|
test.room.InitMaps()
|
||||||
test.expected.InitMaps()
|
test.expected.InitMaps()
|
||||||
if test.room.ReleaseHand(test.releasingParticipantId); !test.room.Equal(&test.expected) {
|
if test.room.ReleaseHand(test.releasingParticipantId); !test.room.Equal(&test.expected) {
|
||||||
t.Errorf("Output \n%+v \nnot equal to expected \n%+v", test.room, test.expected)
|
t.Errorf("Test release hand diff: (-want +got)\n%s", pretty.Diff(test.room, test.expected))
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var p1Id = PersonId(1)
|
var person1 = Person{
|
||||||
var p2Id = PersonId(2)
|
Id: PersonId(100),
|
||||||
|
Name: "test person 1",
|
||||||
|
}
|
||||||
|
var person2 = Person{
|
||||||
|
Id: PersonId(200),
|
||||||
|
Name: "test person 2",
|
||||||
|
}
|
||||||
|
var person3 = Person{
|
||||||
|
Id: PersonId(300),
|
||||||
|
Name: "test person 3",
|
||||||
|
}
|
||||||
|
var person4 = Person{
|
||||||
|
Id: PersonId(400),
|
||||||
|
Name: "test person 4",
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2 persons, 1 hand active, releasing it makes 'nobody' active
|
||||||
var singleHandActive releaseHandTest = releaseHandTest{
|
var singleHandActive releaseHandTest = releaseHandTest{
|
||||||
|
testName: "singleHandActive",
|
||||||
room: Room{
|
room: Room{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
CurrentSpeaker: p1Id,
|
CurrentSpeaker: person1.Id,
|
||||||
Paricipants: []Person{
|
Paricipants: []Person{
|
||||||
{
|
person1,
|
||||||
Id : p1Id,
|
person2,
|
||||||
Name: "p1",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Id : PersonId(2),
|
|
||||||
Name: "p2",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
ParticipantHands: map[PersonId]HandGesture{
|
ParticipantHands: map[PersonId]HandGesture{
|
||||||
p1Id: Expand,
|
person1.Id: Expand,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
releasingParticipantId: p1Id,
|
releasingParticipantId: person1.Id,
|
||||||
expected: Room{
|
expected: Room{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
CurrentSpeaker: PersonId(0),
|
CurrentSpeaker: PersonId(0),
|
||||||
Paricipants: []Person{
|
Paricipants: []Person{
|
||||||
{
|
person1,
|
||||||
Id : p1Id,
|
person2,
|
||||||
Name: "p1",
|
|
||||||
},
|
},
|
||||||
{
|
ParticipantHands: map[PersonId]HandGesture{},
|
||||||
Id : PersonId(2),
|
|
||||||
Name: "p2",
|
|
||||||
},
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3 person in room, active does expand, next is probingQ, this sets mark for expand
|
||||||
|
var raisingLevelFromExpandToClarifyingQ releaseHandTest = releaseHandTest{
|
||||||
|
testName: "raisingLevelFromExpandToClarifyingQ",
|
||||||
|
room: Room{
|
||||||
|
Name: "test",
|
||||||
|
CurrentSpeaker: person1.Id,
|
||||||
|
Paricipants: []Person{
|
||||||
|
person1,
|
||||||
|
person2,
|
||||||
|
person3,
|
||||||
},
|
},
|
||||||
ParticipantHands: map[PersonId]HandGesture{
|
ParticipantHands: map[PersonId]HandGesture{
|
||||||
|
person1.Id: Expand,
|
||||||
|
person3.Id: ClarifyingQ,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
releasingParticipantId: person1.Id,
|
||||||
|
expected: Room{
|
||||||
|
Name: "test",
|
||||||
|
CurrentSpeaker: person3.Id,
|
||||||
|
Paricipants: []Person{
|
||||||
|
person1,
|
||||||
|
person2,
|
||||||
|
person3,
|
||||||
|
},
|
||||||
|
ParticipantHands: map[PersonId]HandGesture{
|
||||||
|
person3.Id: ClarifyingQ,
|
||||||
|
},
|
||||||
|
Marks: map[HandGesture]PersonId{
|
||||||
|
Expand: person1.Id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3 person in room, active does expand, next is probingQ, this sets mark for expand
|
||||||
|
var selectNextHigherLevel releaseHandTest = releaseHandTest{
|
||||||
|
testName: "selectNextHigherLevel",
|
||||||
|
room: Room{
|
||||||
|
Name: "test",
|
||||||
|
CurrentSpeaker: person1.Id,
|
||||||
|
Paricipants: []Person{
|
||||||
|
person1,
|
||||||
|
person2,
|
||||||
|
person3,
|
||||||
|
},
|
||||||
|
ParticipantHands: map[PersonId]HandGesture{
|
||||||
|
person1.Id: Meta,
|
||||||
|
person2.Id: Expand,
|
||||||
|
person3.Id: Meta,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
releasingParticipantId: person1.Id,
|
||||||
|
expected: Room{
|
||||||
|
Name: "test",
|
||||||
|
CurrentSpeaker: person3.Id,
|
||||||
|
Paricipants: []Person{
|
||||||
|
person1,
|
||||||
|
person2,
|
||||||
|
person3,
|
||||||
|
},
|
||||||
|
ParticipantHands: map[PersonId]HandGesture{
|
||||||
|
person2.Id: Expand,
|
||||||
|
person3.Id: Meta,
|
||||||
|
},
|
||||||
|
Marks: map[HandGesture]PersonId{
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4 person in room, returning to lover level, start not from cur speaker, but from mark
|
||||||
|
var usingMarkToLoverLevel releaseHandTest = releaseHandTest{
|
||||||
|
testName: "usingMarkToLoverLevel",
|
||||||
|
room: Room{
|
||||||
|
Name: "test",
|
||||||
|
CurrentSpeaker: person3.Id,
|
||||||
|
Paricipants: []Person{
|
||||||
|
person1,
|
||||||
|
person2,
|
||||||
|
person3,
|
||||||
|
person4,
|
||||||
|
},
|
||||||
|
ParticipantHands: map[PersonId]HandGesture{
|
||||||
|
person2.Id: Expand,
|
||||||
|
person3.Id: Meta,
|
||||||
|
person4.Id: Expand,
|
||||||
|
},
|
||||||
|
Marks: map[HandGesture]PersonId{
|
||||||
|
ClarifyingQ: person3.Id,
|
||||||
|
Expand: person1.Id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
releasingParticipantId: person3.Id,
|
||||||
|
expected: Room{
|
||||||
|
Name: "test",
|
||||||
|
CurrentSpeaker: person2.Id,
|
||||||
|
Paricipants: []Person{
|
||||||
|
person1,
|
||||||
|
person2,
|
||||||
|
person3,
|
||||||
|
person4,
|
||||||
|
},
|
||||||
|
ParticipantHands: map[PersonId]HandGesture{
|
||||||
|
person2.Id: Expand,
|
||||||
|
person4.Id: Expand,
|
||||||
|
},
|
||||||
|
Marks: map[HandGesture]PersonId{
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4 person in room, releasing hand for non-speaker changes nothing else
|
||||||
|
var releasingNonSpeakerHand releaseHandTest = releaseHandTest{
|
||||||
|
testName: "releasingNonSpeakerHand",
|
||||||
|
room: Room{
|
||||||
|
Name: "test",
|
||||||
|
CurrentSpeaker: person3.Id,
|
||||||
|
Paricipants: []Person{
|
||||||
|
person1,
|
||||||
|
person2,
|
||||||
|
person3,
|
||||||
|
person4,
|
||||||
|
},
|
||||||
|
ParticipantHands: map[PersonId]HandGesture{
|
||||||
|
person2.Id: Expand,
|
||||||
|
person3.Id: Meta,
|
||||||
|
person4.Id: Expand,
|
||||||
|
},
|
||||||
|
Marks: map[HandGesture]PersonId{
|
||||||
|
ClarifyingQ: person3.Id,
|
||||||
|
Expand: person1.Id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
releasingParticipantId: person4.Id,
|
||||||
|
expected: Room{
|
||||||
|
Name: "test",
|
||||||
|
CurrentSpeaker: person3.Id,
|
||||||
|
Paricipants: []Person{
|
||||||
|
person1,
|
||||||
|
person2,
|
||||||
|
person3,
|
||||||
|
person4,
|
||||||
|
},
|
||||||
|
ParticipantHands: map[PersonId]HandGesture{
|
||||||
|
person2.Id: Expand,
|
||||||
|
person3.Id: Meta,
|
||||||
|
},
|
||||||
|
Marks: map[HandGesture]PersonId{
|
||||||
|
ClarifyingQ: person3.Id,
|
||||||
|
Expand: person1.Id,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -231,7 +231,7 @@ func joinRoomHandler(templateFs *embed.FS,
|
||||||
return toRoom
|
return toRoom
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("/login/join problem adding person to room", person.Name)
|
log.Printf("/login/join problem adding person to room %+v", person.Name)
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
// TODO render error to be put in error place
|
// TODO render error to be put in error place
|
||||||
// with message try again
|
// with message try again
|
||||||
|
|
Loading…
Reference in New Issue