fix: having mark and same raised gesture

previously didn't check everyone, and person with mark and gesture is
last in the circle
This commit is contained in:
efim 2023-11-22 05:03:14 +00:00
parent 017cf465da
commit 077537a1e3
2 changed files with 62 additions and 19 deletions

View File

@ -129,7 +129,7 @@ func (r *Room) PersonToStandUpFromTable(p PersonId) {
// - if the gesture is of lover priority and there is a mark for the gesture level // - if the gesture is of lover priority and there is a mark for the gesture level
// should be counted from the mark // should be counted from the mark
func (r *Room) NextSpeakerIndex() (nextSpeakerIndex int, found bool, countedFromIndex int) { func (r *Room) NextSpeakerIndex() (nextSpeakerIndex int, found bool, countedFromIndex int) {
// if a current speaker - after removing the hand, we need to find next speaker // if a current speaker - before removing the hand, we need to find next speaker
// from highest hand gesture to lowest, until one is found // from highest hand gesture to lowest, until one is found
currentSpeakerGesture, currentSpeakerFound := r.ParticipantHands[r.CurrentSpeaker] currentSpeakerGesture, currentSpeakerFound := r.ParticipantHands[r.CurrentSpeaker]
@ -143,9 +143,14 @@ gestureIteration:
log.Printf("searching for gesture %s", gesture.String()) log.Printf("searching for gesture %s", gesture.String())
startIndex := r.gestureSearchStartIndex(gesture, currentSpeakerGesture) startIndex := r.gestureSearchStartIndex(gesture, currentSpeakerGesture)
participantsCount := len(r.Paricipants) participantsCount := len(r.Paricipants)
for i := 1; i < participantsCount; i++ { inGestureParticipantIteration:
for i := 1; i <= participantsCount; i++ {
checkIndex := (startIndex + i) % participantsCount checkIndex := (startIndex + i) % participantsCount
checkPerson := r.Paricipants[checkIndex] checkPerson := r.Paricipants[checkIndex]
if checkPerson == r.CurrentSpeaker {
// current speaker still has thair gesture up
continue inGestureParticipantIteration
}
checkGesture, isFound := r.ParticipantHands[checkPerson] checkGesture, isFound := r.ParticipantHands[checkPerson]
if isFound && checkGesture == gesture { if isFound && checkGesture == gesture {
nextSpeakerIndex = slices.Index(r.Paricipants, checkPerson) nextSpeakerIndex = slices.Index(r.Paricipants, checkPerson)
@ -188,8 +193,8 @@ func (r *Room) gestureSearchStartIndex(gesture, curSpeakerGesture HandGesture) i
} }
// if no mark found - count from the speaker // if no mark found - count from the speaker
} }
log.Printf("> selecting person from which to start. cur speaker %s, for gestrue %s, got person %d", log.Printf("> selecting person from which to start. cur speaker %d with gesture %s, for gestrue %s, got person %d",
curSpeakerGesture.String(), gesture.String(), personFromWhichToStartSearch) r.CurrentSpeaker, curSpeakerGesture.String(), gesture.String(), personFromWhichToStartSearch)
indexFromWhichToStart := slices.Index(r.Paricipants, personFromWhichToStartSearch) indexFromWhichToStart := slices.Index(r.Paricipants, personFromWhichToStartSearch)
return indexFromWhichToStart return indexFromWhichToStart

View File

@ -7,7 +7,7 @@ import (
) )
type releaseHandTest struct { type releaseHandTest struct {
testName string testName string
room, expected Room room, expected Room
releasingParticipantId PersonId releasingParticipantId PersonId
} }
@ -18,17 +18,18 @@ var releaseHandTests = []releaseHandTest{
selectNextHigherLevel, selectNextHigherLevel,
usingMarkToLoverLevel, usingMarkToLoverLevel,
releasingNonSpeakerHand, releasingNonSpeakerHand,
releaseToPersonWithHandAndMark,
} }
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){ 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("Test release hand diff: (-want +got)\n%s", pretty.Diff(test.room, test.expected)) t.Errorf("Test release hand diff: (-want +got)\n%s", pretty.Diff(test.room, test.expected))
} }
}) })
} }
} }
@ -139,8 +140,7 @@ var selectNextHigherLevel releaseHandTest = releaseHandTest{
person2.Id: Expand, person2.Id: Expand,
person3.Id: Meta, person3.Id: Meta,
}, },
Marks: map[HandGesture]PersonId{ Marks: map[HandGesture]PersonId{},
},
}, },
} }
@ -163,7 +163,7 @@ var usingMarkToLoverLevel releaseHandTest = releaseHandTest{
}, },
Marks: map[HandGesture]PersonId{ Marks: map[HandGesture]PersonId{
ClarifyingQ: person3.Id, ClarifyingQ: person3.Id,
Expand: person1.Id, Expand: person1.Id,
}, },
}, },
releasingParticipantId: person3.Id, releasingParticipantId: person3.Id,
@ -180,8 +180,7 @@ var usingMarkToLoverLevel releaseHandTest = releaseHandTest{
person2.Id: Expand, person2.Id: Expand,
person4.Id: Expand, person4.Id: Expand,
}, },
Marks: map[HandGesture]PersonId{ Marks: map[HandGesture]PersonId{},
},
}, },
} }
@ -204,7 +203,7 @@ var releasingNonSpeakerHand releaseHandTest = releaseHandTest{
}, },
Marks: map[HandGesture]PersonId{ Marks: map[HandGesture]PersonId{
ClarifyingQ: person3.Id, ClarifyingQ: person3.Id,
Expand: person1.Id, Expand: person1.Id,
}, },
}, },
releasingParticipantId: person4.Id, releasingParticipantId: person4.Id,
@ -223,7 +222,46 @@ var releasingNonSpeakerHand releaseHandTest = releaseHandTest{
}, },
Marks: map[HandGesture]PersonId{ Marks: map[HandGesture]PersonId{
ClarifyingQ: person3.Id, ClarifyingQ: person3.Id,
Expand: person1.Id, Expand: person1.Id,
}, },
}, },
} }
// there is a mark for Expand on person 2, and raised hand with Expand on person 2
// speaker is person 3 with Meta
// after hand release person 2 should be speaking, with mark removed
var releaseToPersonWithHandAndMark releaseHandTest = releaseHandTest{
testName: "releaseToPersonWithHandAndMark",
room: Room{
Name: "test",
CurrentSpeaker: person3.Id,
Paricipants: []PersonId{
person1.Id,
person2.Id,
person3.Id,
person4.Id,
},
ParticipantHands: map[PersonId]HandGesture{
person2.Id: Expand,
person3.Id: Meta,
},
Marks: map[HandGesture]PersonId{
Expand: person2.Id,
},
},
releasingParticipantId: person3.Id,
expected: Room{
Name: "test",
CurrentSpeaker: person2.Id,
Paricipants: []PersonId{
person1.Id,
person2.Id,
person3.Id,
person4.Id,
},
ParticipantHands: map[PersonId]HandGesture{
person2.Id: Expand,
},
Marks: map[HandGesture]PersonId{},
},
}