feat: tests and bugfix for 'lower hand'
This commit is contained in:
@@ -2,63 +2,228 @@ package rooms
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/kr/pretty"
|
||||
)
|
||||
|
||||
type releaseHandTest struct {
|
||||
testName string
|
||||
room, expected Room
|
||||
releasingParticipantId PersonId
|
||||
}
|
||||
|
||||
var releaseHandTests = []releaseHandTest{
|
||||
singleHandActive,
|
||||
raisingLevelFromExpandToClarifyingQ,
|
||||
selectNextHigherLevel,
|
||||
usingMarkToLoverLevel,
|
||||
releasingNonSpeakerHand,
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
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))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
var p1Id = PersonId(1)
|
||||
var p2Id = PersonId(2)
|
||||
var person1 = Person{
|
||||
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{
|
||||
room : Room{
|
||||
Name: "test",
|
||||
CurrentSpeaker: p1Id,
|
||||
testName: "singleHandActive",
|
||||
room: Room{
|
||||
Name: "test",
|
||||
CurrentSpeaker: person1.Id,
|
||||
Paricipants: []Person{
|
||||
{
|
||||
Id : p1Id,
|
||||
Name: "p1",
|
||||
},
|
||||
{
|
||||
Id : PersonId(2),
|
||||
Name: "p2",
|
||||
},
|
||||
person1,
|
||||
person2,
|
||||
},
|
||||
ParticipantHands: map[PersonId]HandGesture{
|
||||
p1Id: Expand,
|
||||
person1.Id: Expand,
|
||||
},
|
||||
},
|
||||
releasingParticipantId: p1Id,
|
||||
releasingParticipantId: person1.Id,
|
||||
expected: Room{
|
||||
Name: "test",
|
||||
Name: "test",
|
||||
CurrentSpeaker: PersonId(0),
|
||||
Paricipants: []Person{
|
||||
{
|
||||
Id : p1Id,
|
||||
Name: "p1",
|
||||
},
|
||||
{
|
||||
Id : PersonId(2),
|
||||
Name: "p2",
|
||||
},
|
||||
person1,
|
||||
person2,
|
||||
},
|
||||
ParticipantHands: map[PersonId]HandGesture{},
|
||||
},
|
||||
}
|
||||
|
||||
// 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{
|
||||
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,
|
||||
},
|
||||
},
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user