diff --git a/rooms/room.go b/rooms/room.go index e549862..e081610 100644 --- a/rooms/room.go +++ b/rooms/room.go @@ -2,6 +2,7 @@ package rooms import ( "log" + "maps" "slices" ) @@ -130,6 +131,22 @@ func (r *Room) gestureSearchStartIndex(gesture, curSpeakerGesture HandGesture) i return indexFromWhichToStart } +func (r *Room) Equal(other *Room) bool { + if r == other { + return true + } + if r.Name != other.Name || r.PasswordHash != other.PasswordHash || r.CurrentSpeaker != other.CurrentSpeaker { + return false + } + if !slices.Equal(r.AdminIds, other.AdminIds) || !slices.Equal(r.Paricipants, other.Paricipants) { + return false + } + if !maps.Equal(r.ParticipantHands, other.ParticipantHands) || !maps.Equal(r.Marks, other.Marks) { + return false + } + return true +} + // sooooooo. i need hand types. are there enums in go? type HandGesture uint8 diff --git a/rooms/room_release_hand_test.go b/rooms/room_release_hand_test.go new file mode 100644 index 0000000..cc5fc96 --- /dev/null +++ b/rooms/room_release_hand_test.go @@ -0,0 +1,64 @@ +package rooms + +import ( + "testing" +) + +type releaseHandTest struct { + room, expected Room + releasingParticipantId PersonId +} + +var releaseHandTests = []releaseHandTest{ + singleHandActive, +} + +func TestRoomReleaseHand(t *testing.T) { + for _, test := range releaseHandTests { + test.room.InitMaps() + test.expected.InitMaps() + 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) + } + } +} + +var p1Id = PersonId(1) +var p2Id = PersonId(2) +var singleHandActive releaseHandTest = releaseHandTest{ + room : Room{ + Name: "test", + CurrentSpeaker: p1Id, + Paricipants: []Person{ + { + Id : p1Id, + Name: "p1", + }, + { + Id : PersonId(2), + Name: "p2", + }, + }, + ParticipantHands: map[PersonId]HandGesture{ + p1Id: Expand, + }, + }, + releasingParticipantId: p1Id, + expected: Room{ + Name: "test", + CurrentSpeaker: PersonId(0), + Paricipants: []Person{ + { + Id : p1Id, + Name: "p1", + }, + { + Id : PersonId(2), + Name: "p2", + }, + }, + ParticipantHands: map[PersonId]HandGesture{ + }, + }, + +}