diff --git a/rooms/room.go b/rooms/room.go index 268b2f9..b19c7f8 100644 --- a/rooms/room.go +++ b/rooms/room.go @@ -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 // should be counted from the mark 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 currentSpeakerGesture, currentSpeakerFound := r.ParticipantHands[r.CurrentSpeaker] @@ -143,9 +143,14 @@ gestureIteration: log.Printf("searching for gesture %s", gesture.String()) startIndex := r.gestureSearchStartIndex(gesture, currentSpeakerGesture) participantsCount := len(r.Paricipants) - for i := 1; i < participantsCount; i++ { + inGestureParticipantIteration: + for i := 1; i <= participantsCount; i++ { checkIndex := (startIndex + i) % participantsCount checkPerson := r.Paricipants[checkIndex] + if checkPerson == r.CurrentSpeaker { + // current speaker still has thair gesture up + continue inGestureParticipantIteration + } checkGesture, isFound := r.ParticipantHands[checkPerson] if isFound && checkGesture == gesture { 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 } - log.Printf("> selecting person from which to start. cur speaker %s, for gestrue %s, got person %d", - curSpeakerGesture.String(), gesture.String(), personFromWhichToStartSearch) + log.Printf("> selecting person from which to start. cur speaker %d with gesture %s, for gestrue %s, got person %d", + r.CurrentSpeaker, curSpeakerGesture.String(), gesture.String(), personFromWhichToStartSearch) indexFromWhichToStart := slices.Index(r.Paricipants, personFromWhichToStartSearch) return indexFromWhichToStart diff --git a/rooms/room_release_hand_test.go b/rooms/room_release_hand_test.go index 369d85b..a670de7 100644 --- a/rooms/room_release_hand_test.go +++ b/rooms/room_release_hand_test.go @@ -7,7 +7,7 @@ import ( ) type releaseHandTest struct { - testName string + testName string room, expected Room releasingParticipantId PersonId } @@ -18,17 +18,18 @@ var releaseHandTests = []releaseHandTest{ selectNextHigherLevel, usingMarkToLoverLevel, releasingNonSpeakerHand, + releaseToPersonWithHandAndMark, } func TestRoomReleaseHand(t *testing.T) { for _, test := range releaseHandTests { - t.Run(test.testName, func(t *testing.T){ - test.room.InitMaps() - test.expected.InitMaps() - 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.Run(test.testName, func(t *testing.T) { + test.room.InitMaps() + test.expected.InitMaps() + 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)) + } + }) } } @@ -139,8 +140,7 @@ var selectNextHigherLevel releaseHandTest = releaseHandTest{ person2.Id: Expand, person3.Id: Meta, }, - Marks: map[HandGesture]PersonId{ - }, + Marks: map[HandGesture]PersonId{}, }, } @@ -163,7 +163,7 @@ var usingMarkToLoverLevel releaseHandTest = releaseHandTest{ }, Marks: map[HandGesture]PersonId{ ClarifyingQ: person3.Id, - Expand: person1.Id, + Expand: person1.Id, }, }, releasingParticipantId: person3.Id, @@ -180,8 +180,7 @@ var usingMarkToLoverLevel releaseHandTest = releaseHandTest{ person2.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{ ClarifyingQ: person3.Id, - Expand: person1.Id, + Expand: person1.Id, }, }, releasingParticipantId: person4.Id, @@ -223,7 +222,46 @@ var releasingNonSpeakerHand releaseHandTest = releaseHandTest{ }, Marks: map[HandGesture]PersonId{ 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{}, + }, +}